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

Game front end #45

Closed
wants to merge 104 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
76ab05b
create qg service
pelazas Feb 21, 2024
cc77134
make docker image work
pelazas Feb 22, 2024
48faa7a
make sparql query
pelazas Feb 22, 2024
ee6b976
check docker for development
pelazas Feb 22, 2024
235ab8b
First view with register and login button with no style applied yet
carolbgmm Feb 22, 2024
0ba9fd4
Small error in tsconfig.json fixed
carolbgmm Feb 22, 2024
28df9dd
Added jsx:react compiler option to tsconfig.json
carolbgmm Feb 22, 2024
09212df
generate question about population in united states
pelazas Feb 23, 2024
d9bf7b4
organize code
pelazas Feb 23, 2024
e454103
question population spain
pelazas Feb 23, 2024
acfcda9
save questions in db
pelazas Feb 23, 2024
af892d7
endpoint in gateway service
pelazas Feb 23, 2024
2a696ad
tests for population question
pelazas Feb 23, 2024
21890a3
fix test
pelazas Feb 23, 2024
387f3c1
Removed unused imports
carolbgmm Feb 23, 2024
93e3911
Changed test
carolbgmm Feb 23, 2024
2e3be49
I18n of the init, adduser and login views
carolbgmm Feb 25, 2024
3150c61
Small change in test
carolbgmm Feb 26, 2024
43978a3
Tests should be working now
carolbgmm Feb 26, 2024
2098203
NOW all test pass
carolbgmm Feb 26, 2024
6a7c622
Merge pull request #30 from Arquisoft/front-end
carolbgmm Feb 26, 2024
219bf25
add small comments
pelazas Feb 27, 2024
e1328c6
generate chatgpt questions 1
pelazas Feb 27, 2024
f24bd60
generate chatgpt questions 2
pelazas Feb 27, 2024
9b11145
Added questions of spain capitals and countries capitals
UO277274 Feb 27, 2024
c0e27ab
Minor fix(typo loggin instead of login) and gapi,react-google-login d…
UO287741 Feb 27, 2024
4265d21
Google Login Menu, Login Button and Logout Button components created
UO287741 Feb 27, 2024
f4feb5e
Internationalization for login button was missing
UO287741 Feb 27, 2024
a2da5b7
merge with dev
pelazas Feb 28, 2024
7dd7e26
make spain capitals question work
pelazas Feb 28, 2024
abfbd8c
make world capitals work
pelazas Feb 28, 2024
4b6a811
put questions toguether into /game endpoint
pelazas Feb 28, 2024
b37a4ee
add math questions
pelazas Feb 28, 2024
bbd29a7
gateway endpoint
pelazas Feb 28, 2024
75825ca
make tests work
pelazas Feb 28, 2024
085ffb0
fix gateway tests
pelazas Feb 28, 2024
2ddef72
Merge pull request #29 from Arquisoft/questiongenerator1
pelazas Feb 28, 2024
a22b37d
Google Login V1
UO287741 Feb 28, 2024
29dd022
Google Login V2
UO287741 Feb 28, 2024
0ea5e47
Trying to fix dependency issues with react-google-login
UO287741 Feb 28, 2024
e1b0162
Google Login functionality halted temporaly
UO287741 Feb 28, 2024
1b0189e
Merge pull request #34 from Arquisoft/front-end
UO287741 Feb 28, 2024
4218d2c
Añadida primera version del boton de log in con google funcional
UO277274 Feb 28, 2024
0fce784
publish image 1
pelazas Feb 29, 2024
4327a0c
GameLayoutV1
UO287741 Feb 29, 2024
de7f80c
publish image 2
pelazas Mar 1, 2024
a83202e
publish image 3
pelazas Mar 1, 2024
9e0a8e1
trigger workflow
pelazas Mar 1, 2024
c9a0335
publish image 4
pelazas Mar 1, 2024
42370ca
trigger workflow
pelazas Mar 1, 2024
1efbe4b
modify docker-compose.yml
pelazas Mar 1, 2024
9426c49
added container to repository
pelazas Mar 1, 2024
6b6b3eb
fix e2e puppeter tests
pelazas Mar 1, 2024
1e46746
fix release.yml
pelazas Mar 1, 2024
179bf08
minor change release.yml
pelazas Mar 1, 2024
de81992
add qgservice to deploy
pelazas Mar 1, 2024
b969f03
Removed google login menu as it is unused
UO277274 Mar 4, 2024
fb4333f
Created pages to navigate through. Navbar is there but not working ju…
carolbgmm Mar 4, 2024
8becd9c
Working navigation bar. Needed to change the style
carolbgmm Mar 4, 2024
ec1271e
fixed small errors
carolbgmm Mar 4, 2024
684dc53
Created game service branch and directory
UO277274 Mar 5, 2024
cfd4bb3
Added game model to have 3 users and a array of questions
UO277274 Mar 5, 2024
207052f
fix gateway endpoint
pelazas Mar 5, 2024
e41df85
fix security hotspot
pelazas Mar 5, 2024
ddfe6ac
Merge pull request #36 from Arquisoft/upload-container1
pelazas Mar 5, 2024
e2628d4
game service setup
pelazas Mar 5, 2024
cbd41d8
added method to create new game entity and gateway
UO277274 Mar 5, 2024
ab72d7c
add container to github and deploy actions
pelazas Mar 5, 2024
43f96fe
structure development of logic to implement
pelazas Mar 5, 2024
83aa05a
Modified players to be 1 to many
UO277274 Mar 5, 2024
536a32a
Merge remote-tracking branch 'origin/gameLogic' into gameService1
UO277274 Mar 5, 2024
a198682
Merge pull request #42 from Arquisoft/gameService1
UO277274 Mar 5, 2024
5e05b2a
removed test as the structure has changed too much
carolbgmm Mar 6, 2024
7045dd9
create game endpoint + logic
pelazas Mar 7, 2024
9da71eb
add _id property to schemas and create game
pelazas Mar 7, 2024
83c5d21
[WIP] update user after game
pelazas Mar 7, 2024
9c9b11f
populate response and fix update lastGame
pelazas Mar 7, 2024
9887776
get lastGame by username
pelazas Mar 7, 2024
b136875
[WIP] test + fixing paths
pelazas Mar 7, 2024
a8ece70
add uuid field to user + postman request
pelazas Mar 7, 2024
06009e8
refactor + uuid + postman to question generator service
pelazas Mar 7, 2024
4ba87cb
give uuids to game model, make endpoints work
pelazas Mar 7, 2024
e881b96
postman for game service
pelazas Mar 7, 2024
07a1f94
gateway endpoint working
pelazas Mar 7, 2024
d626b57
update lastGame for each user that plays
pelazas Mar 7, 2024
9e708ff
update stats of players
pelazas Mar 7, 2024
122d5b1
get statistics by user
pelazas Mar 7, 2024
2bc5216
update gateway postman collection
pelazas Mar 7, 2024
a0b2ac3
fix auth test
pelazas Mar 7, 2024
1317e4e
fixing things
carolbgmm Mar 7, 2024
2160b8b
Merge pull request #43 from Arquisoft/routing-and-nav
UO287741 Mar 7, 2024
d257262
Small style changes
carolbgmm Mar 7, 2024
1b9d6e4
Merge branch 'dev' into front-end
carolbgmm Mar 7, 2024
fe789c5
comment test
pelazas Mar 8, 2024
8c905c2
fix some test + security
pelazas Mar 8, 2024
bda1c4c
fix user service tests
pelazas Mar 8, 2024
9dca29b
test for updateLastGame
pelazas Mar 8, 2024
26c295b
fix security url encoding
pelazas Mar 8, 2024
ca4251f
fix final security warnings
pelazas Mar 8, 2024
8909873
add validation
pelazas Mar 8, 2024
4eff7f8
Merge pull request #41 from Arquisoft/gameLogic
pelazas Mar 8, 2024
b0e8c58
Merge pull request #44 from Arquisoft/front-end
UO287741 Mar 9, 2024
112c541
Game View 1
UO287741 Mar 10, 2024
8723c80
Minor edition
UO287741 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
43 changes: 41 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
#- run: npm --prefix webapp run test:e2e
docker-push-webapp:
name: Push webapp Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -59,6 +59,43 @@ jobs:
registry: ghcr.io
workdir: webapp
buildargs: API_URI

