Skip to content

Commit

Permalink
Merge pull request #84 from Arquisoft/API-InfoPreguntas
Browse files Browse the repository at this point in the history
Api info preguntas
  • Loading branch information
UO285267 authored Mar 21, 2024
2 parents 0822e5c + 2f3f4c4 commit e6a7f33
Show file tree
Hide file tree
Showing 15 changed files with 5,970 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ jobs:
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix preguntas/generatorservice ci
- run: npm --prefix preguntas/questionservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix preguntas/generatorservice test -- --coverage
- run: npm --prefix preguntas/questionservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ jobs:
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix preguntas/generatorservice ci
- run: npm --prefix preguntas/questionservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix preguntas/generatorservice test -- --coverage
- run: npm --prefix preguntas/questionservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
Expand All @@ -38,6 +40,7 @@ jobs:
- run: npm --prefix users/authservice install
- run: npm --prefix users/userservice install
- run: npm --prefix preguntas/generatorservice install
- run: npm --prefix preguntas/questionservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
Expand Down Expand Up @@ -113,6 +116,23 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: preguntas/generatorservice
docker-push-questionservice:
name: Push question 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_es3a/questionservice
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: preguntas/questionservice
docker-push-gatewayservice:
name: Push gateway service Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -122,6 +142,10 @@ jobs:
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Update OpenAPI configuration
run: |
DEPLOY_HOST=${{ secrets.DEPLOY_HOST }}
sed -i "s/SOMEIP/${DEPLOY_HOST}/g" gatewayservice/openapi.yaml
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
Expand All @@ -133,7 +157,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-generatorservice,docker-push-webapp]
needs: [docker-push-userservice,docker-push-authservice,docker-push-gatewayservice,docker-push-generatorservice,docker-push-questionservice,docker-push-webapp]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand Down
22 changes: 21 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ services:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
questionservice:
container_name: questionservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/questionservice:latest
profiles: ["dev", "prod"]
build: ./preguntas/questionservice
depends_on:
- mongodb
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb
userservice:
container_name: userservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es3a/userservice:latest
Expand All @@ -60,14 +73,16 @@ services:
- userservice
- authservice
- generatorservice
- questionservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
QUESTION_SERVICE_URL: http://generatorservice:8003
GENERATOR_SERVICE_URL: http://generatorservice:8003
QUESTION_SERVICE_URL: http://questionservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down Expand Up @@ -115,6 +130,11 @@ services:

volumes:
mongodb_data:
driver: local
driver_opts:
type: none
o: bind
device: /path/to/your/local/mongodb_data
prometheus_data:
grafana_data:

Expand Down
36 changes: 34 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ const express = require('express');
const axios = require('axios');
const cors = require('cors');
const promBundle = require('express-prom-bundle');
//libraries required for OpenAPI-Swagger
const swaggerUi = require('swagger-ui-express');
const fs = require("fs")
const YAML = require('yaml')

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 questionServiceUrl = process.env.QUESTION_SERVICE_URL || 'http://localhost:8003';
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 @@ -45,13 +50,40 @@ app.post('/adduser', async (req, res) => {
app.get('/generate-question', async (req, res) => {
try {
// Forward the generate question request to the question service
const questionResponse = await axios.get(questionServiceUrl+'/generate-question');
const questionResponse = await axios.get(generatorServiceUrl+'/generate-question');
res.json(questionResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

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


// 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 gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
10 changes: 10 additions & 0 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Gateway Service', () => {
axios.get.mockImplementation((url) => {
if (url.endsWith('/generate-question')) {
return Promise.resolve({ data: { question: 'mockedQuestion' } });
}else if (url.endsWith('/questions')) {
return Promise.resolve({ data: { question: 'mockedQuestion' } });
}
});

Expand Down Expand Up @@ -51,4 +53,12 @@ describe('Gateway Service', () => {
expect(response.body.question).toBe('mockedQuestion');

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

expect(response.statusCode).toBe(200);
expect(response.body.question).toBe('mockedQuestion');
});
});
Loading

0 comments on commit e6a7f33

Please sign in to comment.