forked from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from Arquisoft/laura
Creación microservicio historial de preguntas y respuesta correcta
- Loading branch information
Showing
6 changed files
with
5,625 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.