Skip to content

Commit

Permalink
basic stat-service added
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Nov 16, 2024
1 parent 6a9ac6b commit f634ff3
Show file tree
Hide file tree
Showing 12 changed files with 11,381 additions and 4 deletions.
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb

statservice:
container_name: statservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_7/statservice:latest
profiles: ['dev', 'prod']
build: ./statservice
depends_on:
- mongodb
ports:
- '8004:8004'
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/statdb

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_7/gatewayservice:latest
Expand All @@ -63,6 +77,7 @@ services:
- userservice
- authservice
- questionservice
- statservice
ports:
- '8000:8000'
networks:
Expand All @@ -71,6 +86,7 @@ services:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
QUESTION_SERVICE_URL: http://questionservice:8003
STAT_SERVICE_URL: http://statservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
Expand Down
35 changes: 33 additions & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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 statServiceUrl = process.env.STAT_SERVICE_URL || 'http://localhost:8004';

app.use(cors());
app.use(express.json());
Expand Down Expand Up @@ -68,7 +69,7 @@ app.get('/users', async (req, res) => {

app.post('/addquestion', async (req, res) => {
try {
// Forward the add question request to the question generation service
// Forward the add question request to the question service
const addQuestionResponse = await axios.post(
questionServiceUrl + '/addquestion',
req.body
Expand Down Expand Up @@ -98,7 +99,7 @@ app.get('/questions', async (req, res) => {

app.get('/game-questions', async (req, res) => {
try {
// Forward the get question request to the question asking service
// Forward the get question request to the question service
const getQuestionResponse = await axios.get(
questionServiceUrl + '/game-questions',
req.body
Expand All @@ -111,6 +112,36 @@ app.get('/game-questions', async (req, res) => {
}
});

app.post('/addstat', async (req, res) => {
try {
// Forward the add stat request to the stat service
const addStatResponse = await axios.post(
statServiceUrl + '/addstat',
req.body
);
res.json(addStatResponse.data);
} catch (error) {
res
.status(error.response.status)
.json({ error: error.response.data.error });
}
});

app.get('/stats', async (req, res) => {
try {
// Forward the get stats request to the stat service
const getStatsResponse = await axios.get(
statServiceUrl + '/stats',
req.body
);
res.json(getStatsResponse.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)) {
Expand Down
Loading

0 comments on commit f634ff3

Please sign in to comment.