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

Uo289659 #101

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb



gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/gatewayservice:latest
Expand Down Expand Up @@ -115,6 +113,8 @@ services:
environment:
GATEWAY_SERVICE_URL: http://gatewayservice:8000



prometheus:
image: prom/prometheus
container_name: prometheus-${teamname:-defaultASW}
Expand Down
15 changes: 11 additions & 4 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const statisticssServiceUrl = process.env.STATS_SERVICE_URL || 'http://localhost
const generatorServiceUrl = process.env.GENERATOR_SERVICE_URL || 'http://localhost:8003';
const questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8004';


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

Expand Down Expand Up @@ -84,15 +83,23 @@ app.get('/questions', async (req, res) => {

app.post('/addStatistic', async (req, res) => {
try {
const questionResponse = await axios.post(statisticssServiceUrl+'/addStatistic',
req.body,
);
const questionResponse = await axios.post(statisticssServiceUrl+'/addStatistic', req.body );
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

app.get('/users', async (req, res) => {
try {
// Forward the get questions request to the question service
const usersResponse = await axios.get(userServiceUrl+'/users');
res.json(usersResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});


// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
Expand Down
18 changes: 18 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ describe('Gateway Service', () => {
return Promise.resolve({ data: { question: 'mockedQuestion' } });
}else if (url.endsWith('/questions')) {
return Promise.resolve({ data: { question: 'mockedQuestion' } });
}else if (url.endsWith('/statistics')) {
return Promise.resolve({ data: { gamesPlayed: 'mockedGamesPlayed' ,
rigthAnswers: 'mockedRigthAnswers',
wrongAnswers:'mockedWrongAnswers' }});
}
});



// Test /login endpoint
it('should forward login request to auth service', async () => {
const response = await request(app)
Expand Down Expand Up @@ -61,4 +67,16 @@ describe('Gateway Service', () => {
expect(response.statusCode).toBe(200);
expect(response.body.question).toBe('mockedQuestion');
});

// Test /statistics endpoint
it('should forward get statistics request to statistics service', async () => {
const response = await request(app)
.get('/statistics');

expect(response.statusCode).toBe(200);
expect(response.body.gamesPlayed).toBe('mockedGamesPlayed');
expect(response.body.rigthAnswers).toBe('mockedRigthAnswers');
expect(response.body.wrongAnswers).toBe('mockedWrongAnswers');
});

});
48 changes: 47 additions & 1 deletion gatewayservice/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,50 @@ paths:
error:
type: string
description: Error information.
example: Internal Server Error
example: Internal Server Error
/users:
get:
summary: Get all users.
operationId: getUsers
responses:
'200':
description: Users retrieved successfully.
content:
application/json:
schema:
type: array
items:
type: object
properties:
_id:
type: string
description: user ID.
example: 65f756db3fa22d227a4b7c7d
username:
type: string
description: User.
example: carmen
gamesPlayed:
type: integer
description: Games played.
example: 2
rigthAnswers:
type: integer
description: Right answers.
example: 5
wrongAnswers:
type: integer
description: Wrong answers.
example: 5

'500':
description: Internal server error.
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error information.
example: Internal Server Error
6 changes: 6 additions & 0 deletions gatewayservice/package-lock.json

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

63 changes: 32 additions & 31 deletions gatewayservice/package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{
"name": "gatewayservice",
"version": "1.0.0",
"description": "Gateway service, in charge distributing the requests",
"main": "service.js",
"scripts": {
"start": "node gateway-service.js",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/arquisoft/wiq_es3a.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/arquisoft/wiq_es3a/issues"
},
"homepage": "https://github.com/arquisoft/wiq_es3a#readme",
"dependencies": {
"axios": "^1.6.5",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-openapi": "^12.1.3",
"express-prom-bundle": "^7.0.0",
"swagger-ui-express": "^5.0.0",
"yaml": "^2.4.1"
},
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^6.3.4"
}
"name": "gatewayservice",
"version": "1.0.0",
"description": "Gateway service, in charge distributing the requests",
"main": "service.js",
"scripts": {
"start": "node gateway-service.js",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/arquisoft/wiq_es3a.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/arquisoft/wiq_es3a/issues"
},
"homepage": "https://github.com/arquisoft/wiq_es3a#readme",
"dependencies": {
"axios": "^1.6.5",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-openapi": "^12.1.3",
"express-prom-bundle": "^7.0.0",
"fs": "^0.0.1-security",
"swagger-ui-express": "^5.0.0",
"yaml": "^2.4.1"
},
"devDependencies": {
"jest": "^29.7.0",
"supertest": "^6.3.4"
}
}
Loading
Loading