Skip to content

Commit

Permalink
Merge branch 'develop' into zohaib
Browse files Browse the repository at this point in the history
  • Loading branch information
Verzidee authored Mar 31, 2024
2 parents 28790b8 + 7f7429b commit c88e45e
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 60 deletions.
45 changes: 43 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,54 @@ app.get('/getquestions', async(req,res)=> {
const response = await axios.get(`${generateServiceURL}/getquestions`);

// Devuelve la respuesta del servicio de generación de preguntas al cliente original.
res.json(response.data);
res.status(200).json(response.data);

} catch(error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'An unexpected error occurred' });
res.status(500).json({ error: 'Error getting the questions' });
}
}
});

app.post('/createquestion', async (req, res) => {
try {
const response = await axios.post(`${generateServiceURL}/createquestion`, req.body);
res.status(201).json(response.data);
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error creating the question' });
}
}
});

app.put('/updatequestion/:id', async (req, res) => {
try {
const { id } = req.params;
await axios.put(`${generateServiceURL}/updatequestion/${id}`, req.body);
res.status(200).json({ status: 'OK' });
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error updating the question' });
}
}
});

app.put('/deletequestion/:id', async (req, res) => {
try {
const { id } = req.params;
await axios.delete(`${generateServiceURL}/deletequestion/${id}`, req.body);
res.status(200).json({ status: 'OK' });
} catch (error) {
if (error.response) {
res.status(error.response.status).json({ error: error.response.data.error });
} else {
res.status(500).json({ error: 'Error deleting the question' });
}
}
});
Expand Down
223 changes: 222 additions & 1 deletion gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ info:
servers:
- url: http://localhost:8000
description: Development server
- url: http://SOMEIP:8000
- url: http://${{ secrets.DEPLOY_HOST }}:8000
description: Production server
paths:
/adduser:
Expand Down Expand Up @@ -142,3 +142,224 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/getquestions:
get:
summary: Get random questions.
operationId: getQuestions
responses:
'200':
description: Returns random questions.
content:
application/json:
schema:
type: object
properties:
questions:
type: array
items:
type: object
properties:
question:
type: string
description: The question itself.
answers:
type: array
items:
type: object
properties:
answer:
type: string
description: The answer to the question.
correct:
type: boolean
description: Indicates if the answer is correct.
questionCategory:
type: string
description: The category of the question.
example:
questions:
- question: "¿Cuál es la capital de Francia?"
answers:
- answer: "París"
correct: true
- answer: "Londres"
correct: false
- answer: "Madrid"
correct: false
- answer: "Berlín"
correct: false
questionCategory: "Geografía"
'500':
description: Error getting the questions.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error message.
example:
error: "Error getting the questions occurred"
/createquestion:
post:
summary: Create a new question.
operationId: createQuestion
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
question:
type: string
description: The question itself.
answers:
type: array
items:
type: object
properties:
answer:
type: string
description: The answer to the question.
correct:
type: boolean
description: Indicates if the answer is correct.
questionCategory:
type: string
description: The category of the question.
responses:
'201':
description: Question created successfully.
content:
application/json:
schema:
type: object
properties:
_id:
type: string
description: The ID of the created question.
example: "65f756db3fa22d227a4b7c7d"
question:
type: string
description: The question itself.
example: "¿Cuál es la capital de Francia?"
answers:
type: array
items:
type: object
properties:
answer:
type: string
description: The answer to the question.
correct:
type: boolean
description: Indicates if the answer is correct.
questionCategory:
type: string
description: The category of the question.
'400':
description: Bad request. Invalid input data.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Invalid input data.
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
/updatequestion/{id}:
put:
summary: Update a question by ID
operationId: updateQuestionById
parameters:
- in: path
name: id
required: true
description: ID of the question to update
schema:
type: string
example: "605cf8a59c73cc0022563989"
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
question:
type: string
description: The text of the question.
answers:
type: array
items:
type: object
properties:
answer:
type: string
description: The text of the answer.
correct:
type: boolean
description: Indicates if the answer is correct.
questionCategory:
type: string
description: The category of the question.
responses:
'200':
description: Successful update
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Update status
example: OK
'400':
description: Bad request, invalid data provided
'404':
description: Question not found
'500':
description: Internal server error
/deletequestion/{id}:
delete:
summary: Delete a question by ID
operationId: deleteQuestionById
parameters:
- in: path
name: id
required: true
description: ID of the question to delete
schema:
type: string
example: "605cf8a59c73cc0022563989"
responses:
'200':
description: Question deleted successfully
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Deletion status
example: OK
'404':
description: Question not found
'500':
description: Internal server error
Loading

0 comments on commit c88e45e

Please sign in to comment.