From 0b46e065f50d0c0a9b12ca173b576ab499a17fad Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 12:03:40 +0200 Subject: [PATCH 1/9] Removed duplicated file --- webapp/openapi.yaml | 313 -------------------------------------------- 1 file changed, 313 deletions(-) delete mode 100644 webapp/openapi.yaml diff --git a/webapp/openapi.yaml b/webapp/openapi.yaml deleted file mode 100644 index 98968bbf..00000000 --- a/webapp/openapi.yaml +++ /dev/null @@ -1,313 +0,0 @@ -openapi: 3.0.0 -info: - title: wiq_en1b API - description: Our project's OpenAPI specification. - version: 0.1.2 - contact: - name: Project github - url: https://github.com/Arquisoft/wiq_en1b -servers: - - url: http://localhost:8000 - description: Development server - - url: http://SOMEIP:8000 - description: Production server -paths: - /adduser: - post: - summary: Add a new user to the database. - operationId: addUser - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - username: - type: string - description: User ID. - example: student - password: - type: string - description: User password. - example: pass - responses: - '200': - description: User added successfully. - content: - application/json: - schema: - type: object - properties: - username: - type: string - description: User ID - '400': - description: Failed to add user - content: - application/json: - schema: - type: object - properties: - error: - type: string - description: Error information. - example: Username already in use - '500': - description: Internal server error. - content: - application/json: - schema: - type: object - properties: - error: - type: string - description: Error information. - example: Internal Server Error - /health: - get: - summary: Check the health status of the service. - operationId: checkHealth - responses: - '200': - description: Service is healthy. - content: - application/json: - schema: - type: object - properties: - status: - type: string - description: Health status. - example: OK - /login: - post: - summary: Log in to the system. - operationId: loginUser - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - username: - type: string - description: User ID. - example: student - password: - type: string - description: User password. - example: pass - responses: - '200': - description: Login successful. Returns user token, and username. - content: - application/json: - schema: - type: object - properties: - token: - type: string - description: User token. - example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWY3NTZkYjNmYTIyZDIyN2E0YjdjN2QiLCJpYXQiOjE3MTA3MDg3NDUsImV4cCI6MTcxMDcxMjM0NX0.VMG_5DOyQ4GYlJQRcu1I6ICG1IGzuo2Xuei093ONHxw - username: - type: string - description: Username. - example: student - '400': - description: Invalid credentials. - content: - application/json: - schema: - type: object - properties: - error: - type: string - description: Shows the error info.. - example: Invalid credentials - '500': - description: Internal server error. - content: - application/json: - schema: - type: object - properties: - error: - type: string - description: Error information. - example: Internal Server Error - /questions: - get: - summary: Get 5 random questions from the system in any language - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/QuestionResponse' - /questions/{lang}: - get: - summary: Get 5 random questions from the system in the lang specified - parameters: - - name: lang - in: path - required: true - schema: - type: string - description: Language code for filtering questions must be es or en - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/QuestionResponse' - /record: - post: - summary: Add a new record to the database - requestBody: - required: true - content: - application/json: - schema: - $ref: '#/components/schemas/Record' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - user: - type: string - /record/{user}: - get: - summary: Gets the records from a given user - parameters: - - name: user - in: path - required: true - schema: - type: string - description: Username for filtering records - responses: - '200': - description: OK - content: - application/json: - schema: - $ref: '#/components/schemas/RecordResponse' -components: - schemas: - LoginRequest: - type: object - properties: - username: - type: string - password: - type: string - required: - - username - - password - LoginResponse: - type: object - properties: - token: - type: string - User: - type: object - properties: - username: - type: string - email: - type: string - required: - - username - - email - UserResponse: - type: object - properties: - message: - type: string - QuestionResponse: - type: array - items: - type: object - properties: - question: - type: string - answers: - type: array - items: - type: string - correct_answer: - type: string - Record: - type: object - properties: - user: - type: string - game: - type: object - properties: - questions: - type: array - items: - type: object - properties: - question: - type: string - example: What is the capital of Oviedo? - answers: - type: array - items: - type: string - answerGiven: - type: string - correctAnswer: - type: string - points: - type: number - date: - type: string - required: - - user - - game - RecordResponse: - type: object - properties: - user: - type: string - games: - type: array - items: - type: object - properties: - questions: - type: array - items: - type: object - properties: - question: - type: string - example: What is the capital of Oviedo? - answers: - type: array - items: - type: string - answerGiven: - type: string - correctAnswer: - type: string - points: - type: number - date: - type: string - Error: - type: object - properties: - error: - type: string \ No newline at end of file From 610de2bb1571065b0a06d67882ba92fde4c1b99e Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Wed, 24 Apr 2024 12:56:48 +0200 Subject: [PATCH 2/9] Modified user endpoints documentation --- gatewayservice/openapi.yaml | 61 ++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index 47615d2a..3b44ddec 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -9,9 +9,25 @@ info: servers: - url: http://localhost:8000 description: Development server - - url: http://wiqen1b.serveminecraft.net:8000 + - url: http://wiqen1b.serveminecraft.net:8000 description: Production server paths: + /health: + get: + summary: Check the health status of the service. + operationId: checkHealth + responses: + '200': + description: Service is healthy. + content: + application/json: + schema: + type: object + properties: + status: + type: string + description: Health status. + example: OK /adduser: post: summary: Add a new user to the database. @@ -37,11 +53,7 @@ paths: content: application/json: schema: - type: object - properties: - username: - type: string - description: User ID + $ref: '#/components/shcemas/LoginResponse' '400': description: Failed to add user content: @@ -64,22 +76,6 @@ paths: type: string description: Error information. example: Internal Server Error - /health: - get: - summary: Check the health status of the service. - operationId: checkHealth - responses: - '200': - description: Service is healthy. - content: - application/json: - schema: - type: object - properties: - status: - type: string - description: Health status. - example: OK /login: post: summary: Log in to the system. @@ -93,28 +89,19 @@ paths: properties: username: type: string - description: User ID. + description: UserID. example: student password: type: string - description: User password. + description: Userpassword. example: pass responses: '200': - description: Login successful. Returns user token, and username. + description: Login successful. Returns user token, username and email. content: application/json: schema: - type: object - properties: - token: - type: string - description: User token. - example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWY3NTZkYjNmYTIyZDIyN2E0YjdjN2QiLCJpYXQiOjE3MTA3MDg3NDUsImV4cCI6MTcxMDcxMjM0NX0.VMG_5DOyQ4GYlJQRcu1I6ICG1IGzuo2Xuei093ONHxw - username: - type: string - description: Username. - example: student + $ref: '#/components/shcemas/LoginResponse' '400': description: Invalid credentials. content: @@ -217,6 +204,10 @@ components: properties: token: type: string + username: + type: string + email: + type: string User: type: object properties: From 0f83f6a88c9a75ac8141df15e6560ecbd2b5d603 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Wed, 24 Apr 2024 13:53:30 +0200 Subject: [PATCH 3/9] Modified questions endpoints documentation --- gatewayservice/openapi.yaml | 135 +++++++++++++++++++++++++++++++----- 1 file changed, 119 insertions(+), 16 deletions(-) diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index 3b44ddec..1e9df50f 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -107,23 +107,13 @@ paths: content: application/json: schema: - type: object - properties: - error: - type: string - description: Shows the error info.. - example: Invalid credentials + $ref: '#/components/shcemas/Error' '500': description: Internal server error. content: application/json: schema: - type: object - properties: - error: - type: string - description: Error information. - example: Internal Server Error + $ref: '#/components/shcemas/Error' /questions: get: summary: Get 5 random questions from the system in any language @@ -133,7 +123,13 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/QuestionResponse' + $ref: '#/components/schemas/QuestionResponse' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' /questions/{lang}: get: summary: Get 5 random questions from the system in the lang specified @@ -143,7 +139,97 @@ paths: required: true schema: type: string - description: Language code for filtering questions must be es or en + enum: [es, en, tr] + description: Language code for filtering questions + security: + - BearerAuth: [] + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/QuestionResponse' + '400': + description: Wrong values given. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + /questions/{lang}/{amount}: + get: + summary: Get an amount of random questions from the system in the lang specified + parameters: + - name: lang + in: path + required: true + schema: + type: string + enum: [es, en, tr] + description: Language code for filtering questions + - name: amount + in: path + required: true + schema: + type: integer + minimun: 1 + maximun: 20 + description: Amount of questions retrieved + security: + - BearerAuth: [] + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/QuestionResponse' + '400': + description: Wrong values given. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + /questions/{lang}/{amount}/{type}: + get: + summary: Get an amount of questions of the given type from the system in the lang specified + parameters: + - name: lang + in: path + required: true + schema: + type: string + enum: [es, en, tr] + description: Language code for filtering questions + - name: amount + in: path + required: true + schema: + type: integer + minimun: 1 + maximun: 20 + description: Amount of questions retrieved + - name: type + in: path + required: true + schema: + type: string + enum: [POPULATION, CAPITAL, LANGUAGE, SIZE] + description: Type for filtering questions + security: + - BearerAuth: [] responses: '200': description: OK @@ -151,6 +237,18 @@ paths: application/json: schema: $ref: '#/components/schemas/QuestionResponse' + '400': + description: Wrong values given. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' /record: post: summary: Add a new record to the database @@ -188,6 +286,11 @@ paths: schema: $ref: '#/components/schemas/RecordResponse' components: + securitySchemes: + BearerAuth: + type: http + scheme: bearer + bearerFormat: JWT schemas: LoginRequest: type: object @@ -261,7 +364,7 @@ components: correctAnswer: type: string points: - type: number + type: integer date: type: string required: @@ -294,7 +397,7 @@ components: correctAnswer: type: string points: - type: number + type: integer date: type: string Error: From 46fa6c8e5eb93b558a8efeedeb725d76f6a0eb30 Mon Sep 17 00:00:00 2001 From: ErdemYabaci Date: Wed, 24 Apr 2024 15:12:59 +0200 Subject: [PATCH 4/9] Modified record endpoints documentation --- gatewayservice/openapi.yaml | 88 ++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index 1e9df50f..d721ac42 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -258,6 +258,8 @@ paths: application/json: schema: $ref: '#/components/schemas/Record' + security: + - BearerAuth: [] responses: '200': description: OK @@ -268,6 +270,12 @@ paths: properties: user: type: string + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' /record/{user}: get: summary: Gets the records from a given user @@ -278,6 +286,8 @@ paths: schema: type: string description: Username for filtering records + security: + - BearerAuth: [] responses: '200': description: OK @@ -285,6 +295,67 @@ paths: application/json: schema: $ref: '#/components/schemas/RecordResponse' + '400': + description: Wrong values given. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + /record/ranking/top10: + get: + summary: Gets the top 10 users on the system + security: + - BearerAuth: [] + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Top10Ranking' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + /record/ranking/{user}: + get: + summary: Gets the ranking information of the given user + parameters: + - name: user + in: path + required: true + schema: + type: string + description: username of the user + security: + - BearerAuth: [] + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/UserRanking' + '400': + description: Wrong values given. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' + '500': + description: Internal server error. + content: + application/json: + schema: + $ref: '#/components/shcemas/Error' components: securitySchemes: BearerAuth: @@ -404,4 +475,19 @@ components: type: object properties: error: - type: string \ No newline at end of file + type: string + UserRanking: + type: object + properties: + _id: + type: string + totalPoints: + type: integer + totalCompetitiveGames: + type: integer + position: + type: integer + Top10Ranking: + type: array + items: + $ref: '#/components/schemas/UserRanking' \ No newline at end of file From 0dc1658d63e12a35c545ff2d84e16fa4e0d1c4d6 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Wed, 24 Apr 2024 18:56:08 +0200 Subject: [PATCH 5/9] Tested that it works against swaggerEditor online --- gatewayservice/gateway-service.js | 24 ++-- gatewayservice/openapi.yaml | 177 ++++++++++++++++-------------- 2 files changed, 104 insertions(+), 97 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index c08d0e37..f592f9e0 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -33,7 +33,7 @@ app.post('/login', async (req, res) => { const authResponse = await axios.post(authServiceUrl+'/login', req.body); res.json(authResponse.data); } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -43,7 +43,7 @@ app.post('/adduser', async (req, res) => { const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); res.json(userResponse.data); } catch (error) { - manageError(error); + manageError(res, error); } }); @@ -55,7 +55,7 @@ app.get('/questions', verifyToken, async (req, res) => { const questionResponse = await axios.get(questionServiceUrl+'/questions'); res.json(questionResponse.data); } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -78,7 +78,7 @@ app.get('/questions/:lang/:amount/:type', verifyToken, async (req, res) => { } } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -97,7 +97,7 @@ app.get('/questions/:lang/:amount', verifyToken, async (req, res) => { res.json(questionResponse.data); } } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -115,7 +115,7 @@ app.get('/questions/:lang', verifyToken, async (req, res) => { } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -126,7 +126,7 @@ app.post('/record', verifyToken, async(req, res) => { const recordResponse = await axios.post(recordServiceUrl+'/record', req.body); res.json(recordResponse.data); } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -136,7 +136,7 @@ app.get('/record/ranking/top10', verifyToken, async(req, res)=>{ const recordResponse = await axios.get(recordServiceUrl + '/record/ranking/top10'); res.json(recordResponse.data); } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -151,7 +151,7 @@ app.get('/record/ranking/:user', verifyToken, async(req, res)=>{ res.json(recordResponse.data); } } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -166,7 +166,7 @@ app.get('/record/:user', verifyToken, async(req, res)=>{ res.json(recordResponse.data); } } catch (error) { - manageError(error) + manageError(res, error) } }); @@ -206,7 +206,7 @@ function verifyToken(req, res, next) { } function validateLang(lang){ - return ['en', 'es', 'tk'].includes(lang); + return ['en', 'es', 'tr'].includes(lang); } function validateAmount(amount) { @@ -223,7 +223,7 @@ function validateUser(user){ return !(/\s/.test(user)) //True if there are no spaces } -function manageError(error){ +function manageError(res, error){ if(error.response) //Some microservice responded with an error res.status(error.response.status).json({ error: error.response.data.error }); else //Some other error diff --git a/gatewayservice/openapi.yaml b/gatewayservice/openapi.yaml index d721ac42..6755daa9 100644 --- a/gatewayservice/openapi.yaml +++ b/gatewayservice/openapi.yaml @@ -1,16 +1,16 @@ openapi: 3.0.0 info: - title: wiq_en1b API - description: Our project's OpenAPI specification. - version: 0.1.2 + title: WIQ_en1b API + description: WIQ_en1b OpenAPI specification. + version: "0.2" contact: name: Project github url: https://github.com/Arquisoft/wiq_en1b servers: + - url: http://wiqen1b.serveminecraft.net:8000 + description: Production server - url: http://localhost:8000 description: Development server - - url: http://wiqen1b.serveminecraft.net:8000 - description: Production server paths: /health: get: @@ -39,21 +39,29 @@ paths: schema: type: object properties: + email: + type: string + description: User email + example: user@example.com username: type: string - description: User ID. + description: User name example: student password: type: string - description: User password. - example: pass + description: User password + example: password123 + repeatPassword: + type: string + description: Userpassword + example: password123 responses: '200': description: User added successfully. content: application/json: schema: - $ref: '#/components/shcemas/LoginResponse' + $ref: '#/components/schemas/LoginResponse' '400': description: Failed to add user content: @@ -101,22 +109,27 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/LoginResponse' + $ref: '#/components/schemas/LoginResponse' '400': description: Invalid credentials. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /questions: get: summary: Get 5 random questions from the system in any language + parameters: + - name: token + in: header + schema: + type: string responses: '200': description: OK @@ -129,20 +142,22 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /questions/{lang}: get: summary: Get 5 random questions from the system in the lang specified parameters: + - name: token + in: header + schema: + type: string - name: lang in: path required: true schema: type: string - enum: [es, en, tr] - description: Language code for filtering questions - security: - - BearerAuth: [] + enum: [es, en, tk] + description: Language code for filtering questions responses: '200': description: OK @@ -155,34 +170,36 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /questions/{lang}/{amount}: get: summary: Get an amount of random questions from the system in the lang specified parameters: + - name: token + in: header + schema: + type: string - name: lang in: path required: true schema: type: string - enum: [es, en, tr] + enum: [es, en, tk] description: Language code for filtering questions - name: amount in: path required: true schema: type: integer - minimun: 1 - maximun: 20 - description: Amount of questions retrieved - security: - - BearerAuth: [] + minimum: 1 + maximum: 20 + description: Amount of questions retrieved must be between 1 and 20 responses: '200': description: OK @@ -195,41 +212,43 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /questions/{lang}/{amount}/{type}: get: summary: Get an amount of questions of the given type from the system in the lang specified parameters: + - name: token + in: header + schema: + type: string - name: lang in: path required: true schema: type: string - enum: [es, en, tr] + enum: ["es", "en", "tk"] description: Language code for filtering questions - name: amount in: path required: true schema: type: integer - minimun: 1 - maximun: 20 - description: Amount of questions retrieved + minimum: 1 + maximum: 20 + description: Amount of questions retrieved must be between 1 and 20 - name: type in: path required: true schema: type: string - enum: [POPULATION, CAPITAL, LANGUAGE, SIZE] - description: Type for filtering questions - security: - - BearerAuth: [] + enum: ["POPULATION", "CAPITAL", "LANGUAGE", "SIZE"] + description: Type for filtering questions responses: '200': description: OK @@ -242,24 +261,27 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /record: post: summary: Add a new record to the database + parameters: + - name: token + in: header + schema: + type: string requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/Record' - security: - - BearerAuth: [] responses: '200': description: OK @@ -275,19 +297,21 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /record/{user}: get: summary: Gets the records from a given user parameters: + - name: token + in: header + schema: + type: string - name: user in: path required: true schema: type: string description: Username for filtering records - security: - - BearerAuth: [] responses: '200': description: OK @@ -300,18 +324,21 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /record/ranking/top10: get: summary: Gets the top 10 users on the system - security: - - BearerAuth: [] + parameters: + - name: token + in: header + schema: + type: string responses: '200': description: OK @@ -324,19 +351,21 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' /record/ranking/{user}: get: summary: Gets the ranking information of the given user parameters: + - name: token + in: header + schema: + type: string - name: user in: path required: true schema: type: string description: username of the user - security: - - BearerAuth: [] responses: '200': description: OK @@ -349,30 +378,15 @@ paths: content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' '500': description: Internal server error. content: application/json: schema: - $ref: '#/components/shcemas/Error' + $ref: '#/components/schemas/Error' components: - securitySchemes: - BearerAuth: - type: http - scheme: bearer - bearerFormat: JWT schemas: - LoginRequest: - type: object - properties: - username: - type: string - password: - type: string - required: - - username - - password LoginResponse: type: object properties: @@ -382,21 +396,6 @@ components: type: string email: type: string - User: - type: object - properties: - username: - type: string - email: - type: string - required: - - username - - email - UserResponse: - type: object - properties: - message: - type: string QuestionResponse: type: array items: @@ -476,7 +475,7 @@ components: properties: error: type: string - UserRanking: + Ranking: type: object properties: _id: @@ -487,7 +486,15 @@ components: type: integer position: type: integer + UserRanking: + type: object + properties: + userCompetitiveStats: + $ref: '#/components/schemas/Ranking' Top10Ranking: - type: array - items: - $ref: '#/components/schemas/UserRanking' \ No newline at end of file + type: object + properties: + usersCompetitiveStats: + type: array + items: + $ref: '#/components/schemas/Ranking' \ No newline at end of file From e49e22e0992a91169cff2c76be497e426c92964a Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 12:23:34 +0200 Subject: [PATCH 6/9] Updated backend --- users/authservice/auth-service.js | 2 +- .../auth-model.js => user-model.js} | 0 users/userservice/user-model.js | 24 ------------------- users/userservice/user-service.js | 2 +- 4 files changed, 2 insertions(+), 26 deletions(-) rename users/{authservice/auth-model.js => user-model.js} (100%) delete mode 100644 users/userservice/user-model.js diff --git a/users/authservice/auth-service.js b/users/authservice/auth-service.js index 924dc512..4b051af3 100644 --- a/users/authservice/auth-service.js +++ b/users/authservice/auth-service.js @@ -2,7 +2,7 @@ const express = require('express'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); -const User = require('./auth-model') +const User = require('../user-model') const app = express(); const port = 8002; diff --git a/users/authservice/auth-model.js b/users/user-model.js similarity index 100% rename from users/authservice/auth-model.js rename to users/user-model.js diff --git a/users/userservice/user-model.js b/users/userservice/user-model.js deleted file mode 100644 index e6643ff2..00000000 --- a/users/userservice/user-model.js +++ /dev/null @@ -1,24 +0,0 @@ -const mongoose = require('mongoose'); - -const userSchema = new mongoose.Schema({ - email: { - type: String, - required: true, - }, - username: { - type: String, - required: true, - }, - password: { - type: String, - required: true, - }, - createdAt: { - type: Date, - default: Date.now, - }, -}); - -const User = mongoose.model('User', userSchema); - -module.exports = User \ No newline at end of file diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index a6ea8a09..d0a3f455 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -4,7 +4,7 @@ const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const bodyParser = require('body-parser'); const jwt = require('jsonwebtoken'); -const User = require('./user-model') +const User = require('../user-model') const app = express(); const port = 8001; From e9843d4f1023304ce2d037ef4d48bc0e01262731 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 12:25:59 +0200 Subject: [PATCH 7/9] Fixed import --- users/authservice/auth-service.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/authservice/auth-service.test.js b/users/authservice/auth-service.test.js index 7f258f5c..bcd98b40 100644 --- a/users/authservice/auth-service.test.js +++ b/users/authservice/auth-service.test.js @@ -1,7 +1,7 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); -const User = require('./auth-model'); +const User = require('../user-model'); let mongoServer; let app; From ceac612a0b4edcd980dd93682c0d79c09e893694 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 12:35:11 +0200 Subject: [PATCH 8/9] Fixed --- users/authservice/auth-service.js | 2 +- users/authservice/auth-service.test.js | 5 +++-- users/{ => authservice}/user-model.js | 0 users/userservice/user-model.js | 12 ++++++++++++ users/userservice/user-service.js | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) rename users/{ => authservice}/user-model.js (100%) create mode 100644 users/userservice/user-model.js diff --git a/users/authservice/auth-service.js b/users/authservice/auth-service.js index 4b051af3..a233e849 100644 --- a/users/authservice/auth-service.js +++ b/users/authservice/auth-service.js @@ -2,7 +2,7 @@ const express = require('express'); const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); -const User = require('../user-model') +const User = require('./user-model') const app = express(); const port = 8002; diff --git a/users/authservice/auth-service.test.js b/users/authservice/auth-service.test.js index bcd98b40..e1518db7 100644 --- a/users/authservice/auth-service.test.js +++ b/users/authservice/auth-service.test.js @@ -1,13 +1,14 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); -const User = require('../user-model'); +const User = require('./user-model'); let mongoServer; let app; //test user let user = { + email: "user@gmail.com", username: 'testuser', password: 'testpassword', }; @@ -15,7 +16,7 @@ let user = { async function addUser(user){ const hashedPassword = await bcrypt.hash(user.password, 10); const newUser = new User({ - email: "user@gmail.com", + email: user.email, username: user.username, password: hashedPassword, createdAt: new Date() diff --git a/users/user-model.js b/users/authservice/user-model.js similarity index 100% rename from users/user-model.js rename to users/authservice/user-model.js diff --git a/users/userservice/user-model.js b/users/userservice/user-model.js new file mode 100644 index 00000000..5cdbaf69 --- /dev/null +++ b/users/userservice/user-model.js @@ -0,0 +1,12 @@ +const mongoose = require('mongoose'); + +const userSchema = new mongoose.Schema({ + email: String, + username: String, + password: String, + createdAt: Date, +}); + +const User = mongoose.model('User', userSchema); + +module.exports = User \ No newline at end of file diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index d0a3f455..a6ea8a09 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -4,7 +4,7 @@ const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const bodyParser = require('body-parser'); const jwt = require('jsonwebtoken'); -const User = require('../user-model') +const User = require('./user-model') const app = express(); const port = 8001; From 283543586ee5c80c0ac5d33190fc74bc61489a38 Mon Sep 17 00:00:00 2001 From: Mister-Mario Date: Thu, 25 Apr 2024 12:37:16 +0200 Subject: [PATCH 9/9] Added a conditional to not load the api-doc in case the .yaml does not exist --- gatewayservice/gateway-service.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index f592f9e0..62b3dc83 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -171,15 +171,19 @@ app.get('/record/:user', verifyToken, async(req, res)=>{ }); // Read the OpenAPI YAML file synchronously -const file = fs.readFileSync('./openapi.yaml', 'utf8'); +const openapiPath = './openapi.yaml' +if(fs.existsSync(openapiPath)){ + const file = fs.readFileSync(openapiPath, 'utf8'); -// Parse the YAML content into a JavaScript object representing the Swagger document -const swaggerDocument = YAML.parse(file); + // Parse the YAML content into a JavaScript object representing the Swagger document + const swaggerDocument = YAML.parse(file); + + // Serve the Swagger UI documentation at the '/api-doc' endpoint + // This middleware serves the Swagger UI files and sets up the Swagger UI page + // It takes the parsed Swagger document as input + app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); +} -// Serve the Swagger UI documentation at the '/api-doc' endpoint -// This middleware serves the Swagger UI files and sets up the Swagger UI page -// It takes the parsed Swagger document as input -app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); // Start the gateway service const server = app.listen(port, () => {