Skip to content

Commit

Permalink
Merge branch 'develop-beforeMerge22'
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289029 committed Apr 7, 2024
2 parents c1d9997 + cbbec57 commit b96d2b5
Show file tree
Hide file tree
Showing 15 changed files with 781 additions and 31 deletions.
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: ${MONGODB_URI}

userservice:
container_name: userservice-${teamname:-defaultASW}
Expand All @@ -37,7 +37,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: ${MONGODB_URI}

questionsgenerator:
container_name: questionsgenerator-${teamname:-defaultASW}
Expand All @@ -51,7 +51,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: ${MONGODB_URI}

record:
container_name: record-${teamname:-defaultASW}
Expand All @@ -66,7 +66,7 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ
MONGODB_URI: ${MONGODB_URI}

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
Expand Down
118 changes: 106 additions & 12 deletions gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,26 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/saveHistorial:
/generateQuestions:
post:
summary: Saves the data of a question the user answered in the database.
operationId: saveHistorial
summary: Generates questions from wikidata to the database.
operationId: generateQuestions
responses:
'200':
description: Generates questions successfully. Returns a message of success.
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: Success message.
example: Questions generated successfully
/saveQuestion:
post:
summary: Saves the data of a question the user answered locally.
operationId: saveQuestion
requestBody:
required: true
content:
Expand Down Expand Up @@ -227,7 +243,7 @@ paths:
type: string
description: selected answer
example: Madrid
correct:
isCorrect:
type: boolean
description: true if the answer is correct, false if it is incorrect
example: false
Expand All @@ -237,7 +253,45 @@ paths:
example: user1234
responses:
'200':
description: Saves the data into the database. Returns a message to confirm it was a success.
description: Saves the data successfully. Returns a message to confirm it was a success.
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: message of success.
example: Question saved successfully
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
/saveGameRecord:
post:
summary: Saves the data of a game the user finished.
operationId: saveGameRecord
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: username of the user logged in
example: user1234
responses:
'200':
description: Saves the game successfully. Returns a message to confirm it was a success.
content:
application/json:
schema:
Expand All @@ -246,7 +300,7 @@ paths:
msg:
type: string
description: message of success.
example: Saves the data correctly
example: Game record saved succesfully
'500':
description: Internal server error.
content:
Expand All @@ -258,10 +312,10 @@ paths:
type: string
description: Error information.
example: Internal Server Error
/getHistorial:
/getGameRecord:
post:
summary: gets the data of all games and questions of the user logged in.
operationId: getHistorial
operationId: getGameRecord
requestBody:
required: true
content:
Expand All @@ -281,16 +335,19 @@ paths:
schema:
type: object
properties:
games:
user:
type: string
description: ID of the user
questions:
type: array
items:
type: object
properties:
title:
question:
type: string
description: question title
example: What is the capital of France?
answers:
answersArray:
type: array
items:
type: string
Expand All @@ -308,11 +365,48 @@ paths:
type: string
description: selected answer
example: Madrid
answeredRight:
isCorrect:
type: boolean
description: true if the answer is correct, false if it is incorrect
example: false
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
/deleteTempQuestions:
post:
summary: Deletes the locally saved answers of the games.
operationId: deleteTempQuestions
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
username:
type: string
description: username of the user logged in
example: user1234
responses:
'200':
description: Deletes succesfully the data. Returns a message to confirm it was a success.
content:
application/json:
schema:
type: object
properties:
msg:
type: string
description: message of success.
example: Temp questions deleted successfully
'500':
description: Internal server error.
content:
Expand Down
4 changes: 3 additions & 1 deletion questionsgenerator/questions-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const QuestionGenerator = require('./questionGenerator.js');
const Question = require('./question-model')
const mongoURI = process.env.MONGODB_URI || 'mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ';
const mongoURI = process.env.MONGODB_URI;
//|| 'mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ';

const app = express();
app.disable('x-powered-by');
Expand Down Expand Up @@ -51,6 +52,7 @@ app.post('/generateQuestions', async (req, res) => {
const generator = new QuestionGenerator();
await generator.loadTemplates();
await generator.generate10Questions();
res.status(200).json({ msg: "Questions generated successfully" });
})

async function getRandomQuestionByCategory(category) {
Expand Down
8 changes: 4 additions & 4 deletions record/historial-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const User = require('./auth-model');
const Game = require('./historial-model');
const mongoURI = process.env.MONGODB_URI || 'mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ';
const mongoURI = process.env.MONGODB_URI;

const app = express();
app.disable('x-powered-by');
Expand Down Expand Up @@ -35,7 +35,7 @@ app.post('/saveQuestion', async (req, res) => {
isCorrect
});

res.json({ msg: "Question saved successfully" });
res.status(200).json({ msg: "Question saved successfully" });
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
Expand All @@ -60,7 +60,7 @@ app.post('/saveGameRecord', async (req, res) => {

delete gameQuestions[username];

res.json("Game record saved succesfully");
res.status(200).json("Game record saved succesfully");
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand All @@ -76,7 +76,7 @@ app.post('/getGameRecord', async (req, res) => {
const games = await Game.find({ user: user._id });


res.json({ games: games });
res.status(200).json({ games: games });
} catch (error) {
res.status(500).json({ error: "Internal Server Error" });
}
Expand Down
2 changes: 1 addition & 1 deletion users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const port = 8002;
app.use(express.json());

// Connect to MongoDB
const mongoURI = process.env.MONGODB_URI || 'mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ';
const mongoURI = process.env.MONGODB_URI;

mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true});
//const userCollection = mongoose.connection.useDb("WIQ").collection("users");
Expand Down
3 changes: 1 addition & 2 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const port = 8001;
app.use(bodyParser.json());

// Connect to MongoDB
const mongoURI = process.env.MONGODB_URI || 'mongodb+srv://wiq_es01b_admin:[email protected]/wiq?retryWrites=true&w=majority&appName=WIQ';
const mongoURI = process.env.MONGODB_URI;

mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true});
//const userCollection = mongoose.connection.useDb("WIQ").collection("users");

// Function to validate required fields in the request body
function validateRequiredFields(req, requiredFields) {
Expand Down
Loading

0 comments on commit b96d2b5

Please sign in to comment.