Skip to content

Commit

Permalink
Merge pull request #91 from Arquisoft/laura
Browse files Browse the repository at this point in the history
Creación microservicio historial de preguntas y respuesta correcta
  • Loading branch information
uo277310 authored Mar 2, 2024
2 parents afa8841 + 0ce4033 commit a774ec2
Show file tree
Hide file tree
Showing 6 changed files with 5,625 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ services:
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb

generatedquestservice:
container_name: generatedquestservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6b/generatedquestservice:latest
profiles: ["dev", "prod"]
build: ./questions/generatedquestservice
depends_on:
- mongodb
ports:
- "8007:8007"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/questiondb

gatewayservice:
container_name: gatewayservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6b/gatewayservice:latest
Expand Down
20 changes: 20 additions & 0 deletions questions/generatedquestservice/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/generatedquestservice

# 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 8007

# Define the command to run your app
CMD ["node", "generatedquest-service.js"]
17 changes: 17 additions & 0 deletions questions/generatedquestservice/generatedquest-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const mongoose = require('mongoose');

const generatedQuest = new mongoose.Schema({

generatedQuestionBody: {
type: String,
required: true,
},
correctAnswer: {
type: String,
required: true,
},
});

const GeneratedQuestion = mongoose.model('GeneratedQuestion', generatedQuest);

module.exports = GeneratedQuestion
55 changes: 55 additions & 0 deletions questions/generatedquestservice/generatedquest-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const GeneratedQuestion = require('./generatedquest-model');

const app = express();
const port = 8007;

// Middleware to parse JSON in request body
app.use(bodyParser.json());

// Connect to MongoDB
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/questiondb';
mongoose.connect(mongoUri);


// Route for user login
app.post('/addGeneratedQuestion', async (req, res) => {
try {
const newQuestion = new GeneratedQuestion({
generatedQuestionBody: req.body.generatedQuestionBody,
correctAnswer: req.body.correctAnswer,
});
newQuestion.save();
res.json(newQuestion);

} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
});

//obtencion de todas las preguntas genradas y su respuesta correcta
app.get('/getAllGeneratedQuestions', async (req, res) => {
try {
const allQuestions = await GeneratedQuestion.find();

res.json(allQuestions);

} catch (error) {
res.status(500).json({ error: 'Internal Server Error' });
}
});

// Start the server
const server = app.listen(port, () => {
console.log(`Auth Service listening at http://localhost:${port}`);
});

server.on('close', () => {
// Close the Mongoose connection
mongoose.connection.close();
});

module.exports = server

Loading

0 comments on commit a774ec2

Please sign in to comment.