diff --git a/auth_service/README.md b/auth_service/README.md deleted file mode 100644 index 5ba65b25..00000000 --- a/auth_service/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# Auth Service - -## How to use -To get an auth token simply send the following json to the /api/auth/login endpoint - -```json -{ - "username" : username, - "password" : password -} -``` - -To register a new account send the following json to the /api/auth/register endpoint - -```json -{ - "username" : username, - "password" : password -} -``` diff --git a/auth_service/openapi.yaml b/auth_service/openapi.yaml index 35656ce1..0b1b258b 100644 --- a/auth_service/openapi.yaml +++ b/auth_service/openapi.yaml @@ -8,7 +8,8 @@ servers: paths: /api/auth/register: post: - summary: Register a new user + summary: Register User + description: Registers a new user. requestBody: required: true content: @@ -18,13 +19,13 @@ paths: properties: username: type: string - example: user123 + description: Username of the new user. password: type: string - example: password123 + description: Password of the new user. responses: '201': - description: User successfully registered + description: Created content: application/json: schema: @@ -32,9 +33,9 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for the registered user. '200': - description: Username already exists + description: OK content: application/json: schema: @@ -42,13 +43,14 @@ paths: properties: error: type: string - example: "Nombre de usuario no disponible" + description: Error message if registration fails. '500': - description: Internal server error + description: Internal Server Error /api/auth/login: post: - summary: Log in with username and password + summary: User Login + description: Logs in an existing user. requestBody: required: true content: @@ -58,13 +60,13 @@ paths: properties: username: type: string - example: user123 + description: Username of the user. password: type: string - example: password123 + description: Password of the user. responses: '200': - description: User logged in successfully + description: OK content: application/json: schema: @@ -72,9 +74,9 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for the logged-in user. '401': - description: Invalid username or password + description: Unauthorized content: application/json: schema: @@ -82,13 +84,14 @@ paths: properties: error: type: string - example: "Usuario o contraseƱa incorrectos" + description: Error message if login fails. '500': - description: Internal server error + description: Internal Server Error /api/auth/verify: post: - summary: Verify user authentication token + summary: Verify Token + description: Verifies the validity of a JWT token. requestBody: required: true content: @@ -98,35 +101,53 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token to verify. responses: '200': - description: Token is valid + description: OK '401': - description: Invalid or expired token + description: Unauthorized '500': - description: Internal server error + description: Internal Server Error - /health: - get: - summary: Health check endpoint + /api/auth/getName: + post: + summary: Get Username + description: Retrieves the username of the authenticated user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. responses: '200': - description: Service is healthy + description: OK content: application/json: schema: type: object properties: - status: + name: type: string - example: "OK" + description: Username of the authenticated user. + createdAt: + type: string + format: date-time + description: Creation date of the authenticated user's account. + '400': + description: Bad Request '500': - description: Internal server error + description: Internal Server Error /api/user/getUsers: get: - summary: Obtener todos los usuarios + summary: Get All Users + description: Retrieves the list of all users. responses: '200': description: OK @@ -139,21 +160,24 @@ paths: properties: name: type: string - example: "User1" + description: Username of the user. id: type: integer - example: "1234" + description: ID of the user. + '500': + description: Internal Server Error /api/user/getUser: get: - summary: Obtener un usuario por ID + summary: Get User by ID + description: Retrieves a user by their ID. parameters: - - in: query - name: user_id + - name: user_id + in: query required: true schema: type: integer - example: "1234" + description: ID of the user to retrieve. responses: '200': description: OK @@ -165,30 +189,48 @@ paths: user: type: object properties: - name: - type: string - example: "User1" id: type: integer - example: "1234" - '401': - description: Usuario no encontrado - requestBody: - required: false - content: - application/json: {} + description: ID of the user. + name: + type: string + description: Username of the user. + '400': + description: Bad Request + '500': + description: Internal Server Error /api/user/deleteUser: post: - summary: Eliminar un usuario por ID - requestBody: - required: true - content: - application/json: {} + summary: Delete User + description: Deletes a user by their ID. + parameters: + - name: user_id + in: query + required: true + schema: + type: integer + description: ID of the user to delete. responses: '200': - description: Usuario borrado + description: OK + content: + application/json: + schema: + type: object + properties: + message: + type: string + description: Success message after user deletion. '401': - description: Usuario no encontrado + description: Unauthorized + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error message if user deletion fails. '500': - description: Error del servidor + description: Internal Server Error diff --git a/friends_service/openapi.yaml b/friends_service/openapi.yaml index 597cf9ca..a9e6bc02 100644 --- a/friends_service/openapi.yaml +++ b/friends_service/openapi.yaml @@ -8,7 +8,8 @@ servers: paths: /api/friends/request/send: post: - summary: Send friend request + summary: Send Friend Request + description: Sends a friend request to another user. requestBody: required: true content: @@ -18,21 +19,20 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTY3ODkwLCJpYXQiOjE1MTYyMzkwMjJ9.UzI1NiIsInR5cCI6IkpXVCJ9" + description: JWT token for authentication. to: type: string - example: "user_id_to_send_request" - required: - - token - - to + description: ID of the user to send the request to. responses: '200': description: OK '400': - description: Invalid request or there is already a pending request or they are already friends + description: Bad Request + /api/friends/request/accept: post: - summary: Accept friend request + summary: Accept Friend Request + description: Accepts a friend request from another user. requestBody: required: true content: @@ -42,21 +42,20 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTY3ODkwLCJpYXQiOjE1MTYyMzkwMjJ9.UzI1NiIsInR5cCI6IkpXVCJ9" + description: JWT token for authentication. from: type: string - example: "user_id_of_request_sender" - required: - - token - - from + description: ID of the user who sent the request. responses: '200': - description: Friend request accepted + description: OK '400': - description: Invalid request or request not found + description: Bad Request + /api/friends/request/: post: - summary: Get pending friend requests + summary: Get Friend Requests + description: Retrieves friend requests received by the authenticated user. requestBody: required: true content: @@ -66,15 +65,30 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTY3ODkwLCJpYXQiOjE1MTYyMzkwMjJ9.UzI1NiIsInR5cCI6IkpXVCJ9" - required: - - token + description: JWT token for authentication. responses: '200': description: OK + content: + application/json: + schema: + type: array + items: + type: object + properties: + from: + type: string + description: ID of the user who sent the request. + to: + type: string + description: ID of the user who received the request. + '400': + description: Bad Request + /api/friends/: post: - summary: Get friends list + summary: Get Friends + description: Retrieves the list of friends of the authenticated user. requestBody: required: true content: @@ -84,29 +98,22 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMjM0NTY3ODkwLCJpYXQiOjE1MTYyMzkwMjJ9.UzI1NiIsInR5cCI6IkpXVCJ9" - required: - - token + description: JWT token for authentication. responses: '200': description: OK -components: - schemas: - FriendRequest: - type: object - properties: - from: - type: string - example: "user_id_of_request_sender" - to: - type: string - example: "user_id_to_receive_request" - Friendship: - type: object - properties: - friend1: - type: string - example: "user_id1" - friend2: - type: string - example: "user_id2" + content: + application/json: + schema: + type: array + items: + type: object + properties: + friend1: + type: string + description: ID of the first friend. + friend2: + type: string + description: ID of the second friend. + '400': + description: Bad Request diff --git a/game_service/openapi.yaml b/game_service/openapi.yaml index 6e80675d..fa6620bd 100644 --- a/game_service/openapi.yaml +++ b/game_service/openapi.yaml @@ -8,7 +8,8 @@ servers: paths: /api/game/new: post: - summary: Start a new game + summary: Create New Game + description: Creates a new game session for the user. requestBody: required: true content: @@ -18,18 +19,25 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. + tags: + type: string + description: Comma-separated list of tags for game questions (optional). + gameMode: + type: string + description: Mode of the game (e.g., single-player, multiplayer). responses: '200': - description: New game started successfully - '401': - description: Invalid token + description: OK + '400': + description: Bad Request '500': - description: Internal server error + description: Internal Server Error /api/game/next: post: - summary: Get the next question in the game + summary: Get Next Question + description: Retrieves the next question in the game session. requestBody: required: true content: @@ -39,10 +47,13 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. + lang: + type: string + description: Language code for question language (e.g., 'en', 'es'). responses: '200': - description: Next question retrieved successfully + description: OK content: application/json: schema: @@ -50,23 +61,27 @@ paths: properties: title: type: string - example: "What is the capital of France?" + description: Title of the question. + lang: + type: string + description: Language of the question. imageUrl: type: string - example: "https://example.com/image.jpg" + description: URL of the image associated with the question (optional). awnsers: type: array items: type: string - example: ["Paris", "London", "Berlin", "Rome"] - '401': - description: Invalid token + description: Possible answers to the question. + '400': + description: Bad Request '500': - description: Internal server error + description: Internal Server Error /api/game/awnser: post: - summary: Submit an answer to the current question + summary: Submit Answer + description: Submits the answer to the current question in the game session. requestBody: required: true content: @@ -76,26 +91,22 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. awnser: type: string - example: "Paris" + description: User's answer to the question. responses: '200': - description: Answer submitted successfully - content: - application/json: - schema: - type: string - example: "Correct" - '401': - description: Invalid token + description: OK + '400': + description: Bad Request '500': - description: Internal server error + description: Internal Server Error /api/game/update: post: - summary: Update the current game state + summary: Update Question + description: Updates the current question in the game session. requestBody: required: true content: @@ -105,10 +116,10 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. responses: '200': - description: Game state updated successfully + description: OK content: application/json: schema: @@ -116,22 +127,235 @@ paths: properties: title: type: string - example: "What is the capital of France?" + description: Title of the question. imageUrl: type: string - example: "https://example.com/image.jpg" + description: URL of the image associated with the question (optional). awnsers: type: array items: type: string - example: ["Paris", "London", "Berlin", "Rome"] + description: Possible answers to the question. created: type: string - example: "1647865400000" + format: date-time + description: Timestamp of when the question was created. duration: type: string - example: "30" - '401': - description: Invalid token + description: Duration of the question. + numberOfQuestions: + type: integer + description: Total number of questions in the game session. + questionNumber: + type: integer + description: Number of the current question. + '400': + description: Bad Request + '500': + description: Internal Server Error + + /api/game/settings: + post: + summary: Get Game Settings + description: Retrieves the game settings for the authenticated user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + durationQuestion: + type: integer + description: Duration of each question in seconds. + numberOfQuestions: + type: integer + description: Number of questions per game session. + '500': + description: Internal Server Error + + /api/game/updatesettings: + post: + summary: Update Game Settings + description: Updates the game settings for the authenticated user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + durationQuestion: + type: integer + description: Duration of each question in seconds. + numberOfQuestions: + type: integer + description: Number of questions per game session. + responses: + '200': + description: OK + '400': + description: Bad Request + '500': + description: Internal Server Error + + /api/game/getHistory: + post: + summary: Get Game History + description: Retrieves the game history for the authenticated user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + type: object + properties: + id: + type: integer + description: ID of the game. + createdAt: + type: string + format: date-time + description: Timestamp of when the game was created. + updatedAt: + type: string + format: date-time + description: Timestamp of when the game was last updated. + '500': + description: Internal Server Error + /api/game/getHistoryByUser: + post: + summary: Get Game History By User + description: Retrieves the game history for a specified user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + userId: + type: string + description: ID of the user to retrieve game history for. + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + type: object + properties: + id: + type: integer + description: ID of the game. + createdAt: + type: string + format: date-time + description: Timestamp of when the game was created. + updatedAt: + type: string + format: date-time + description: Timestamp of when the game was last updated. + '400': + description: Bad Request + '500': + description: Internal Server Error + + /api/game/getNumberOfQuestions: + post: + summary: Get Number of Questions + description: Retrieves the total number of questions in the current game session. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + numberOfQuestions: + type: integer + description: Total number of questions in the current game session. + '500': + description: Internal Server Error + + /api/game/currentquestion: + post: + summary: Get Current Question + description: Retrieves the current question in the game session. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + question: + type: object + properties: + id: + type: integer + description: ID of the question. + title: + type: string + description: Title of the question. + imageUrl: + type: string + description: URL of the image associated with the question (optional). + awnsers: + type: array + items: + type: string + description: Possible answers to the question. '500': - description: Internal server error + description: Internal Server Error diff --git a/game_service/readme.md b/game_service/readme.md deleted file mode 100644 index 1dcdff91..00000000 --- a/game_service/readme.md +++ /dev/null @@ -1,99 +0,0 @@ -# Game API documentation -***Important**: App is listening on port 8003* -## New game endpoint -### URL -``` -/api/game/new -``` -### How to use -Needs the token for authentication, no further parameters required, it creates a new game. - -*returns 200 Ok on success.* - -Example request: -```json -{ - "token":"eyDVhZGFkODgtMjUyiaWTQQ8" -} -``` -## Next question endpoint -### URL -``` -/api/game/next -``` -### How to use -Needs the token for authentication, no further parameters required, it creates a new question. - - -*returns 200 Ok and the question on success.* - -Example request: -```json -{ - "token":"eyDVhZGFkODgtMjUyiaWTQQ8" -} -``` -Example awnser: -```json -{ - "title": "Cual es la capital de Kosovo", - "awnsers": [ - "Pristina", - "Yantzaza", - "Florencia", - "Arzew" - ] -} -``` - -## Update question endpoint -### URL -``` -/api/game/update -``` -### How to use -Needs the token for authentication, no further parameters required, it gives the data of the current question. - -*returns 200 Ok and the question on success.* - -Example request: -```json -{ - "token":"eyDVhZGFkODgtMjUyiaWTQQ8" -} -``` -Example awnser: -```json -{ - "title": "Cual es la capital de Kosovo", - "awnsers": [ - "Pristina", - "Yantzaza", - "Florencia", - "Arzew" - ], - // This params can and should be used to calculate the remaining time - "created": "1708527343000", //These are UNIXMILIS, use current UNIXMILIS to know the remaining time. - "duration": "20" //Duration of the question in seconds -``` -## Awnser question endpoint -### URL -``` -/api/game/awnser -``` -### How to use -Needs the token for authentication and the awnser of the question, it gives back the correct awnser. - -*returns 200 Ok and the awnser on success.* - -Example request: -```json -{ - "token":"eyDVhZGFkODgtMjUyiaWTQQ8", - "awnser": "Arzew" -} -``` -Example awnser: -```json -Pristina -``` \ No newline at end of file diff --git a/question_service/README.md b/question_service/README.md index 36d81590..04cad091 100644 --- a/question_service/README.md +++ b/question_service/README.md @@ -1,30 +1,5 @@ # Question generation API -## How to use +## How to add more templates +The templates are loaded into a MongoDB database from templates.json, if you want to add new templates simply add them into templates.json in the form of an array, the templates will have the format specified in [ADR 12](https://github.com/Arquisoft/wiq_es1c/wiki/ADR-12-%28Question-Templates%29) -To use the app simply send a GET request to port _23123_ with the format /generate, the response will follow the following format: - -```json -{ - "title": "question goes here", - "imageUrl": "url of image goes here OPTIONAL", - "awnser": "true anwser goes here", - "fake": ["these", "are", "fake"] -} -``` - ---- - -## Developer Zone! - -### How to add more templates - -To add a new template simply add the to the apropiate generator inside /questionGenerators - -**\*NOTE:** Please keep in mind the existing types of questions (Geography)\* - -The generator **must** be an async function that returns the generated question in the apropiate format - -### Wikidata - -The file wikidata.js exposes a function to call wikidata using SPARQL to find the necessary information for the questions, you **dont** have to worry about doing the same query multiple times as the function has an builtin cache. diff --git a/question_service/openapi.yaml b/question_service/openapi.yaml index 2a7ad0ab..0141f10e 100644 --- a/question_service/openapi.yaml +++ b/question_service/openapi.yaml @@ -8,40 +8,58 @@ servers: paths: /api/questions/generate: post: - summary: Generate a random question + summary: Generate Question + description: Generates a new question using a random template. responses: '200': - description: Random question generated successfully + description: OK content: application/json: schema: - type: object - properties: - title: - type: string - description: The question text - example: "What is the capital of France?" - imageUrl: - type: string - description: The URL of an optional image related to the question - example: "https://example.com/image.jpg" - awnser: - type: string - description: The correct answer to the question - example: "Paris" - fake: - type: array - description: An array of fake answers - items: - type: string - example: ["London", "Berlin", "Rome"] + $ref: '#/components/schemas/GeneratedQuestion' '500': - description: Failed to generate question + description: Internal Server Error + + /api/questions/tags: + post: + summary: Get All Tags + description: Retrieves all available tags for question generation. + responses: + '200': + description: OK content: application/json: schema: - type: object - properties: - error: - type: string - example: "Failed to generate question" + type: array + items: + type: string + '500': + description: Internal Server Error + +components: + schemas: + GeneratedQuestion: + type: object + properties: + title: + type: string + description: The generated question title with placeholders replaced. + answer: + type: string + description: The correct answer to the question. + fake: + type: array + items: + type: string + description: An array of three different fake answers. + tags: + type: array + items: + type: string + description: An array of associated tags for the question. + lang: + type: string + description: The language of the question. + imageUrl: + type: string + description: URL of the image associated with the question (optional). diff --git a/userdetails_service/openapi.yaml b/userdetails_service/openapi.yaml index a818b7cf..dc6d7a66 100644 --- a/userdetails_service/openapi.yaml +++ b/userdetails_service/openapi.yaml @@ -8,7 +8,8 @@ servers: paths: /api/userdetails/name: post: - summary: Get user's name + summary: Get User Name + description: Retrieves the name and creation date of the authenticated user. requestBody: required: true content: @@ -18,10 +19,10 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. responses: '200': - description: User name retrieved successfully + description: OK content: application/json: schema: @@ -29,17 +30,18 @@ paths: properties: name: type: string - example: "John" - '400': - description: Invalid user or error retrieving user name - '401': - description: Invalid token + description: User's name. + createdAt: + type: string + format: date-time + description: Timestamp of user creation. '500': - description: Internal server error + description: Internal Server Error /api/userdetails/history: post: - summary: Get user's game history + summary: Get User History + description: Retrieves the game history for the authenticated user. requestBody: required: true content: @@ -49,57 +51,107 @@ paths: properties: token: type: string - example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." + description: JWT token for authentication. responses: '200': - description: User game history retrieved successfully + description: OK content: application/json: schema: type: array items: - type: object - properties: - id: - type: string - example: "ecadb470-b62c-42de-bb38-66b6b1d3b3c3" - createdAt: - type: string - format: date-time - example: "2024-03-19T08:39:34.000Z" - updatedAt: - type: string - format: date-time - example: "2024-03-19T08:39:34.000Z" - UserId: - type: string - example: "beb91682-e280-414a-a07e-7d9f3ee9add6" - Questions: - type: array - items: - type: object - properties: - id: - type: string - title: - type: string - imageUrl: - type: string - awnsers: - type: array - items: - type: string - created: - type: string - duration: - type: string - user_answer: - type: string - onTime: - type: boolean + $ref: '#/components/schemas/GameHistory' + '500': + description: Internal Server Error + + /api/userdetails/history-by-user: + post: + summary: Get User History By User + description: Retrieves the game history for a specified user. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + token: + type: string + description: JWT token for authentication. + userId: + type: string + description: ID of the user to retrieve game history for. + responses: + '200': + description: OK + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/GameHistory' '400': - description: Invalid user or error retrieving game history - '401': - description: Invalid token + description: Bad Request '500': - description: Internal server error + description: Internal Server Error + +components: + schemas: + GameHistory: + type: object + properties: + id: + type: string + description: ID of the game. + createdAt: + type: string + format: date-time + description: Timestamp of when the game was created. + updatedAt: + type: string + format: date-time + description: Timestamp of when the game was last updated. + questions: + type: array + items: + $ref: '#/components/schemas/Question' + Question: + type: object + properties: + id: + type: string + description: ID of the question. + title: + type: string + description: The question's title. + imageUrl: + type: string + description: URL of the image associated with the question. + answer: + type: string + description: The correct answer to the question. + fake: + type: array + items: + type: string + description: Array of fake answers. + user_answer: + type: string + description: The user's answer to the question. + duration: + type: integer + description: Duration of the question in seconds. + onTime: + type: boolean + description: Indicates whether the user answered the question within the allotted time. + createdAt: + type: string + format: date-time + description: Timestamp of when the question was created. + updatedAt: + type: string + format: date-time + description: Timestamp of when the question was last updated. + gameId: + type: string + description: ID of the game the question belongs to.