docker-push-qgservice:
name: Push question generator 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_en2a/questiongenerator
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
registry: ghcr.io
workdir: game/qgservice

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:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_en2a/gameservice
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
registry: ghcr.io
workdir: game/gameservice

docker-push-authservice:
name: Push auth service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -76,6 +113,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/authservice

docker-push-userservice:
name: Push user service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -93,6 +131,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: users/userservice

docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -113,7 +152,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-qgservice]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
docs/build
docs/build
game/qgservice/.env
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

questiongeneratorservice:
container_name: qgservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en2a/questiongenerator:latest
profiles: ["dev", "prod"]
build: ./game/qgservice
depends_on:
- mongodb
ports:
- "8003:8003"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

gameservice:
container_name: gameservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_en2a/gameservice:latest
profiles: ["dev", "prod"]
build: ./game/gameservice
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
- questiongeneratorservice
- gameservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
QG_SERVICE_URL: http://questiongeneratorservice:8003
GAME_SERVICE_URL: http://gameservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down
2 changes: 2 additions & 0 deletions game/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 game/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 8004

# Define the command to run your app
CMD ["node", "gameservice.js"]
28 changes: 28 additions & 0 deletions game/gameservice/GameController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
let Game = require('./game-model');
const { createGame } = require('./queries/CreateGame');
const mongoose = require('mongoose');

