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

Stats fixed #40

Merged
merged 11 commits into from
Mar 4, 2024
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix webapp ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
- run: npm --prefix users/userservice install
- run: npm --prefix gatewayservice install
- run: npm --prefix questionservice install
- run: npm --prefix statsservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
Expand Down
19 changes: 18 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

statsservice:
container_name: statsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/statsservice:latest
profiles: ["dev", "prod"]
build: ./statsservice
depends_on:
- mongodb
- userservice
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
USER_SERVICE_URL: http://userservice:8001

authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/authservice:latest
Expand Down Expand Up @@ -74,12 +90,13 @@ services:
- userservice
- authservice
- questionservice
- statsservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
STATS_SERVICE_URL: http://questionservice:8004
STATS_SERVICE_URL: http://statsservice:8004
QUESTION_SERVICE_URL: http://questionservice:8003
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
Expand Down
41 changes: 41 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 statsServiceUrl = process.env.AUTH_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -52,6 +53,46 @@ app.get('/questions', async (req, res) => {
}
});

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

app.post('/saveGame', async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(statsServiceUrl+'/saveGame', req.body);
res.json(gameResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

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

app.post('/userSaveGame', async (req, res) => {
try {
// Forward the save game request to the stats service
const gameResponse = await axios.post(userServiceUrl+'/userSaveGame', req.body);
res.json(gameResponse.data);
} catch (error) {
res.status(error.response.status).json({ error: error.response.data.error });
}
});

// Start the gateway service
const server = app.listen(port, () => {
console.log(`Gateway Service listening at http://localhost:${port}`);
Expand Down
143 changes: 143 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"axios": "^1.6.7",
"cors": "^2.8.5",
"cron": "^3.1.6",
"cross-fetch": "^4.0.0",
"date-fns": "^3.3.1",
"react-auth-kit": "^3.0.2-alpha.19"
Expand Down
Loading
Loading