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 #89

Merged
merged 81 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
1b6ef82
footer added
uo288574 Mar 18, 2024
c94c0ec
Nav bar
uo288574 Mar 19, 2024
c91901e
first version of tests (problems with nav import)
uo288574 Mar 19, 2024
0bc3393
Fixed problem with the control of the order of questions, ow they don…
alegarman2002 Mar 19, 2024
5f8d556
Merge branch 'master' into webapp_interface
alegarman2002 Mar 20, 2024
bfce6bf
Added the first version of game service but I have to fix it because …
alegarman2002 Mar 20, 2024
8674c79
fixed the last problems with the connection of the game service
alegarman2002 Mar 20, 2024
17d7fc2
The id could be a counter that we can increment with each game we create
alegarman2002 Mar 20, 2024
627f694
Added to the menu the first version of customizing games
uo288574 Mar 21, 2024
0fe0525
Progress bar done, still need to test
uo288574 Mar 21, 2024
60920e1
Added nav, footer and linear progress for game
uo288574 Mar 26, 2024
1b745da
Added nav and footer for menu
uo288574 Mar 26, 2024
696534b
menu changes
uo288574 Mar 28, 2024
4d9b2ef
added instructions
uo288574 Mar 28, 2024
7ef0cc9
Merge branch 'develop' into webapp_interface
uo288574 Mar 29, 2024
84fa3d7
Added the first version of open api in the game service
alegarman2002 Mar 29, 2024
7951d3e
First version of the game service with id but still not working ( we …
alegarman2002 Mar 30, 2024
aedfdc5
Added imports and useEffect
uo288574 Mar 30, 2024
dcfd1d1
import for SvgIcon
uo288574 Mar 30, 2024
11c6189
fixed a lot of problems with the webapp and updated the question gestion
alegarman2002 Mar 30, 2024
36cdec2
Apparently first version of game service before adding the game histo…
alegarman2002 Mar 31, 2024
478e7d2
Merge branch 'develop' into webapp_interface
alegarman2002 Mar 31, 2024
d3a45c5
Nav and footer colour changed and footer position fixed.
uo288574 Apr 1, 2024
611fb43
Fixed problems with storage games
alegarman2002 Apr 3, 2024
fc86f3b
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 3, 2024
492f7c5
nav test
uo288574 Apr 3, 2024
16df92e
Added 'ContextFun' and 'Router' for test
uo288574 Apr 3, 2024
03cd087
added nav and footer for login/sing up view
uo288574 Apr 4, 2024
64ee780
remove repeated import
uo288574 Apr 4, 2024
a7fc986
added footer test
uo288574 Apr 4, 2024
f860019
test file for menu and solved problem with user stats service test
uo288574 Apr 4, 2024
0d4ccec
remove import
uo288574 Apr 4, 2024
d4c3130
delete the test file because it still doesn't prove anything.
uo288574 Apr 4, 2024
b64e9b6
test fixed
uo288574 Apr 4, 2024
99b1bf0
trying to pass sonar cloud test
uo288574 Apr 4, 2024
8ee80c1
Merge branch 'develop' into webapp_interface
uo288574 Apr 5, 2024
ced7e14
show an other question if progress bar reach 100%
uo288574 Apr 5, 2024
c24eb99
Ending the game when we have 3 errors (commented)
uo288574 Apr 6, 2024
f10aed8
deleted unused progress bar
uo288574 Apr 6, 2024
5085463
Workin on the openapi doc
alegarman2002 Apr 6, 2024
8a6e54e
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 6, 2024
b9d63d4
Created all openapi files except the ones of wikidata
alegarman2002 Apr 6, 2024
1ead5df
Added the dependencies to deploy the openapi
alegarman2002 Apr 10, 2024
068e58f
first menu test
uo288574 Apr 10, 2024
00a3c30
Merge branch 'develop' into webapp_interface
uo288574 Apr 10, 2024
aa6ff89
Updated some problems with the openapi format
alegarman2002 Apr 10, 2024
477bf7c
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 Apr 10, 2024
dd1a762
updated dependecies of lock.json
alegarman2002 Apr 10, 2024
e3e1514
menu test
uo288574 Apr 10, 2024
b152712
menu test
uo288574 Apr 10, 2024
f8aebe7
change imports
uo288574 Apr 10, 2024
8277a8b
trying to pass firts test
uo288574 Apr 10, 2024
076606d
show an other question when progress bar reach 100%
uo288574 Apr 10, 2024
5808c81
new method to use progress bar
uo288574 Apr 10, 2024
ae2ddd3
change menu test and progress bar at 0% with correct answer
uo288574 Apr 10, 2024
4052482
firts menu test
uo288574 Apr 10, 2024
8538c25
check game modes
uo288574 Apr 10, 2024
ee72fe1
change test
uo288574 Apr 10, 2024
8be59e2
minor fixes
marco-qg Apr 10, 2024
d47717f
new game mode (we have to refactor between game modes)
uo288574 Apr 10, 2024
112b9fa
test for "firstGame"
uo288574 Apr 10, 2024
863ca4e
trying to pass first test for "firstGame"
uo288574 Apr 10, 2024
edc34c7
imports
uo288574 Apr 10, 2024
9cce98b
minor fix
uo288574 Apr 10, 2024
8ab9746
minor fix
uo288574 Apr 10, 2024
d6d937d
code refactoring
marco-qg Apr 10, 2024
1cd19af
removing warnings
marco-qg Apr 10, 2024
07cc011
progress bar fixed
marco-qg Apr 10, 2024
c2fcc2f
Fixed problem with one openapi identation
alegarman2002 Apr 10, 2024
5ef7220
Updated files of build and release for github deploy
alegarman2002 Apr 10, 2024
0871440
fixed warnings in game3.js
alegarman2002 Apr 10, 2024
8ce6ae7
Trying to fix test od first game
alegarman2002 Apr 10, 2024
24a12e3
commented test, we should do it when everything is fixed
marco-qg Apr 10, 2024
28d7686
Solving problem with lack of tests in suite
marco-qg Apr 11, 2024
cae4755
removing test call
marco-qg Apr 11, 2024
40a8eb4
refactor game3
uo288574 Apr 11, 2024
ca4b96a
file Game with some duplicate code from FirstGame and Game3
uo288574 Apr 11, 2024
f92388a
webapp style improvement
marco-qg Apr 11, 2024
ae1287f
Fixed tests
marco-qg Apr 11, 2024
8e307c2
small login fix
marco-qg Apr 11, 2024
2df55c9
Added blur
marco-qg Apr 11, 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
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ jobs:
- run: npm --prefix webapp ci
- run: npm --prefix storeQuestionService ci
- run: npm --prefix userStatsService ci
- run: npm --prefix gameservice 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 storeQuestionService test -- --coverage
- run: npm --prefix userStatsService test -- --coverage
# - run: npm --prefix gameservice test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ jobs:
- run: npm --prefix storeQuestionService ci
- run: npm --prefix userStatsService ci
- run: npm --prefix webapp ci
- run: npm --prefix gameservice 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 storeQuestionService test -- --coverage
- run: npm --prefix userStatsService test -- --coverage
#- run: npm --prefix gameservice test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down Expand Up @@ -207,6 +209,26 @@ jobs:
registry: ghcr.io
workdir: userStatsService
platforms: linux/arm64
docker-push-gameservice:
name: Push game service Docker Image to GitHub Packages
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [e2e-tests]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_es6c/gameservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: gameservice
platforms: linux/arm64
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

gameservice:
container_name: gameservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6c/gameservice:latest
profiles: ["dev", "prod"]
build: ./gameservice
depends_on:
- questiongeneratorservice
ports:
- "8005:8005"
networks:
- mynetwork
environment:
QUESTIONS_GENERATOR_SERVICE_URL: http://questiongeneratorservice:8007
STORE_STATS_SERVICE: http://userstatsservice:8003

questiongeneratorservice:
container_name: questiongeneratorservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6c/questiongeneratorservice:latest
Expand Down Expand Up @@ -99,6 +114,8 @@ services:
USER_STATS_SERVICE_URL: http://userstatsservice:8003
STORE_QUESTION_SERVICE_URL: http://storequestionservice:8004
QUESTIONS_GENERATOR_SERVICE_URL: http://questiongeneratorservice:8007
GAME_SERVICE_URL: http://gameservice:8005


webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down
2 changes: 2 additions & 0 deletions gameservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
20 changes: 20 additions & 0 deletions gameservice/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/gameService

# 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 8005

# Define the command to run your app
CMD ["node", "game-service.js"]
109 changes: 109 additions & 0 deletions gameservice/game-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const express = require('express');
const cors = require('cors');
const axios = require('axios');

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

const questionService = process.env.QUESTIONS_GENERATOR_SERVICE_URL || 'http://localhost:8007';
const userStatsService = process.env.STORE_STATS_SERVICE ||'http://localhost:8003';

function generateAleatoryString() {
let characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; // Caracteres alfanuméricos
let len = 24;
let result = '';
for (let i = 0; i < len; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}


// Middleware to parse JSON in request body
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;

app.get('/generateGameUnlimitedQuestions', async (req, res) => {
try {
console.log("Llegamos a crear un id del juego")
var gameId = generateAleatoryString()
res.json(gameId)
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' })
}
})


// Route for getting questions
app.get('/gameUnlimitedQuestions', async (req, res) => {
try {
// TODO: Implement logic to fetch questions from MongoDB and send response
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Líneas que sobran

// const questions = await Question.find()
console.log("Llegamos a pedir preguntas")
const questionGenerated = await axios.get(`${questionService}/questions?n_preguntas=${1}`);
console.log("Pedimos las preguntas")
res.json(questionGenerated.data);
} catch (error) {
// res.status(500).json({ message: error.message })
res.status(500).json({ error: 'Internal Server Error' });
}
});

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
console.log("Vamos a guardar resultado")
const store = await axios.post(`${userStatsService}/history/game`, {id, username, points, questions})
console.log("Guardamos resultado")
res.json(store.data)
} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
})

