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

Develop a master para deployment #58

Merged
merged 108 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
46d5a46
Se ha añadido caché para las preguntas
CANCI0 Feb 18, 2024
c40363f
Añadido límite de preguntas por petición
CANCI0 Feb 18, 2024
f5b615e
Error corregido
CANCI0 Feb 18, 2024
4dd6a6a
Funciona
CANCI0 Feb 18, 2024
e245788
El get de famosos no funciona
CANCI0 Feb 18, 2024
e80d75d
Refactorización del código
CANCI0 Feb 18, 2024
4cb5f18
Añadidos más temáticas (not working)
CANCI0 Feb 18, 2024
f59be46
Error de acceso a propiedades
CANCI0 Feb 18, 2024
b0897ae
Añadida temática programación
CANCI0 Feb 18, 2024
8cd48fe
Ya no salen "Q8945..." en respuesta correcta
CANCI0 Feb 18, 2024
8f01659
Ahora se pueden obtener preguntas aleatorias de varias temáticas
CANCI0 Feb 19, 2024
39a0540
Añadidos formateadores de fecha y número
CANCI0 Feb 19, 2024
6a08a27
Cambios menores
CANCI0 Feb 19, 2024
f4add29
Really basic prototype to calculate user stats
iyanfdezz Feb 19, 2024
054c082
Cambios menores
CANCI0 Feb 20, 2024
8e861fc
Interfaz básica
CANCI0 Feb 20, 2024
e7d2996
Se ha conectado la interfaz con la API de preguntas (no va la puntuac…
CANCI0 Feb 20, 2024
348c09b
Ya funciona
CANCI0 Feb 20, 2024
8ef17ec
Making progress in Stats API
iyanfdezz Feb 20, 2024
07c9bb4
Merge pull request #31 from Arquisoft/Interfaz
iyanfdezz Feb 21, 2024
26e3563
Now deployment works
iyanfdezz Feb 21, 2024
757a88f
Se ha dockerizado el módulo
CANCI0 Feb 21, 2024
8933b43
Se ha añadido el módulo al docker-compose
CANCI0 Feb 21, 2024
cfd9bc7
Merge pull request #33 from Arquisoft/Dockerizar-API-preguntas-#32
CANCI0 Feb 21, 2024
920414a
Merge pull request #34 from Arquisoft/user-stats
CANCI0 Feb 21, 2024
88bdb06
Autentificación de usuario
Rodrox11 Feb 21, 2024
61ce2fe
Added games to the user database
iyanfdezz Feb 22, 2024
f0dadc1
Now number of correct and incorrect questions are saved during the game
iyanfdezz Feb 22, 2024
928d645
Now average time per question is also calculated
iyanfdezz Feb 22, 2024
8828bd1
Now the game saves on the users database (no sé si funciona)
iyanfdezz Feb 22, 2024
ef35c76
Merge pull request #35 from Arquisoft/user-stats
CANCI0 Feb 24, 2024
6742afb
Fixed user's database (currently not working)
iyanfdezz Feb 24, 2024
35f70e3
Servicio de estadísticas dockerizado (errores)
CANCI0 Feb 24, 2024
40364c7
Merge pull request #36 from Arquisoft/Dockerizar-statsservice
CANCI0 Feb 24, 2024
d4fb131
Added UI for Stats service (not working)
iyanfdezz Feb 29, 2024
8325791
Primer formateo de la vista
UO288443 Mar 1, 2024
721d1f0
Now ststs view shows up
iyanfdezz Mar 2, 2024
46bdad3
Stats reject connection
iyanfdezz Mar 2, 2024
8327b73
Stats get and post added to gateway service
iyanfdezz Mar 2, 2024
d38c772
Arreglos
CANCI0 Mar 3, 2024
a81d4bb
Añadadida pregunta de banderas de países
CANCI0 Mar 3, 2024
14e0db2
dockerized stats service (not working)
iyanfdezz Mar 3, 2024
5fc66a5
Still working on stats service
iyanfdezz Mar 3, 2024
d9ded20
Finally works
iyanfdezz Mar 3, 2024
c01b06d
Arreglada autenticación de usuario
iyanfdezz Mar 4, 2024
d61e573
Añadidos tests sobre la API questions
CANCI0 Mar 4, 2024
be84b2b
Ahora funcionan los colorines de respuesta correcta e incorrecta del …
CANCI0 Mar 4, 2024
f0e3bf8
Casi funciona el nuevo modo "Batería de sabios"
CANCI0 Mar 4, 2024
5a58f9d
Ya funciona el segundo modo
CANCI0 Mar 4, 2024
a808bde
Merge branch 'develop' into Generación-de-preguntasV2-#2
CANCI0 Mar 4, 2024
3ee43e8
Merge pull request #39 from Arquisoft/Generación-de-preguntasV2-#2
CANCI0 Mar 4, 2024
6910348
Fixes
CANCI0 Mar 4, 2024
bc5ac14
More fixes
CANCI0 Mar 4, 2024
93a9a65
Finally stats are showing (missing avg time and final question)
iyanfdezz Mar 4, 2024
b71b5df
Merge branch 'develop' into stats-ui
iyanfdezz Mar 4, 2024
dd7299f
Merge pull request #40 from Arquisoft/stats-ui
iyanfdezz Mar 4, 2024
f2f8259
Hotfix
iyanfdezz Mar 4, 2024
e2a88f4
More fixes + avg time added (not well calculated)
iyanfdezz Mar 4, 2024
2c36795
Merge pull request #41 from Arquisoft/fixing-stats
iyanfdezz Mar 4, 2024
2b00b6d
Gestión de acesso a rutas privadas
Rodrox11 Mar 5, 2024
cf74f29
Ya no se repite la primera pregunta en clásico
CANCI0 Mar 5, 2024
f51cf40
Se ha añadido timeout a la búsqueda de usuarios para no sobrecargar a…
CANCI0 Mar 5, 2024
68a9c24
Merge pull request #45 from Arquisoft/testing
CANCI0 Mar 5, 2024
8451c0b
Merge branch 'develop' into Cancio-GeneralFixes
CANCI0 Mar 5, 2024
bb4dad8
Merge pull request #46 from Arquisoft/Cancio-GeneralFixes
CANCI0 Mar 5, 2024
8e35c02
Ahora el login redirige a /home
CANCI0 Mar 5, 2024
6775360
Dependecia sin usar eliminada
CANCI0 Mar 5, 2024
b6541cf
Merge remote-tracking branch 'origin/develop' into Cancio-GeneralFixes
CANCI0 Mar 5, 2024
36f9999
implementación del logout
Rodrox11 Mar 5, 2024
e22f45c
Borradas dependencias en desuso
CANCI0 Mar 5, 2024
3c0d33c
Merge pull request #47 from Arquisoft/Cancio-GeneralFixes
CANCI0 Mar 5, 2024
e2307f5
Agregar vision de /sobre
Rodrox11 Mar 7, 2024
744fc5e
Ya no puede coincidir el nombre de la entidad con el de una de sus pr…
CANCI0 Mar 7, 2024
b21fca3
Más correcciones
CANCI0 Mar 7, 2024
bfd195b
Cambios en la lógica de los modos de juego
CANCI0 Mar 7, 2024
c45c010
Añadida alerta si no se cargan las preguntas
CANCI0 Mar 7, 2024
5541f4d
Ahora se manejan errores cuando el servicio de preguntas está cargand…
CANCI0 Mar 7, 2024
8080a75
Se ha añadido mensaje de error
CANCI0 Mar 7, 2024
88ac67d
Merge pull request #49 from Arquisoft/Cancio-fixes
CANCI0 Mar 7, 2024
92e99f6
Arreglado bud de Batería de sabios
CANCI0 Mar 7, 2024
b97569f
CSS fixes
iyanfdezz Mar 7, 2024
1f614a7
Fix in format
iyanfdezz Mar 7, 2024
62ff82a
arreglar errores
Rodrox11 Mar 8, 2024
3ad21da
arreglar error de prueba
Rodrox11 Mar 8, 2024
2787cf5
corregir error logout
Rodrox11 Mar 8, 2024
88b2f8a
implementacion de App.test
Rodrox11 Mar 8, 2024
64fefda
corregir wrongRoute
Rodrox11 Mar 8, 2024
4fb66bd
implementar test
Rodrox11 Mar 8, 2024
a6c3dcc
Arreglado error de doble data fetch
CANCI0 Mar 8, 2024
e593c05
Merge pull request #53 from Arquisoft/Cancio-fixes
CANCI0 Mar 9, 2024
34e15e2
Arreglos
CANCI0 Mar 9, 2024
7f6ee20
Test casi listos
UO288443 Mar 9, 2024
b5949d0
Modo de juego conoce ciudades
UO288443 Mar 9, 2024
a31ecf4
Merge branch 'develop' of https://github.com/Arquisoft/wiq_es1a into …
UO288443 Mar 9, 2024
5671bdc
Avances en el modo oscuro
CANCI0 Mar 9, 2024
f3e95b7
YA cambia de tema
CANCI0 Mar 9, 2024
9bc3f12
Ya funciona correctamente
CANCI0 Mar 9, 2024
9e2e976
Merge pull request #55 from Arquisoft/Modo-Oscuro
CANCI0 Mar 9, 2024
0c38559
Agregar test componente Footer
Rodrox11 Mar 10, 2024
795c5d1
Merge branch 'testing' of https://github.com/Arquisoft/wiq_es1a into …
Rodrox11 Mar 10, 2024
d427fc1
Merge remote-tracking branch 'origin/develop' into testing
iyanfdezz Mar 10, 2024
7dfa70b
Añadidas las pages al sonar
CANCI0 Mar 10, 2024
46e2c5a
Cambios para el deploy
CANCI0 Mar 10, 2024
c80c4be
Eliminados test stats porque no funcionan
iyanfdezz Mar 10, 2024
98c9397
Merge branch 'testing' of https://github.com/Arquisoft/wiq_es1a into …
iyanfdezz Mar 10, 2024
33a921c
Merge pull request #57 from Arquisoft/testing
CANCI0 Mar 10, 2024
5a6a104
Tests arreglados
CANCI0 Mar 10, 2024
2585a11
Merge branch 'master' into develop
iyanfdezz Mar 10, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ jobs:
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
Expand Down
39 changes: 38 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionservice ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
Expand All @@ -36,6 +37,8 @@ jobs:
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix questionservice install
- run: npm --prefix statsservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
Expand Down Expand Up @@ -93,6 +96,40 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice
docker-push-statsservice:
name: Push stats 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_es1a/statsservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: statsservice
docker-push-questionservice:
name: Push questions 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_es1a/questionservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: questionservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -113,7 +150,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-gatewayservice,docker-push-webapp,docker-push-questionservice, docker-push-statsservice]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ services:
networks:
- mynetwork

