Refactored API

This commit is contained in:
Marco Realacci 2022-11-15 23:23:33 +01:00
parent c694deedd5
commit f699f8c7e5

View file

@ -4,7 +4,7 @@ info:
description: |- description: |-
Keep in touch with your friends by sharing photos of special moments, thanks to WASAPhoto! You can Keep in touch with your friends by sharing photos of special moments, thanks to WASAPhoto! You can
upload your photos directly from your PC, and they will be visible to everyone following you. upload your photos directly from your PC, and they will be visible to everyone following you.
version: "1" version: "2.0.0"
paths: paths:
/session: /session:
post: post:
@ -19,21 +19,20 @@ paths:
$ref: "#/components/requestBodies/userDetails" $ref: "#/components/requestBodies/userDetails"
responses: responses:
'201': '201':
description: User log-in action successful description: User log-in action successful.
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
identifier: user_id: #todo parameter name
type: string $ref: "#/components/schemas/uid"
example: '* imagine a Bearer token *'
/session/username: /users/{user_id}/username:
put: put:
tags: ["login"] tags: ["username"]
summary: Updates the username summary: Updates the username
description: Changes the username of the user with the given one description: Changes the username of the user with the given one.
operationId: setMyUsername operationId: setMyUsername
security: security:
- BearerAuth: [] - BearerAuth: []
@ -41,12 +40,12 @@ paths:
$ref: "#/components/requestBodies/userDetails" $ref: "#/components/requestBodies/userDetails"
responses: responses:
'200': '200':
description: Update username action successful description: Update username action successful.
'409': '409':
description: The chosen username is already taken description: The chosen username is already taken by another user.
/followers/{username}: /users/{user_id}/followers/{follower_uid}:
post: put:
tags: ["followers"] tags: ["followers"]
summary: Follows a user summary: Follows a user
description: Starts following a user description: Starts following a user
@ -54,17 +53,23 @@ paths:
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
description: The user to follow description: The user ID of the user to follow.
- name: follower_uid
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The new follower's user ID.
responses: responses:
'200': '200':
description: Follow user action successful description: Follow user action successful.
'409': '403':
description: The user is already followed by the user description: The user has no permission perform this action.
delete: delete:
tags: ["followers"] tags: ["followers"]
summary: Unfollows a user summary: Unfollows a user
@ -73,148 +78,199 @@ paths:
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
description: The user to unfollow description: The user ID of the user to remove a follower from.
- name: follower_uid
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The user ID of the follower to remove.
responses: responses:
'200': '200':
description: Unfollow user action successful description: Unfollow user action successful.
'409': '404':
description: The user is not followed by the user description: The user is not followed by the user.
/bans: /users/{user_id}/bans/{ban_uid}:
post: put:
tags: ["bans"] tags: ["bans"]
summary: Bans a user summary: Bans a user
description: Bans a user //edit this please description: Add a user to the list of banned users of the user.
operationId: banUser operationId: banUser
security: security:
- BearerAuth: [] - BearerAuth: []
requestBody: parameters:
$ref: "#/components/requestBodies/userDetails" - name: user_id
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The user ID of the banning user.
- name: ban_uid
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The user ID of the user to ban.
responses: responses:
'200': '200':
description: Ban user action successful description: Ban user action successful.
'409': '403':
description: The user is already banned by the user description: The user has no permission to perform this action.
/bans/{username}:
delete: delete:
tags: ["bans"] tags: ["bans"]
summary: Unbans a user summary: Unbans a user
description: Unbans a user //todo edit this please description: Removes a ban from the list of banned users of the user.
operationId: unbanUser operationId: unbanUser
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
description: The user to unfollow description: The user ID of the unbanning user.
- name: ban_uid
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The user ID of the user to unban.
responses: responses:
'200': '200':
description: Unban user action successful description: Unban user action successful.
'409': '403':
description: The user was not banned by the user description: The user has no permission to perform this action.
'404':
description: The user is not banned by the user.
/photos/{username}/{photoID}/likes: /users/{user_id}/photos/{photo_id}/likes/{liker_uid}:
post: put:
tags: ["photos"] tags: ["likes"]
summary: Like a photo #todo review summary: likes a Photo
description: aaa #todo review description: Adds a like to a photo.
operationId: likePhoto operationId: likePhoto
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
description: The owner of the picture to like description: The user ID of the owner of the photo to add a like to.
- name: photoID - name: liker_uid
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/uid"
required: true required: true
description: The ID of the photo to like description: The user ID of the user who likes the photo.
- name: photo_id
in: path
schema:
$ref: "#/components/schemas/photo_id"
required: true
description: The ID of the photo to like.
responses: responses:
'200': '200':
description: Like photo action successful description: Like photo action successful.
'403':
description: The user has no permission to perform this action.
'404': '404':
description: The photo does not exists, or the author of the photo has banned the user description: The photo does not exists, or the author of the photo has banned the user.
delete: delete:
tags: ["photos"] tags: ["likes"]
summary: Unlike a photo #todo review summary: Unlikes a photo
description: aaa #todo review description: Removes a like from a photo
operationId: unlikePhoto operationId: unlikePhoto
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
description: The owner of the picture to unlike description: The user ID of the owner of the photo to remove a like from.
- name: photoID - name: liker_uid
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/uid"
required: true required: true
description: The ID of the photo to unlike description: The user ID of the user that was liking the photo.
- name: photo_id
in: path
schema:
$ref: "#/components/schemas/photo_id"
required: true
description: The ID of the photo to remove a like from.
responses: responses:
'200': '200':
description: Unlike photo action successful description: Unlike photo action successful.
'404': '404':
description: The photo does not exists or the user was not liking the photo description: The photo does not exists or the user was not liking the photo.
/profile/{username}: #todo maybe username not here /users/{user_id}:
get: get:
tags: ["profile"] tags: ["profile"]
summary: Returns user profile summary: Returns user profile
description: todo description: Returns the profile of a user, including user's photos, followers, and following users.
operationId: getUserProfile operationId: getUserProfile
security:
- BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
description: The user ID of the user to get the profile of.
required: true required: true
responses: responses:
'200': '200':
description: Returns the profile details of the given user description: Returns the profile details of the given user.
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
username:
$ref: "#/components/schemas/name"
followers: followers:
type: array type: array
description: Array of users that the user is following description: Array of users that the user is following.
items: items:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid_name"
following: following:
type: array type: array
description: Array of users that are following the user description: Array of users that are following the user.
items: items:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid_name"
photos: photos:
$ref: "#/components/schemas/userPhotoStream" $ref: "#/components/schemas/user_photo_stream"
'404': '404':
description: User not found or has banned the requesting user description: User not found (or the authorized user is banned).
/photos: /users/{user_id}/photos:
post: post:
tags: ["photos"] tags: ["photos"]
summary: Uploads a photo summary: Uploads a photo
description: Uploads a photo in the gallery of the authorized user description: Uploads a photo in the gallery of the authorized user.
operationId: uploadPhoto operationId: uploadPhoto
security: security:
- BearerAuth: [] - BearerAuth: []
parameters:
- name: user_id
in: path
schema:
$ref: "#/components/schemas/uid"
required: true
description: The user ID of the user who uploads the photo.
requestBody: requestBody:
content: content:
image/jpeg: image/jpeg:
@ -222,81 +278,85 @@ paths:
format: binary format: binary
responses: responses:
'201': '201':
description: Upload photo action successful #todo maybe get id? description: Upload photo action successful.
/photos/{username}/{photoID}: /users/{user_id}/photos/{photo_id}:
get: get:
tags: ["photos"] tags: ["photos"]
summary: Download a photo summary: Downloads a photo
description: Returns the requested photo description: Returns the requested photo in binary format.
operationId: getUserPhoto operationId: getUserPhoto
security:
- BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
description: The user ID of the user who owns the photo.
required: true required: true
- name: photoID - name: photo_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
description: The ID of the photo to download.
required: true required: true
responses: responses:
'200': '200':
description: Returns the profile details of the given user description: The requested photo in binary format.
content: content:
image/jpeg: image/jpeg:
schema: schema:
format: binary format: binary
'404': '404':
description: Photo not found description: Photo not found (or the user is banned by the owner of the photo).
'403':
description: Requesting user has no permission to see the photo (banned or not following)
delete: delete:
tags: ["photos"] tags: ["photos"]
summary: Deletes a photo summary: Deletes a photo
description: Deletes a photo in the gallery of the authorized user description: Deletes a photo in the gallery of the authorized user.
operationId: deletePhoto operationId: deletePhoto
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
description: The user ID of the user who deletes the photo.
required: true required: true
- name: photoID - name: photo_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
description: The ID of the photo to delete.
required: true required: true
responses: responses:
'200': '200':
description: Delete photo action successful description: Delete photo action successful.
'401': '401':
description: The user does not own the photo description: The user has no permission to delete that photo.
/photos/{username}/{photoID}/comments: /users/{user_id}/photos/{photo_id}/comments:
post: post:
tags: ["comments"] tags: ["comments"]
summary: Comments a photo #todo review summary: Comments a photo
description: aaa #todo review description: Adds a comment to a photo.
operationId: commentPhoto operationId: commentPhoto
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
- name: photoID - name: photo_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
required: true required: true
requestBody: requestBody:
description: User details description: The comment to post.
content: content:
application/json: application/json:
schema: schema:
@ -307,122 +367,138 @@ paths:
example: "What a lovely picture! 😊" example: "What a lovely picture! 😊"
responses: responses:
'200': '200':
description: Comment photo action successful description: Comment photo action successful.
'404': '404':
description: The photo does not exists, or the author of the photo has banned the user description: The photo does not exists (or the author of the photo has banned the user).
/photos/{username}/{photoID}/comments/{commentID}: /users/{user_id}/photos/{photo_id}/comments/{comment_id}:
delete: delete:
tags: ["comments"] tags: ["comments"]
summary: Deletes a comment summary: Deletes a comment
description: Deletes a photo in the gallery of the authorized user description: Deletes a photo in the gallery of the authorized user.
operationId: deleteComment operationId: deleteComment
security: security:
- BearerAuth: [] - BearerAuth: []
parameters: parameters:
- name: username - name: user_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/uid"
required: true required: true
- name: photoID - name: photo_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
required: true required: true
- name: commentID - name: comment_id
in: path in: path
schema: schema:
$ref: "#/components/schemas/commentID" $ref: "#/components/schemas/comment_id"
required: true required: true
responses: responses:
'200': '200':
description: Delete photo action successful description: Delete comment action successful.
'401':
/stream: #todo parametri per lazy loading description: The user has no permission to delete that comment.
'404':
description: The comment does not exists.
/stream: #todo path
get: get:
tags: ["stream"] tags: ["stream"]
summary: Returns user stream summary: Returns user stream
description: todo description: Returns the photo stream of the authorized user.
operationId: getMyStream operationId: getMyStream
security: security:
- BearerAuth: [] #todo maybe not needed - BearerAuth: []
parameters: parameters:
- name: limit - name: limit
in: query in: query
schema: schema:
type: integer type: integer
default: 25 default: 25
description: The number of elements to show description: The number of elements to show.
required: false required: false
- name: startIndex - name: startIndex
in: query in: query
schema: schema:
type: integer type: integer
default: 0 default: 0
description: The starting offset description: The starting offset.
required: false required: false
responses: responses:
'200': '200':
description: Returns the profile details of the given user description: The photo stream.
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/photoStream" $ref: "#/components/schemas/photo_stream"
components: components:
securitySchemes: securitySchemes:
BearerAuth: BearerAuth:
type: http type: http
scheme: bearer scheme: bearer
schemas: schemas:
uid_name:
type: object
properties:
user_id:
$ref: "#/components/schemas/uid"
name:
$ref: "#/components/schemas/name"
uid:
type: string
format: uuid
example: "1b4e28ba-2fa1-11d2-883f-0016d3cca427"
name: name:
type: string type: string
example: Maria example: Maria
pattern: 'ˆ.*?$' pattern: 'ˆ.*?$'
minLength: 3 minLength: 3
maxLength: 16 maxLength: 16
photoID: photo_id:
type: integer type: integer
description: The ID of the photo description: The ID of the photo.
example: 1527 example: 1527
commentID: comment_id:
type: integer type: integer
description: The ID of the comment description: The ID of the comment.
example: 3 example: 3
uploadTime: upload_time:
type: string type: string
format: date-time format: date-time
description: Photo upload time and date description: Photo upload time and date.
likes: likes:
type: integer type: integer
example: 90 example: 90
description: Number of likes description: Number of likes.
userPhotoStream: user_photo_stream:
type: array type: array
items: items:
type: object type: object
properties: properties:
photoID: photo_id:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
uploadTime: upload_time:
$ref: "#/components/schemas/uploadTime" $ref: "#/components/schemas/upload_time"
likes: likes:
$ref: "#/components/schemas/likes" $ref: "#/components/schemas/likes"
photoStream: photo_stream:
type: array type: array
items: items:
type: object type: object
properties: properties:
user_id:
$ref: "#/components/schemas/uid"
username: username:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/name"
photoID: photo_id:
$ref: "#/components/schemas/photoID" $ref: "#/components/schemas/photo_id"
uploadTime: upload_time:
$ref: "#/components/schemas/uploadTime" $ref: "#/components/schemas/upload_time"
likes: likes:
$ref: "#/components/schemas/likes" $ref: "#/components/schemas/likes"
@ -436,17 +512,4 @@ components:
properties: properties:
name: name:
$ref: "#/components/schemas/name" $ref: "#/components/schemas/name"
required: true
photoDetails:
description: Photo details
content:
application/json:
schema:
type: object
properties:
username:
$ref: "#/components/schemas/name"
photo:
$ref: "#/components/schemas/photoID"
required: true required: true