From 3f8d9315359baf7c16fca45ac19760c3033b5e55 Mon Sep 17 00:00:00 2001 From: Fernando Jose Gonzalez Sierra Date: Sun, 28 Apr 2024 12:17:51 +0200 Subject: [PATCH] =?UTF-8?q?OpenAPI=20update=20y=20bot=C3=B3n=20finalizar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatewayservice/gateway-service.js | 4 +- gatewayservice/openapi.yaml | 125 ++++++++------------------- webapp/src/components/Pages/Juego.js | 3 +- 3 files changed, 39 insertions(+), 93 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 918b9df..363400a 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -93,7 +93,7 @@ app.get('/getUserData', async (req, res) => { const { username } = req.query; try{ const getUserDataResponse = await axios.get(userServiceUrl+ `/getUserData?username=${username}`) - res.json(getUserDataResponse.data); + res.status(200).json(getUserDataResponse.data); }catch(error){ res.status(error.response.status).json({error: error.response.data.error}); } @@ -102,7 +102,7 @@ app.get('/getUserData', async (req, res) => { app.get('/getUsernames', async (req, res) => { try{ const getUserDataResponse = await axios.get(userServiceUrl+ `/getUsernames`) - res.json(getUserDataResponse.data); + res.status(200).json(getUserDataResponse.data); }catch(error){ res.status(error.response.status).json({error: error.response.data.error}); } diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index 31a02ff..aec74e7 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -183,21 +183,23 @@ paths: type: string description: Error information. example: Internal Server Error - /updateCorrectAnswers: + /updateStats: get: summary: Updates the data of the user, increasing his number of correct answers. - operationId: updateCorrectAnswers + operationId: updateStats parameters: in: path name: params required: true - description: Parameters for the update (username and numAnswers) + description: Parameters for the update (username, numRespuestsasCorrectas, numRespuestasIncorrectas) schema: type: object properties: username: type: string - numAnswers: + numRespuestsasCorrectas: + type: integer + numRespuestasIncorrectas: type: integer responses: '200': @@ -213,63 +215,16 @@ paths: message: type: string example: Respuestas correctas actualizada con éxito - '404': - description: The user is not found. - content: - application/json: - schema: - type: object - properties: - success: - type: boolean - example: false - message: - type: string - example: Usuario no encontrado - '500': - description: Internal server error. - content: - application/json: - schema: - type: object - properties: - success: - type: boolean - example: false - message: - type: string - description: Error information. - example: Error al actualizar las respuestas correctas - /updateIncorrectAnswers: - get: - summary: Updates the data of the user, increasing his number of incorrect answers. - operationId: updateIncorrectAnswers - parameters: - in: path - name: params - required: true - description: Parameters for the update (username and numAnswers) - schema: - type: object - properties: - username: - type: string - numAnswers: - type: integer - responses: - '200': - description: Updates the data correctly. + '401': + description: Params needed for the get action. content: application/json: schema: type: object properties: - success: - type: boolean - example: true - message: + error: type: string - example: Respuestas incorrectas actualizada con éxito + example: Faltan parámetros en la solicitud. '404': description: The user is not found. content: @@ -296,16 +251,16 @@ paths: message: type: string description: Error information. - example: Error al actualizar las respuestas incorrectas - /updateCompletedGames: + example: Error al actualizar las respuestas correctas + /getUserData: get: - summary: Update the number of completed games by the user. - operationId: updateCompletedGames + summary: Gets the data of an user. + operationId: getUserData parameters: in: path name: username required: true - description: Username for the update of data + description: Username for the search of data schema: type: string responses: @@ -316,12 +271,22 @@ paths: schema: type: user properties: - success: - type: boolean - example: true - message: + username: type: string - example: Juegos completados actualizado con éxito + example: Pablo + password: + type: integer + example: pass + createdAt: + type: date + correctAnswers: + type: integer + incorrectAnswers: + type: integer + completedGames: + type: integer + averageTime: + type: integer '404': description: The user is not found. content: @@ -348,21 +313,14 @@ paths: message: type: string description: Error information. - example: Error al actualizar Juegos completados - /getUserData: + example: Error al obtener los datos de usuario + /getUsernames: get: - summary: Gets the data of an user. - operationId: getUserData - parameters: - in: path - name: username - required: true - description: Username for the search of data - schema: - type: string + summary: Gets all the usernames. + operationId: getUsernames responses: '200': - description: Finds the data of the user correctly. + description: Finds the data of the user correctly (or no users). content: application/json: schema: @@ -384,19 +342,6 @@ paths: type: integer averageTime: type: integer - '404': - description: The user is not found. - content: - application/json: - schema: - type: object - properties: - success: - type: boolean - example: false - message: - type: string - example: Usuario no encontrado '500': description: Internal server error. content: diff --git a/webapp/src/components/Pages/Juego.js b/webapp/src/components/Pages/Juego.js index 025cfaf..a8c2818 100644 --- a/webapp/src/components/Pages/Juego.js +++ b/webapp/src/components/Pages/Juego.js @@ -224,7 +224,8 @@ const Juego = ({isLogged, username, numPreguntas}) => { {finishGame ? <>

PARTIDA FINALIZADA

ACERTADAS: {numRespuestasCorrectas} FALLADAS: {numRespuestasIncorrectas}

- + { !disableFinish ? + : <> } : <>} { disableFinish ? (

Comience nueva partida o visite sus estadísticas!!

)