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 #20 from Arquisoft/laura
Creacion añadido de respuestas
- Loading branch information
Showing
8 changed files
with
5,619 additions
and
1 deletion.
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/answerservice | ||
|
||
# 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", "answer-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,18 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const answerSchema = new mongoose.Schema({ | ||
|
||
answerBody: { | ||
type: String, | ||
required: true, | ||
}, | ||
typeAnswer: { | ||
type: String, | ||
required: true, | ||
},//para filtrar por el tipo de pregunta | ||
//autor, year etc... | ||
}); | ||
|
||
const Answer = mongoose.model('Answer', answerSchema); | ||
|
||
module.exports = Answer |
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,44 @@ | ||
const express = require('express'); | ||
const mongoose = require('mongoose'); | ||
const bodyParser = require('body-parser'); | ||
const Question = require('./answer-model'); | ||
const Answer = require('./answer-model'); | ||
|
||
const app = express(); | ||
const port = 8004; | ||
|
||
// 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('/addAnswer', async (req, res) => { | ||
try { | ||
const newAnswer1 = new Answer({ | ||
answerBody: req.body.answerBody, | ||
typeAnswer: req.body.typeAnswer, | ||
}); | ||
newAnswer1.save(); | ||
res.json(newAnswer1); | ||
|
||
} 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.