Skip to content

Commit

Permalink
Fix questions routes (CS3219-AY2425S1#73)
Browse files Browse the repository at this point in the history
Fix question routes being unaccessible on production
  • Loading branch information
samuelim01 authored Nov 2, 2024
1 parent 097b6b7 commit 5272e5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/src/_services/question.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
46 changes: 23 additions & 23 deletions services/question/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:
Expand Down Expand Up @@ -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:

Expand All @@ -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:
Expand Down Expand Up @@ -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:

Expand All @@ -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:
Expand Down Expand Up @@ -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:

Expand All @@ -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:
Expand Down Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -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:

Expand All @@ -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:
Expand All @@ -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:

Expand All @@ -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:
Expand All @@ -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:

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion services/question/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ app.use(

// Routes
app.use('/', router);
app.use('/api/question', questionRouter);
app.use('/api/question/questions', questionRouter);

export default app;

0 comments on commit 5272e5d

Please sign in to comment.