Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creacion añadido de respuestas #20

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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