Skip to content

Commit

Permalink
Merge pull request #34 from Arquisoft/develop-QuestionGenerator
Browse files Browse the repository at this point in the history
Prototype 1
  • Loading branch information
alexfdzs authored Mar 11, 2024
2 parents a648913 + cedaff5 commit 4a4a9b3
Show file tree
Hide file tree
Showing 42 changed files with 23,405 additions and 3,484 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionsgenerator ci
- run: npm --prefix historial ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionsgenerator test -- --coverage
- run: npm --prefix historial test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionsgenerator ci
- run: npm --prefix historial ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix questionsgenerator test -- --coverage
- run: npm --prefix historial test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ services:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

questionsservice:
container_name: questionsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1b/questionsservice:latest
profiles: ["dev", "prod"]
build: ./questionsgenerator
depends_on:
- mongodb
ports:
- "8003:8003"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb

historialservice:
container_name: historialservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1b/historialservice:latest
profiles: ["dev", "prod"]
build: ./historial
depends_on:
- mongodb
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
Expand All @@ -48,13 +76,17 @@ services:
- mongodb
- userservice
- authservice
- questionsservice
- historialservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
QUESTION_SERVICE_URL: http://questionsservice:8003
HISTORIAL_SERVICE_URL: http://historialservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down
2 changes: 0 additions & 2 deletions docs/src/01_introduction_and_goals.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ We also expect to provide a practical software that fulfills customer expectatio
[options="header",cols="1,2,2"]
|===
|Priority|Quality goal|Motivation
| _High_ | *Privacy* | Personal data and information shouldn´t be something that just anyone can play with, so
the system must guarantee their users´ information to be safe and hidden to other people
| _High_ | *Usability* | The application interface has to be satisfying and easy to handle to users even if their web
skills are zero
| _High_ | *Maintainability* | Our software should be designed in a way that it won´t be difficult to modify, extend and
Expand Down
5 changes: 0 additions & 5 deletions docs/src/08_concepts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ ifndef::imagesdir[:imagesdir: ../images]
== Cross-cutting Concepts


=== _Security_

_Deployment of secure user authentication systems to ensure that only the own user can access his personal data and
specific functionalities._



=== _Ethics_
Expand Down
33 changes: 33 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const port = 8000;

const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const getQuestionUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003';
const getHistorialUrl = process.env.HISTORIAL_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -41,6 +43,37 @@ app.post('/adduser', async (req, res) => {
}
});

app.post('/getQuestion', async (req, res) => {
try {
// Forward the getQuestion request to the question service
const questionResponse = await axios.post(getQuestionUrl+'/getQuestion');
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.post('/saveHistorial', async (req, res) => {
try {
// Forward the saveHistorial request to the historial service
const questionResponse = await axios.post(getHistorialUrl+'/saveHistorial', req.body);
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.post('/getHistorial', async (req, res) => {
try {
// Forward the getHistorial request to the historial service
const questionResponse = await axios.post(getHistorialUrl+'/getHistorial', req.body);
res.json(questionResponse.data);
} catch (error) {

res.status(error.response.status).json({ error: error.response.data.error });
}
});

// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
2 changes: 2 additions & 0 deletions historial/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
20 changes: 20 additions & 0 deletions historial/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20

# Set the working directory in the container
WORKDIR /usr/src/historial

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install app dependencies
RUN npm install

# Copy the app source code to the working directory
COPY . .

# Expose the port the app runs on
EXPOSE 8004

# Define the command to run your app
CMD ["node", "historial-service.js"]
20 changes: 20 additions & 0 deletions historial/auth-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose');

const gameSchema = new mongoose.Schema({
correctAnswer: String,
answers: [String],
title: String,
answeredRight: Boolean,
selectedAnswer: String,
});

const userSchema = new mongoose.Schema({
username: String,
password: String,
createdAt: Date,
games: { type: [gameSchema], default: [] },
});

const User = mongoose.model('User', userSchema);

module.exports = User;
87 changes: 87 additions & 0 deletions historial/historial-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// questions-service.js
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const User = require('./auth-model');

const app = express();
const port = 8004;

// Middleware to parse JSON in request body
app.use(express.json());

//Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb';
mongoose.connect(mongoUri);


//to respond to the /saveHistorial request
app.post('/saveHistorial', async (req,res) => {
try {

//extract the infrmation from the request to save it in the user
const { question, answersArray, correctAnswer, selectedAnswer, correct, username2 } = req.body;

const username = username2;

//search for the user with username=user in the bd
const user = await User.findOne({ username });

//creamos la pregunta para guardarla en el historial
const partida = {
correctAnswer: correctAnswer,
answers: answersArray,
title: question,
answeredRight: correct,
selectedAnswer: selectedAnswer
}

console.log(partida.selectedAnswer);
//guardamos la partida en el array de preguntas del usuario
user.games.push(partida);

//guardamos los cambios realizados en el usuario
await user.save();

res.json({ msg: "Saves the data correctly" });

} catch(error){
res.status(500).json({ error: 'Internal Server Error inside service' });
}
});

//to respond to the /saveHistorial request
app.post('/getHistorial', async (req,res) => {
try {

//extract the infrmation from the request to save it in the user
const { username2 } = req.body;

const username = username2;

//search for the user with username=user in the bd
const user = await User.findOne({ username });

const gamesUser = user.games;

//respond with the user's games
res.json({ games: gamesUser });

} catch(error){
res.status(500).json({ error: 'Internal Server Error inside service' });
}
});



const server = app.listen(port, () => {
console.log(`Historial Service listening at http://localhost:${port}`);
});

server.on('close', () => {
// Close the Mongoose connection
mongoose.connection.close();
});


module.exports = server
Loading

0 comments on commit 4a4a9b3

Please sign in to comment.