Skip to content

Commit

Permalink
Merge pull request #20 from Arquisoft/laura
Browse files Browse the repository at this point in the history
Creacion añadido de respuestas
  • Loading branch information
uo283055 authored Feb 11, 2024
2 parents 4cf2d46 + 43153ad commit 846331e
Show file tree
Hide file tree
Showing 8 changed files with 5,619 additions and 1 deletion.
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ services:
MONGODB_URI: mongodb://mongodb:27017/questiondb


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


authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6b/authservice:latest
Expand Down
20 changes: 20 additions & 0 deletions questions/answerservice/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/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"]
18 changes: 18 additions & 0 deletions questions/answerservice/answer-model.js
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
44 changes: 44 additions & 0 deletions questions/answerservice/answer-service.js
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

Loading

0 comments on commit 846331e

Please sign in to comment.