app.use((err, req, res, next) => {
console.error(`An error occurred: ${err}`);
res.status(500).send(`An error occurred: ${err.message}`);
});



//libraries required for OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs")
const YAML = require('yaml')

// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
if (fs.existsSync(openapiPath)) {
const file = fs.readFileSync(openapiPath, 'utf8');

// Parse the YAML content into a JavaScript object representing the Swagger document
const swaggerDocument = YAML.parse(file);

// Serve the Swagger UI documentation at the '/api-doc' endpoint
// This middleware serves the Swagger UI files and sets up the Swagger UI page
// It takes the parsed Swagger document as input
app.use('/api-doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
} else {
console.log("Not configuring OpenAPI. Configuration file not present.")
}

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

server.on('close', () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tienes ni mongo en este servicio... Esto sobra

// Close the Mongoose connection
});

module.exports = server
146 changes: 146 additions & 0 deletions gameservice/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
openapi: 3.0.0
info:
title: GameService API
description: Gateway OpenAPI specification.
version: 0.2.0
servers:
- url: http://localhost:8005
description: Development server
- url: http://gameservice:8005
description: Production server
paths:
/generateGameUnlimitedQuestions:
get:
summary: Generate the id for the unlimited game questions.
operationId: generateGameUnlimitedQuestions
requestBody:
required: true
content:
application/json:
schema:
type: object
responses:
'200':
description: Create the id of the game and returned successfuly.
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: The id of the game created.
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
/gameUnlimitedQuestion:
get:
summary: Generate questions for the unlimited game questions.
operationId: gameUnlimitedQuestions
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: Game Id.
example: sqeweg12er56yg46u89k
responses:
'200':
description: Question created and returned successfuly.
content:
application/json:
schema:
type: object
properties:
answers:
type: List<String>
description: List with the possible answers.
example:
question:
type: String
description: The question that is going to be done
correctAnswer:
type: String
description: The correct answer for the question
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
/storeGame:
post:
summary: Stores the actual game in the database.
operationId: storeGame
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: Game Id.
example: sqeweg12er56yg46u89k
username:
type: string
description: The name if the user.
points:
type: integer
description: The number of points that the user score.
questions:
answers:
type: List<String>
description: List with the possible answers.
example:
question:
type: String
description: The question that is going to be done
correctAnswer:
type: String
description: The correct answer for the question
responses:
'200':
description: Question created and returned successfuly.
content:
application/json:
schema:
type: object
properties:
id:
type: string
description: The question that is going to bre realized.
example:
answers:
type: List<String>
description: List with the possible answers.
example:
'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
Loading