Skip to content

Commit

Permalink
Merge pull request #50 from Arquisoft/storeQuestionService
Browse files Browse the repository at this point in the history
Store question service implemented
AbelMH1 authored Mar 13, 2024
2 parents 93e709b + 1ae5550 commit 998a6ee
Showing 12 changed files with 5,629 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ services:
environment:
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
STORE_QUESTION_SERVICE_URL: http://storequestionservice:8004

webapp:
container_name: webapp-${teamname:-defaultASW}
@@ -99,6 +100,20 @@ services:
depends_on:
- prometheus

storequestionservice:
container_name: storequestion-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6c/storequestionservice:latest
profiles: ["dev", "prod"]
build: ./storequestionservice
depends_on:
- mongodb
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/storedquestion


volumes:
mongodb_data:
19 changes: 19 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,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 storeQuestionsServiceUrl = process.env.STORE_QUESTION_SERVICE_URL || 'http://localhost:8004'

app.use(cors());
app.use(express.json());
@@ -41,6 +42,24 @@ app.post('/adduser', async (req, res) => {
}
});

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

app.get('/history/questions', async (req, res) => {
try {
const response = await axios.get(storeQuestionsServiceUrl+'/history/questions');
res.json(response.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}`);
2 changes: 2 additions & 0 deletions storeQuestionService/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
20 changes: 20 additions & 0 deletions storeQuestionService/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/storequestionservice

# 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", "store-q-service.js"]
Loading

0 comments on commit 998a6ee

Please sign in to comment.