questionservice:
container_name: questionservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/questionservice:latest
profiles: ["dev", "prod"]
build: ./questionservice
ports:
- "8003:8003"
networks:
- mynetwork

statsservice:
container_name: statsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/statsservice:latest
profiles: ["dev", "prod"]
build: ./statsservice
depends_on:
- mongodb
- userservice
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
USER_SERVICE_URL: http://userservice:8001

authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/authservice:latest
Expand Down Expand Up @@ -46,13 +72,17 @@ services:
build: ./gatewayservice
depends_on:
- mongodb
- statsservice
- userservice
- authservice
- questionservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
STATS_SERVICE_URL: http://statsservice:8004
QUESTION_SERVICE_URL: http://questionservice:8003
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001

Expand Down
117 changes: 101 additions & 16 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,128 @@
const express = require('express');
const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');
const express = require("express");
const axios = require("axios");
const cors = require("cors");
const promBundle = require("express-prom-bundle");

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

const authServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8002';
const userServiceUrl = process.env.USER_SERVICE_URL || 'http://localhost:8001';
const authServiceUrl = process.env.AUTH_SERVICE_URL || "http://localhost:8002";
const userServiceUrl = process.env.USER_SERVICE_URL || "http://localhost:8001";
const questionServiceUrl =
process.env.QUESTION_SERVICE_URL || "http://localhost:8003";
const statsServiceUrl = process.env.AUTH_SERVICE_URL || "http://localhost:8004";


