forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Webapp interface #89
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
1b6ef82
footer added
uo288574 c94c0ec
Nav bar
uo288574 c91901e
first version of tests (problems with nav import)
uo288574 0bc3393
Fixed problem with the control of the order of questions, ow they don…
alegarman2002 5f8d556
Merge branch 'master' into webapp_interface
alegarman2002 bfce6bf
Added the first version of game service but I have to fix it because …
alegarman2002 8674c79
fixed the last problems with the connection of the game service
alegarman2002 17d7fc2
The id could be a counter that we can increment with each game we create
alegarman2002 627f694
Added to the menu the first version of customizing games
uo288574 0fe0525
Progress bar done, still need to test
uo288574 60920e1
Added nav, footer and linear progress for game
uo288574 1b745da
Added nav and footer for menu
uo288574 696534b
menu changes
uo288574 4d9b2ef
added instructions
uo288574 7ef0cc9
Merge branch 'develop' into webapp_interface
uo288574 84fa3d7
Added the first version of open api in the game service
alegarman2002 7951d3e
First version of the game service with id but still not working ( we …
alegarman2002 aedfdc5
Added imports and useEffect
uo288574 dcfd1d1
import for SvgIcon
uo288574 11c6189
fixed a lot of problems with the webapp and updated the question gestion
alegarman2002 36cdec2
Apparently first version of game service before adding the game histo…
alegarman2002 478e7d2
Merge branch 'develop' into webapp_interface
alegarman2002 d3a45c5
Nav and footer colour changed and footer position fixed.
uo288574 611fb43
Fixed problems with storage games
alegarman2002 fc86f3b
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 492f7c5
nav test
uo288574 16df92e
Added 'ContextFun' and 'Router' for test
uo288574 03cd087
added nav and footer for login/sing up view
uo288574 64ee780
remove repeated import
uo288574 a7fc986
added footer test
uo288574 f860019
test file for menu and solved problem with user stats service test
uo288574 0d4ccec
remove import
uo288574 d4c3130
delete the test file because it still doesn't prove anything.
uo288574 b64e9b6
test fixed
uo288574 99b1bf0
trying to pass sonar cloud test
uo288574 8ee80c1
Merge branch 'develop' into webapp_interface
uo288574 ced7e14
show an other question if progress bar reach 100%
uo288574 c24eb99
Ending the game when we have 3 errors (commented)
uo288574 f10aed8
deleted unused progress bar
uo288574 5085463
Workin on the openapi doc
alegarman2002 8a6e54e
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 b9d63d4
Created all openapi files except the ones of wikidata
alegarman2002 1ead5df
Added the dependencies to deploy the openapi
alegarman2002 068e58f
first menu test
uo288574 00a3c30
Merge branch 'develop' into webapp_interface
uo288574 aa6ff89
Updated some problems with the openapi format
alegarman2002 477bf7c
Merge branch 'webapp_interface' of https://github.com/Arquisoft/wiq_e…
alegarman2002 dd1a762
updated dependecies of lock.json
alegarman2002 e3e1514
menu test
uo288574 b152712
menu test
uo288574 f8aebe7
change imports
uo288574 8277a8b
trying to pass firts test
uo288574 076606d
show an other question when progress bar reach 100%
uo288574 5808c81
new method to use progress bar
uo288574 ae2ddd3
change menu test and progress bar at 0% with correct answer
uo288574 4052482
firts menu test
uo288574 8538c25
check game modes
uo288574 ee72fe1
change test
uo288574 8be59e2
minor fixes
marco-qg d47717f
new game mode (we have to refactor between game modes)
uo288574 112b9fa
test for "firstGame"
uo288574 863ca4e
trying to pass first test for "firstGame"
uo288574 edc34c7
imports
uo288574 9cce98b
minor fix
uo288574 8ab9746
minor fix
uo288574 d6d937d
code refactoring
marco-qg 1cd19af
removing warnings
marco-qg 07cc011
progress bar fixed
marco-qg c2fcc2f
Fixed problem with one openapi identation
alegarman2002 5ef7220
Updated files of build and release for github deploy
alegarman2002 0871440
fixed warnings in game3.js
alegarman2002 8ce6ae7
Trying to fix test od first game
alegarman2002 24a12e3
commented test, we should do it when everything is fixed
marco-qg 28d7686
Solving problem with lack of tests in suite
marco-qg cae4755
removing test call
marco-qg 40a8eb4
refactor game3
uo288574 ca4b96a
file Game with some duplicate code from FirstGame and Game3
uo288574 f92388a
webapp style improvement
marco-qg ae1287f
Fixed tests
marco-qg 8e307c2
small login fix
marco-qg 2df55c9
Added blur
marco-qg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// 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', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Líneas que sobran