diff --git a/server/swagger.yaml b/server/swagger.yaml index c16c7ac..5847b9b 100644 --- a/server/swagger.yaml +++ b/server/swagger.yaml @@ -1,13 +1,17 @@ -openapi: 3.0.0 +openapi: 3.0.2 +security: + - bearerAuth: [] info: title: Campus Events and Entertainment Center API version: 1.0.0 description: API for managing campus events and entertainment servers: - - url: http://localhost:5000/api + - url: https://localhost:5000/api paths: - /users/register: + /users: post: + tags: + - Users summary: Register a user requestBody: required: true @@ -15,19 +19,29 @@ paths: application/json: schema: type: object + additionalProperties: false required: - username - password properties: username: type: string + pattern: ^[a-zA-Z0-9]+$ + maxLength: 15 password: type: string + pattern: ^[a-zA-Z0-9]+$ + maxLength: 32 responses: '200': description: User created successfully - /users/login: + '429': + $ref: '#/components/responses/429' + security: [] + /sessions: post: + tags: + - Users summary: Login a user requestBody: required: true @@ -35,43 +49,799 @@ paths: application/json: schema: type: object + additionalProperties: false required: - username - password properties: username: type: string + pattern: ^[a-zA-Z0-9]+$ + maxLength: 15 password: type: string + pattern: ^[a-zA-Z0-9]+$ + maxLength: 32 responses: '200': description: User logged in successfully + content: + application/json: + schema: + type: object + additionalProperties: false + properties: + token: + type: string + expires: + type: string + format: date-time + '401': + $ref: '#/components/responses/401' + security: [] + delete: + tags: + - Users + summary: Logout a user + responses: + '200': + description: User logged out successfully + '401': + $ref: '#/components/responses/401' + /users/{username}: + get: + tags: + - Users + summary: Get a user by username + parameters: + - $ref: '#/components/parameters/path_username' + responses: + '200': + description: User found + content: + application/json: + schema: + $ref: '#/components/schemas/User' + '404': + $ref: '#/components/responses/404' + /me: + get: + tags: + - Users + summary: Get the current user by token + responses: + '200': + description: User found content: application/json: schema: $ref: '#/components/schemas/User' '401': - description: Invalid username or password + $ref: '#/components/responses/401' + put: + tags: + - Users + summary: Edit the current user's info + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/User' + responses: + '200': + description: User info updated successfully + '401': + $ref: '#/components/responses/401' + delete: + tags: + - Users + summary: Delete the current user + responses: + '200': + description: User deleted successfully + '401': + $ref: '#/components/responses/401' + /events: + post: + tags: + - Events + summary: Create an event + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Event' + responses: + '200': + description: Event created successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + get: + tags: + - Events + summary: Get a list of events + description: Only published events are returned, ordered by time + parameters: + - $ref: '#/components/parameters/query_limit' + - $ref: '#/components/parameters/query_offset' + responses: + '200': + description: Events found + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Event' + '404': + $ref: '#/components/responses/404' + security: [] + /events/{event_id}: + get: + tags: + - Events + summary: Get an event by id + parameters: + - $ref: '#/components/parameters/path_event_id' + responses: + '200': + description: Event found + content: + application/json: + schema: + $ref: '#/components/schemas/Event' + '404': + $ref: '#/components/responses/404' + put: + tags: + - Events + summary: Edit an event by id + parameters: + - $ref: '#/components/parameters/path_event_id' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Event' + responses: + '200': + description: Event updated successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + delete: + tags: + - Events + summary: Delete an event by id + parameters: + - $ref: '#/components/parameters/path_event_id' + responses: + '200': + description: Event deleted successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /events/{event_id}/status: + put: + tags: + - Events + summary: Change the status of an event + parameters: + - $ref: '#/components/parameters/path_event_id' + requestBody: + required: true + content: + application/json: + schema: + type: object + additionalProperties: false + required: + - status + properties: + status: + $ref: '#/components/schemas/EventStatus' + responses: + '200': + description: Event status changed successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /events/{event_id}/reservation: + post: + tags: + - Events + summary: Register an event + parameters: + - $ref: '#/components/parameters/path_event_id' + requestBody: + required: true + content: + application/json: + schema: + type: object + additionalProperties: false + required: + - seat + properties: + seat: + type: string + responses: + '200': + description: Event registered successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + delete: + tags: + - Events + summary: Cancel a reservation + parameters: + - $ref: '#/components/parameters/path_event_id' + responses: + '200': + description: Reservation cancelled successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /events/{event_id}/comments: + get: + tags: + - Events + - Comments + summary: Get comments of an event + description: Comments are default ordered by time, can be changed by request + parameters: + - $ref: '#/components/parameters/path_event_id' + - $ref: '#/components/parameters/query_limit' + - $ref: '#/components/parameters/query_offset' + - $ref: '#/components/parameters/query_desc' + - name: order + in: query + schema: + type: string + enum: + - time + - likes + default: time + responses: + '200': + description: Comments found + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Comment' + '400': + $ref: '#/components/responses/400' + '404': + $ref: '#/components/responses/404' + post: + tags: + - Events + - Comments + summary: Comment on an event + parameters: + - $ref: '#/components/parameters/path_event_id' + requestBody: + required: true + content: + application/json: + schema: + type: object + additionalProperties: false + required: + - content + properties: + content: + type: string + responses: + '200': + description: Comment created successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /comments/{comment_id}: + patch: + tags: + - Comments + summary: Edit a comment + parameters: + - $ref: '#/components/parameters/path_comment_id' + requestBody: + required: true + content: + application/json: + schema: + type: object + additionalProperties: false + required: + - content + properties: + content: + type: string + responses: + '200': + description: Comment updated successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + delete: + tags: + - Comments + summary: Delete a comment + parameters: + - $ref: '#/components/parameters/path_comment_id' + responses: + '200': + description: Comment deleted successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /comments/{comment_id}/like: + post: + tags: + - Comments + summary: Like a comment + parameters: + - $ref: '#/components/parameters/path_comment_id' + responses: + '200': + description: Comment liked successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + delete: + tags: + - Comments + summary: Unlike a comment + parameters: + - $ref: '#/components/parameters/path_comment_id' + responses: + '200': + description: Comment unliked successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + /locations: + get: + tags: + - Locations + summary: Get a list of locations + description: Only available locations are returned + parameters: + - $ref: '#/components/parameters/query_limit' + - $ref: '#/components/parameters/query_offset' + responses: + '200': + description: Locations found + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Location' + '404': + $ref: '#/components/responses/404' + post: + tags: + - Locations + summary: Create a location + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Location' + responses: + '200': + description: Location created successfully + '401': + $ref: '#/components/responses/401' + /locations/{location_id}: + get: + tags: + - Locations + summary: Get a location by id + parameters: + - $ref: '#/components/parameters/path_location_id' + responses: + '200': + description: Location found + content: + application/json: + schema: + $ref: '#/components/schemas/Location' + '404': + $ref: '#/components/responses/404' + put: + tags: + - Locations + summary: Edit a location by id + parameters: + - $ref: '#/components/parameters/path_location_id' + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Location' + responses: + '200': + description: Location updated successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + delete: + tags: + - Locations + summary: Delete a location by id + parameters: + - $ref: '#/components/parameters/path_location_id' + responses: + '200': + description: Location deleted successfully + '401': + $ref: '#/components/responses/401' + '404': + $ref: '#/components/responses/404' + + + + components: + parameters: + path_username: + name: username + in: path + required: true + schema: + type: string + pattern: ^[a-zA-Z0-9]+$ + maxLength: 15 + path_event_id: + name: event_id + in: path + required: true + schema: + type: integer + minimum: 1 + path_location_id: + name: location_id + in: path + required: true + schema: + type: integer + minimum: 1 + path_tag_id: + name: tag_id + in: path + required: true + schema: + type: integer + minimum: 1 + path_comment_id: + name: comment_id + in: path + required: true + schema: + type: integer + minimum: 1 + query_limit: + name: limit + in: query + required: false + schema: + type: integer + minimum: 1 + maximum: 100 + default: 10 + query_offset: + name: offset + in: query + required: false + schema: + type: integer + minimum: 0 + default: 0 + query_desc: + name: desc + in: query + required: false + schema: + type: boolean + default: true schemas: User: type: object + additionalProperties: false required: - username - - password + - nickname + - user_group + - avatar + - user_intro + - user_email properties: id: type: integer description: The auto-generated id of the user readOnly: true - username: + username: type: string description: The username of the user - password: - type: string - description: The password of the user - example: - id: 1 - username: user1 - password: pass1 -tags: [] + nickname: + type: string + user_group: + $ref: '#/components/schemas/UserGroup' + avatar: + type: string + description: The URL of the user's avatar + + user_intro: + type: string + user_email: + type: string + format: email + UserPrivacy: + type: object + additionalProperties: false + required: + - gender + - birthday + - event_history + - following + - followers + - published_events + properties: + gender: + $ref: '#/components/schemas/Gender' + birthday: + type: string + format: date + event_history: + type: array + items: + $ref: '#/components/schemas/Event' + following: + type: array + items: + $ref: '#/components/schemas/User' + followers: + type: array + items: + $ref: '#/components/schemas/User' + published_events: + type: array + items: + $ref: '#/components/schemas/Event' + Gender: + enum: + - 1 + - 2 + - 3 + type: integer + description: >- + 1 = male, 2 = female, 3 = other + UserGroup: + enum: + - 1 + - 2 + - 3 + type: integer + description: >- + 1 = Audience, 2 = Organizer, 3 = Admin + Event: + type: object + additionalProperties: false + required: + - id + - title + - description + - poster + - organizer + - participants + - time + - location + - tags + - status + - comments + - ratings + properties: + id: + type: integer + readOnly: true + title: + type: string + description: + type: string + poster: + type: string + description: The URL of the event's poster + organizer: + $ref: '#/components/schemas/User' + participants: + type: array + items: + $ref: '#/components/schemas/EventParticipant' + time: + type: string + format: date-time + location: + $ref: '#/components/schemas/Location' + tags: + type: array + items: + $ref: '#/components/schemas/EventTag' + status: + $ref: '#/components/schemas/EventStatus' + comments: + type: array + items: + $ref: '#/components/schemas/Comment' + EventParticipant: + type: object + additionalProperties: false + required: + - id + - name + - description + - avatar + properties: + id: + type: integer + readOnly: true + name: + type: string + description: + type: string + avatar: + type: string + EventTag: + type: object + additionalProperties: false + required: + - id + - name + properties: + id: + type: integer + readOnly: true + name: + type: string + EventStatus: + enum: + - 1 + - 2 + - 3 + - 4 + - 5 + type: integer + description: >- + 1 = Draft,2 = Reviewing, 3 = Published, 4 = Ongoing, 5 = Finished, 6 = Cancelled + Comment: + type: object + additionalProperties: false + required: + - id + - user + - content + - time + - likes + properties: + id: + type: integer + readOnly: true + user: + $ref: '#/components/schemas/User' + content: + type: string + time: + type: string + format: date-time + likes: + type: integer + Location: + type: object + additionalProperties: true + required: + - id + - name + - address + - status + - capacity + properties: + id: + type: integer + readOnly: true + name: + type: string + address: + type: string + status: + $ref: '#/components/schemas/LocationStatus' + capacity: + type: integer + LocationStatus: + enum: + - 1 + - 2 + - 3 + type: integer + description: >- + 1 = Available, 2 = Unavailable, 3 = Closed + ErrorDetail: + title: ErrorDetail + additionalProperties: false + required: + - title + - description + type: object + properties: + title: + title: Title + type: string + description: + title: Description + type: string + securitySchemes: + bearerAuth: + type: http + scheme: bearer + bearerFormat: JWT + responses: + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorDetail' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorDetail' + '404': + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorDetail' + '429': + description: Too Many Requests + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorDetail' + '500': + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorDetail' +tags: + - name: Users + description: Operations about users + - name: Events + description: Operations about events + - name: Comments + description: Operations about comments + - name: Locations + description: Operations about locations