From 5272e5d20125170fab2dadea2a35a77636ccd441 Mon Sep 17 00:00:00 2001 From: samuelim01 <61283948+samuelim01@users.noreply.github.com> Date: Sat, 2 Nov 2024 12:12:46 +0800 Subject: [PATCH] Fix questions routes (#73) Fix question routes being unaccessible on production --- frontend/src/_services/question.service.ts | 2 +- services/question/README.md | 46 +++++++++++----------- services/question/src/app.ts | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/frontend/src/_services/question.service.ts b/frontend/src/_services/question.service.ts index b7a64bba87..e13688c788 100644 --- a/frontend/src/_services/question.service.ts +++ b/frontend/src/_services/question.service.ts @@ -14,7 +14,7 @@ import { ApiService } from './api.service'; providedIn: 'root', }) export class QuestionService extends ApiService { - protected apiPath = 'question'; + protected apiPath = 'question/questions'; private httpOptions = { headers: new HttpHeaders({ diff --git a/services/question/README.md b/services/question/README.md index 09794c2e4b..21cf175d7c 100644 --- a/services/question/README.md +++ b/services/question/README.md @@ -31,7 +31,7 @@ This endpoint allows the retrieval of all the questions in the database. If filt that matches with parameters will be returned; if no parameters are provided, all questions will be returned. - **HTTP Method**: `GET` -- **Endpoint**: `/api/question` +- **Endpoint**: `/api/question/questions` #### Parameters: @@ -51,25 +51,25 @@ that matches with parameters will be returned; if no parameters are provided, al ``` Retrieve all Questions: -curl -X GET http://localhost:8081/api/question +curl -X GET http://localhost:8081/api/question/questions Retrieve Questions by Title: -curl -X GET "http://localhost:8081/api/question?title=Reverse%20a%20String" +curl -X GET "http://localhost:8081/api/question/questions?title=Reverse%20a%20String" Retrieve Questions by Description: -curl -X GET "http://localhost:8081/api/question?description=string" +curl -X GET "http://localhost:8081/api/question/questions?description=string" Retrieve Questions by Topics: -curl -X GET "http://localhost:8081/api/question?topics=Algorithms,Data%20Structures" +curl -X GET "http://localhost:8081/api/question/questions?topics=Algorithms,Data%20Structures" Retrieve Questions by Difficulty: -curl -X GET "http://localhost:8081/api/question?difficulty=Easy" +curl -X GET "http://localhost:8081/api/question/questions?difficulty=Easy" Retrieve Questions by Title and Difficulty: -curl -X GET "http://localhost:8081/api/question?title=Reverse%20a%20String&difficulty=Easy" +curl -X GET "http://localhost:8081/api/question/questions?title=Reverse%20a%20String&difficulty=Easy" Retrieve Questions by Title, Description, Topics, and Difficulty: -curl -X GET "http://localhost:8081/api/question?title=Reverse%20a%20String&description=string&topics=Algorithms&difficulty=Easy" +curl -X GET "http://localhost:8081/api/question/questions?title=Reverse%20a%20String&description=string&topics=Algorithms&difficulty=Easy" ``` #### Parameter Format Details: @@ -117,7 +117,7 @@ encoding and readability concerns. This endpoint allows the retrieval of the question by using the question ID. - **HTTP Method**: `GET` -- **Endpoint**: `/api/question/{id}` +- **Endpoint**: `/api/question/questions/{id}` #### Parameters: @@ -135,7 +135,7 @@ This endpoint allows the retrieval of the question by using the question ID. ``` Retrieve Question by ID: -curl -X GET http://localhost:8081/api/question/1 +curl -X GET http://localhost:8081/api/question/questions/1 ``` #### Example of Response Body for Success: @@ -165,7 +165,7 @@ curl -X GET http://localhost:8081/api/question/1 This endpoint allows the retrieval of random questions that matches the parameters provided. - **HTTP Method**: `GET` -- **Endpoint**: `/api/question/search` +- **Endpoint**: `/api/question/questions/search` #### Parameters: @@ -187,10 +187,10 @@ This endpoint allows the retrieval of random questions that matches the paramete ``` Retrieve Random Question by Topics and Difficulty: -curl -X GET "http://localhost:8081/api/question/search?topics=Algorithms&difficulty=Medium" +curl -X GET "http://localhost:8081/api/question/questions/search?topics=Algorithms&difficulty=Medium" Retrieve Random Question by Topics, Difficulty, and Limit: -curl -X GET "http://localhost:8081/api/question/search?topics=Algorithms,Data%20Structures&difficulty=Easy&limit=5" +curl -X GET "http://localhost:8081/api/question/questions/search?topics=Algorithms,Data%20Structures&difficulty=Easy&limit=5" ``` #### Example of Response Body for Success: @@ -243,7 +243,7 @@ curl -X GET "http://localhost:8081/api/question/search?topics=Algorithms,Data%20 This endpoint retrieves all unique topics in the database - **HTTP Method**: `GET` -- **Endpoint**: `/api/question/topics` +- **Endpoint**: `/api/question/questions/topics` #### Responses: @@ -256,7 +256,7 @@ This endpoint retrieves all unique topics in the database ``` Retrieve Topics: -curl -X GET http://localhost:8081/api/question/topics +curl -X GET http://localhost:8081/api/question/questions/topics ``` #### Example of Response Body for Success: @@ -286,7 +286,7 @@ This endpoint allows the addition of a new question. The `id` is now automatical uniqueness. - **HTTP Method**: `POST` -- **Endpoint**: `/api/question` +- **Endpoint**: `/api/question/questions` #### Request Body: @@ -307,7 +307,7 @@ uniqueness. ``` Add Question: -curl -X POST http://localhost:8081/api/question -H "Content-Type: application/json" -d "{\"title\": \"New Question\", \"description\": \"This is a description for a new question.\", \"topics\": [\"Data Structures\", \"Algorithms\"], \"difficulty\": \"Medium\"}" +curl -X POST http://localhost:8081/api/question/questions -H "Content-Type: application/json" -d "{\"title\": \"New Question\", \"description\": \"This is a description for a new question.\", \"topics\": [\"Data Structures\", \"Algorithms\"], \"difficulty\": \"Medium\"}" ``` #### Example of Response Body for Success: @@ -334,7 +334,7 @@ curl -X POST http://localhost:8081/api/question -H "Content-Type: application/js This endpoint allows updating an existing question. Only the title, description, topics, and difficulty can be updated. - **HTTP Method**: `PUT` -- **Endpoint**: `/api/question/{id}` +- **Endpoint**: `/api/question/questions/{id}` #### Request Parameters: @@ -360,7 +360,7 @@ This endpoint allows updating an existing question. Only the title, description, ``` Update Question: -curl -X PUT http://localhost:8081/api/question/21 -H "Content-Type: application/json" -d "{\"title\": \"Updated Question Title\", \"description\": \"This is the updated description.\", \"topics\": [\"Updated Topic\"], \"difficulty\": \"Hard\"}" +curl -X PUT http://localhost:8081/api/question/questions/21 -H "Content-Type: application/json" -d "{\"title\": \"Updated Question Title\", \"description\": \"This is the updated description.\", \"topics\": [\"Updated Topic\"], \"difficulty\": \"Hard\"}" ``` #### Example of Response Body for Success: @@ -387,7 +387,7 @@ curl -X PUT http://localhost:8081/api/question/21 -H "Content-Type: application/ This endpoint allows the deletion of a question by the question ID. - **HTTP Method**: `DELETE` -- **Endpoint**: `/api/question/{id}` +- **Endpoint**: `/api/question/questions/{id}` #### Parameters: @@ -405,7 +405,7 @@ This endpoint allows the deletion of a question by the question ID. ``` Delete Question: -curl -X DELETE http://localhost:8081/api/question/21 +curl -X DELETE http://localhost:8081/api/question/questions/21 ``` #### Example of Response Body for Success: @@ -432,7 +432,7 @@ curl -X DELETE http://localhost:8081/api/question/21 This endpoint allows the deletion of multiple questions by their question IDs. - **HTTP Method**: `POST` -- **Endpoint**: `/api/question/delete` +- **Endpoint**: `/api/question/questions/delete` #### Parameters: @@ -451,7 +451,7 @@ This endpoint allows the deletion of multiple questions by their question IDs. ``` Delete Questions: -curl -X POST http://localhost:8081/api/question/delete -H "Content-Type: application/json" -d '{"ids": [21, 22]}' +curl -X POST http://localhost:8081/api/question/questions/delete -H "Content-Type: application/json" -d '{"ids": [21, 22]}' ``` #### Example of Response Body for Success: diff --git a/services/question/src/app.ts b/services/question/src/app.ts index 789741e9d5..d9f53024a5 100644 --- a/services/question/src/app.ts +++ b/services/question/src/app.ts @@ -23,6 +23,6 @@ app.use( // Routes app.use('/', router); -app.use('/api/question', questionRouter); +app.use('/api/question/questions', questionRouter); export default app;