let GameController = {
/* HACER EN USER - GET LAST GAME BY USER
findByUsername: async (req, res) => {
let game = await User.find({username: req.params.username}).populate("lastGame")
let response = await Game.findById(game[0].lastGame.id).populate("questions").populate("players")
res.json(response);
},*/
create: async (req, res) => {
const { questions, players } = req.body;
console.log(questions, players)
const game = await createGame(questions, players);
res.json(game);
},
delete: async (req, res) => {
await Game.findOneAndDelete({uuid: req.params.id});
res.json({message: "Game deleted"});
},
getById: async (req, res) => {
let game = await Game.find({uuid: req.params.id})
res.json(game);
}
}

module.exports = GameController;
22 changes: 22 additions & 0 deletions game/gameservice/game-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require('mongoose');

const gameSchema = new mongoose.Schema({
uuid: {
type: String,
required: true,
},
players:[{
type: String,
required: true,
}],
questions:[
{
type: String,
required: true,
}
],
});

const Game = mongoose.model('Game', gameSchema);

module.exports = Game
40 changes: 40 additions & 0 deletions game/gameservice/game-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');

let mongoServer;
let app;

beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
process.env.MONGODB_URI = mongoUri;
app = require('./gameservice');
});

afterAll(async () => {
app.close();
await mongoServer.stop();
});

describe('Game service', () => {

// mock data
const questions = [{ _id: 'question1_id' }, { _id: 'question2_id' }];
const users = [{ _id: 'user1_id' }, { _id: 'user2_id' }];

it('should create a game and update user lastGame field', async () => {
const response = await request(app).post('/creategame').send({questions,users});
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('_id');

const gameId = response.body._id;
const gameFromDB = await mongoose.model('Game').findById(gameId);
const user1FromDB = await mongoose.model('User').findById('user1_id');
const user2FromDB = await mongoose.model('User').findById('user2_id');

// Assertions for the database state
expect(gameFromDB).toBeTruthy();
expect(user1FromDB.lastGame.toString()).toBe(gameId);
expect(user2FromDB.lastGame.toString()).toBe(gameId);
});
});
32 changes: 32 additions & 0 deletions game/gameservice/gameservice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// gameservice.js
const express = require('express');
const axios = require('axios');
const mongoose = require('mongoose');
const { createGame } = require('./queries/CreateGame');
const GameController = require('./GameController');

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

// app.use(bodyParser.json());
app.use(express.json());

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

app.get('/', (req, res) => {
res.json({
"hi": "game service"
});
});

// Routes
app.post('/createGame', GameController.create);
app.delete('/deleteGame/:id', GameController.delete);
app.get('/getGame/:id', GameController.getById);

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

module.exports = server;
Loading