app.use(cors());
app.use(express.json());

//Prometheus configuration
const metricsMiddleware = promBundle({includeMethod: true});
const metricsMiddleware = promBundle({ includeMethod: true });
app.use(metricsMiddleware);

app.set("json spaces", 40);

// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'OK' });
app.get("/health", (req, res) => {
res.json({ status: "OK" });
});

app.post('/login', async (req, res) => {
app.post("/login", async (req, res) => {
try {
// Forward the login request to the authentication service
const authResponse = await axios.post(authServiceUrl+'/login', req.body);
const authResponse = await axios.post(authServiceUrl + "/login", req.body);
res.json(authResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.post('/adduser', async (req, res) => {
app.post("/adduser", async (req, res) => {
try {
// Forward the add user request to the user service
const userResponse = await axios.post(userServiceUrl+'/adduser', req.body);
const userResponse = await axios.post(
userServiceUrl + "/adduser",
req.body
);
res.json(userResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.get("/questions", async (req, res) => {
try {
// Forward the question request to the question service
const questionResponse = await axios.get(
questionServiceUrl + "/questions",
{ params: req.query }
);
res.json(questionResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.get("/stats", async (req, res) => {
try {
// Forward the stats request to the stats service
const statsResponse = await axios.get(statsServiceUrl + "/stats", req.body);
res.json(statsResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.post("/saveGame", async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(
statsServiceUrl + "/saveGame",
req.body
);
res.json(gameResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.get("/getstats", async (req, res) => {
try {
// Forward the stats request to the stats service
const statsResponse = await axios.get(
userServiceUrl + "/getstats",
req.body
);
res.json(statsResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.post("/userSaveGame", async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(
userServiceUrl + "/userSaveGame",
req.body
);
res.json(gameResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

Expand All @@ -46,4 +131,4 @@ const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
});

module.exports = server
module.exports = server;
52 changes: 52 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ describe('Gateway Service', () => {
}
});

axios.get.mockImplementation((url, data) => {
if (url.endsWith("/questions")) {
return Promise.resolve({
data: [
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
],
});
} else if (url.endsWith("/questions?n=1&tematica=all")) {
return Promise.resolve({
data: [
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
],
});
}
});

// Test /login endpoint
it('should forward login request to auth service', async () => {
const response = await request(app)
Expand All @@ -37,4 +61,32 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Prueba de la ruta /questions
it("should return a question", async () => {
const response = await request(app).get("/questions");

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki",
},
]);
});

// Prueba de la ruta /questions?n=1&tematica=all
it("should return a question", async () => {
const response = await request(app).get("/questions?n=1&tematica=all");

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
{
pregunta: "¿Cuál es la capital de Finlandia?",
respuestas: ["Ámsterdam", "Pretoria", "Lima", "Helsinki"],
correcta: "Helsinki"
}
]);
});
});
Loading
Loading