Skip to content

Commit

Permalink
Sincronización con develop (28 Marzo)
Browse files Browse the repository at this point in the history
  • Loading branch information
uo264915 committed Mar 28, 2024
2 parents 492a216 + 56ea4b4 commit d9d57fb
Show file tree
Hide file tree
Showing 18 changed files with 5,805 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix questions/creationservice ci
- run: npm --prefix questions/retrieveservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
Expand Down
40 changes: 39 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix questions/creationservice ci
- run: npm --prefix questions/retrieveservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
Expand All @@ -35,6 +37,8 @@ jobs:
node-version: 20
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix questions/creationservice install
- run: npm --prefix questions/retrieveservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
Expand Down Expand Up @@ -93,6 +97,40 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice
docker-push-creationservice:
name: Push creations service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es2b/creationservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questions/creationservice
docker-push-retrieveservice:
name: Push retrieves service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es2b/retrieveservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questions/retrieveservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -113,7 +151,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-webapp]
needs: [docker-push-userservice,docker-push-authservice,docker-push-creationservice,docker-push-retrieveservice,docker-push-gatewayservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
18 changes: 17 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ services:
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
MONGODB_URI: mongodb://mongodb:27017/questiondb

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

authservice:
container_name: authservice-${teamname:-defaultASW}
Expand Down Expand Up @@ -63,6 +77,7 @@ services:
- userservice
- authservice
- creationservice
- retrieveservice
ports:
- "8000:8000"
networks:
Expand All @@ -71,6 +86,7 @@ services:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
CREATION_SERVICE_URL: http://creationservice:8005
RETRIEVE_SERVICE_URL: http://retrieveservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down
15 changes: 12 additions & 3 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const port = 8000;
const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const creationServiceUrl = process.env.CREATION_SERVICE_URL || 'http://localhost:8005';
const retrieveServiceUrl = process.env.RETRIEVE_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -43,10 +44,18 @@ app.post('/adduser', async (req, res) => {
app.post('/createquestion', async (req, res) => {
try {
// Create a petition to the URL (le llegará a creation-service.js) with the option /createquestion and the req.body params
console.log("salgo de gateway hacia creation");
const questionResponse = await axios.post(creationServiceUrl+'/createquestion', req.body);
console.log("vengo de creation y estoy en gateway");
console.log(questionResponse.status);
// Return a json response with what we obtained on the petition
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.post('/getquestionshistory', async (req, res) => {
try {
// Create a petition to the URL (le llegará a retrieve-service.js) with the option /getgeneratedquestions and the req.body params
const questionResponse = await axios.post(retrieveServiceUrl+'/getquestionshistory', req.body);
// Return a json response with what we obtained on the petition
res.json(questionResponse.data);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions questions/creationservice/creation-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ const mongoose = require('mongoose');

// Crea la base de datos con las columnas especificadas
const questionSchema = new mongoose.Schema({
question: String,
correctAnswer: String,
incorrectAnswer1: String,
incorrectAnswer2: String,
incorrectAnswer3: String,
question: {
type: String,
required: true,
},
correctAnswer: {
type: String,
required: true,
},
incorrectAnswer1: {
type: String,
required: true,
},
incorrectAnswer2: {
type: String,
required: true,
},
incorrectAnswer3: {
type: String,
required: true,
},
});

const Question = mongoose.model('Question', questionSchema);
Expand Down
34 changes: 31 additions & 3 deletions questions/creationservice/creation-service.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const express = require('express');
const mongoose = require('mongoose');
const fetch = require('node-fetch');
const Question = require('./creation-model');

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

app.use(express.json());

const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
mongoose.connect(mongoUri);

const optionsNumber = 4;

// It will be the country of the question
// It will be the questionObject
var questionObject= "";
// It will be the correct capital of the question
// It will be the correct answer
var correctOption = "";
// It will be the different options for the answers
var answerOptions = [];
Expand All @@ -22,7 +26,7 @@ var queries = ['SELECT DISTINCT ?questionObject ?questionObjectLabel ?answer ?an
// Array of the possible questions
var questions = ["¿Cual es la capital de "];

// Recieves the information of the query and select wich data use on the question (country and capitals)
// Recieves the information of the query and select wich data use on the question
function getQuestionInfo(info){
answerOptions = [];
var fourRows = [];
Expand All @@ -47,6 +51,28 @@ function selectRandomQuery(){
randomQuerySelector = Math.floor(Math.random() * queries.length);
}

async function saveQuestion(){
var incorrectAnswers=[];
answerOptions.forEach(e => {
if(e!=correctOption)
incorrectAnswers.push(e);
});

try {
const newQuestion = new Question({
question: questionObject,
correctAnswer: correctOption,
incorrectAnswer1: incorrectAnswers[0],
incorrectAnswer2: incorrectAnswers[1],
incorrectAnswer3: incorrectAnswers[2]
});
await newQuestion.save();

}catch (error){
console.error("Error al guardar la pregunta: " + error);
}
}

app.post('/createquestion', async (req, res) => {
selectRandomQuery();
const apiUrl = `https://query.wikidata.org/sparql?query=${encodeURIComponent(queries[randomQuerySelector])}&format=json`;
Expand Down Expand Up @@ -77,6 +103,8 @@ app.post('/createquestion', async (req, res) => {
responseCorrectOption : correctOption,
responseAnswerOptions : answerOptions
};

saveQuestion();

// Return the resoult with a 200 status
res.status(200).json(solution);
Expand Down
2 changes: 1 addition & 1 deletion questions/creationservice/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "creationservice",
"version": "1.0.0",
"description": " Creation service, in charge of ",
"description": " Creation service, in charge of create the questions of the game and store them",
"main": "service.js",
"scripts": {
"start": "node creation-service.js",
Expand Down
2 changes: 2 additions & 0 deletions questions/retrieveservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
20 changes: 20 additions & 0 deletions questions/retrieveservice/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/retrieveservice

# 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", "retrieve-service.js"]
Loading

0 comments on commit d9d57fb

Please sign in to comment.