Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webapp interface to check test coverage #139

Merged
merged 17 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions gameservice/game-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ app.use(express.json());
// Middleware to enable CORS (cross-origin resource sharing). In order for the API to be accessible by other origins (domains).
app.use(cors());

var gameId = 0;
let gameId = 0;

app.get('/generateGame', async (req, res) => {
console.log("Llegamos a crear un id del juego")
var gameId = generateAleatoryString()
let gameId = generateAleatoryString()
res.json(gameId)
})


// Route for getting questions
app.get('/questions', async (req, res) => {
try {
// TODO: Implement logic to fetch questions from MongoDB and send response
// const questions = await Question.find()
const questionGenerated = await axios.get(questionService + req.url);
res.json(questionGenerated.data);
} catch (error) {
Expand All @@ -50,11 +48,11 @@ app.get('/questions', async (req, res) => {
app.post('/storeGame', async (req, res) => {
try {
//hay que preparar los datos para enviarlos al servicio
var id = req.body.id
var username = req.body.username
var points = req.body.points
var questions = req.body.questions
var avgtime = req.body.avgtime
let id = req.body.id
let username = req.body.username
let points = req.body.points
let questions = req.body.questions
let avgtime = req.body.avgtime
console.log("Vamos a guardar resultado")
const store = await axios.post(`${userStatsService}/history/game`, {id, points, username, questions, avgtime})
console.log("Guardamos resultado")
Expand All @@ -64,6 +62,7 @@ app.post('/storeGame', async (req, res) => {
}
})

//FALTA
app.get('/topics', async (req, res) => {
try {
const topics = await axios.get(`${questionService}/topics`)
Expand Down
39 changes: 26 additions & 13 deletions gameservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ servers:
- url: http://gameservice:8005
description: Production server
paths:
/generateGameUnlimitedQuestions:

/generateGame:
get:
summary: Generate the id for the unlimited game questions.
operationId: generateGameUnlimitedQuestions
summary: Generate the id for the game.
operationId: generateGame
requestBody:
required: true
content:
Expand All @@ -30,6 +31,7 @@ paths:
id:
type: string
description: The id of the game created.
example: Game id created (sqeweg12er56yg46u89k)
'500':
description: Internal server error.
content:
Expand All @@ -41,10 +43,11 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/gameUnlimitedQuestion:

/questions:
get:
summary: Generate questions for the unlimited game questions.
operationId: gameUnlimitedQuestions
summary: Generate questions for the game.
operationId: questions
requestBody:
required: true
content:
Expand All @@ -67,13 +70,15 @@ paths:
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres.
question:
type: String
description: The question that is going to be done
example: ¿Capital de España?
correctAnswer:
type: String
description: The correct answer for the question
description: The correct answer for the question
example: Madrid.
'500':
description: Internal server error.
content:
Expand Down Expand Up @@ -103,20 +108,28 @@ paths:
username:
type: string
description: The name if the user.
example: username.
points:
type: integer
description: The number of points that the user score.
example: 1000.
questions:
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres.
question:
type: String
description: The question that is going to be done
example: ¿Capital de España?
correctAnswer:
type: String
description: The correct answer for the question
example: Madrid
avgtime:
type: integer
description: The average time taken to answer questions in seconds.
example: 23
responses:
'200':
description: Question created and returned successfuly.
Expand All @@ -127,12 +140,12 @@ paths:
properties:
id:
type: string
description: The question that is going to bre realized.
example:
description: The question that is going to be realized.
example: ¿Capital de España?
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres.
'500':
description: Internal server error.
content:
Expand All @@ -143,4 +156,4 @@ paths:
error:
type: string
description: Error information.
example: Internal Server Error
example: Internal Server Error
10 changes: 1 addition & 9 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,6 @@ app.get('/history/questions', async (req, res) => {
}
})

// app.get(`/questions`, async (req, res) => {
// try {
// const response = await axios.get(questionsGeneratorServiceUrl+`/questions`);
// res.json(response.data);
// } catch (error) {
// res.status(error.response.status).json({ error: error.response.data.error });
// }
// })

app.get('/generateGame', async (req, res) => {
try {
const response = await axios.get(gameService + '/generateGame')
Expand Down Expand Up @@ -123,6 +114,7 @@ app.post('/storeGame', async (req, res) => {
}
})

//FALTA ???
app.get('/topics', async (req, res) => {
try {
const response = await axios.get(`${gameService}/topics`)
Expand Down
78 changes: 68 additions & 10 deletions gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ paths:
username:
type: string
description: User ID
example: student
password:
type: string
description: Hashed password
Expand Down Expand Up @@ -142,6 +143,7 @@ paths:
type: string
description: Error information.
example: Internal Server Error

/history/games/:username:
get:
summary: Access to de history of games of the user.
Expand Down Expand Up @@ -188,10 +190,53 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/generateGameUnlimitedQuestions:

/history/questions:
get:
summary: Generate the id for the unlimited game questions.
operationId: generateGameUnlimitedQuestions
summary: Returns the the stored questions.
operationId: gethistoryQuestions
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
'200':
description: Question stored correctly and returns it.
content:
application/json:
schema:
type: object
properties:
token:
type: string
description: User token.
example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWY3NTZkYjNmYTIyZDIyN2E0YjdjN2QiLCJpYXQiOjE3MTA3MDg3NDUsImV4cCI6MTcxMDcxMjM0NX0.VMG_5DOyQ4GYlJQRcu1I6ICG1IGzuo2Xuei093ONHxw
questions:
type: List<Question>
description: Question.
example: ¿Cual es la capital de España?, ¿Cual es la capital de Francia?
createdAt:
type: string
description: Creation date.
example: '2024-03-17T20:47:23.935Z'
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error

/generateGame:
get:
summary: Generate the id for the game.
operationId: generateGame
requestBody:
required: true
content:
Expand All @@ -209,6 +254,7 @@ paths:
id:
type: string
description: The id of the game created.
example: sqeweg12er56yg46u89k
token:
type: string
description: User token.
Expand All @@ -228,10 +274,11 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/gameUnlimitedQuestion:

/questions:
get:
summary: Generate questions for the unlimited game questions.
operationId: gameUnlimitedQuestions
summary: Generate questions for the game.
operationId: questions
requestBody:
required: true
content:
Expand All @@ -254,13 +301,15 @@ paths:
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres
question:
type: String
description: The question that is going to be done
example: ¿Cual es la capital de españa?
correctAnswer:
type: String
description: The correct answer for the question
example: Madrid
'500':
description: Internal server error.
content:
Expand All @@ -272,6 +321,7 @@ paths:
type: string
description: Error information.
example: Internal Server Error

/storeGame:
post:
summary: Stores the actual game in the database.
Expand All @@ -290,20 +340,28 @@ paths:
username:
type: string
description: The name if the user.
example: student
points:
type: integer
description: The number of points that the user score.
example: 1000
questions:
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres
question:
type: String
description: The question that is going to be done
example: ¿Cual es la capital de españa?
correctAnswer:
type: String
description: The correct answer for the question
example: Madrid
avgtime:
type: integer
description: average time to answer the questions
example: 23
responses:
'200':
description: Question created and returned successfuly.
Expand All @@ -315,11 +373,11 @@ paths:
id:
type: string
description: The question that is going to bre realized.
example:
example: sqeweg12er56yg46u89k
answers:
type: List<String>
description: List with the possible answers.
example:
example: Madrid, Paris, Roma o Londres
'500':
description: Internal server error.
content:
Expand Down
Loading