Skip to content

Commit

Permalink
Merge pull request #132 from Arquisoft/service_question_generator
Browse files Browse the repository at this point in the history
Service question generator
  • Loading branch information
alegarman2002 authored Apr 29, 2024
2 parents 6205aba + 38288c2 commit 4d733eb
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 220 deletions.
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ services:
container_name: questiongeneratorservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6c/questiongeneratorservice:latest
profiles: ["dev", "prod"]
build: ./questionsservice/questiongeneratorservice
build:
context: ./questionsservice
dockerfile: ./questiongeneratorservice/Dockerfile
depends_on:
- mongodb_wiki
- storequestionservice
Expand All @@ -100,6 +102,7 @@ services:
networks:
- mynetwork
environment:
DATAMODELS_URI: './questiondata-model'
MONGODB_URI: mongodb://mongodb_wiki:27017/questions
STORE_QUESTION_SERVICE_URL: http://storequestionservice:8004
restart: always
Expand All @@ -108,14 +111,17 @@ services:
container_name: wikidataextractorservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es6c/wikidataextractorservice:latest
profiles: ["dev", "prod"]
build: ./questionsservice/wikidataExtractor
build:
context: ./questionsservice
dockerfile: ./wikidataExtractor/Dockerfile
depends_on:
- mongodb_wiki
ports:
- "8008:8008"
networks:
- mynetwork
environment:
DATAMODELS_URI: './questiondata-model'
MONGODB_URI: mongodb://mongodb_wiki:27017/questions
restart: always

Expand Down
82 changes: 82 additions & 0 deletions questionsservice/questiondata-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const mongoose = require('mongoose');

const paisSchema = new mongoose.Schema({
pais: {
type: String,
required: true
},
capital: {
type: String,
required: false
},
continente: {
type: String,
required: false
},
lenguaje: {
type: String,
required: false
},
bandera: {
type: String,
required: false
}
}, { timestamps: {} }); // Añade y gestiona automáticamente los campos createdAt y updatedAt

const monumentSchema = new mongoose.Schema({
monumento: {
type: String,
required: true
},
pais: {
type: String,
required: false
}
}, {timestamps: {}});

const chemicalElementsSchema = new mongoose.Schema({
elemento: {
type: String,
required: true
},
simbolo: {
type: String,
required: false
}
}, {timestamps: {}});

const filmSchema = new mongoose.Schema({
pelicula: {
type: String,
required: true
},
director: {
type: String,
required: false
}
}, {timestamps: {}});

const songSchema = new mongoose.Schema({
cancion: {
type: String,
required: true
},
artista: {
type: String,
required: false
}
}, {timestamps: {}});

const Pais = mongoose.model('Pais', paisSchema);
const Monumento = mongoose.model('Monumento', monumentSchema);
const Elemento = mongoose.model('Elemento', chemicalElementsSchema);
const Pelicula = mongoose.model('Pelicula', filmSchema);
const Cancion = mongoose.model('Cancion', songSchema);

module.exports = {
Pais,
Monumento,
Elemento,
Pelicula,
Cancion
};
5 changes: 3 additions & 2 deletions questionsservice/questiongeneratorservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ FROM node:20
WORKDIR /usr/src/questionsservice/questiongeneratorservice

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./
COPY ./questiongeneratorservice/package*.json ./

# Install app dependencies
RUN npm install

# Copy the app source code to the working directory
COPY . .
COPY ./questiongeneratorservice/ .
COPY questiondata-model.js .

# Expose the port the app runs on
EXPOSE 8007
Expand Down
64 changes: 32 additions & 32 deletions questionsservice/questiongeneratorservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ app.get('/questions', async (req, res) => {
}
} catch (error) {
console.error(`Bad Request: ${error.message}`);
res.status(400).json({ message: error.message });
res.status(400).json({ error: error.message });
}
});

// Route for getting topics for questions
app.get('/topics', async (req, res) => {
try {
const topics = QuestionGenerator.getAvailableTopics();
res.send(topics);
} catch (error) {
console.error(`An error occurred: ${error.message}`);
res.status(500).json({ error: 'Internal Server Error' });
}
});

Expand Down
Loading

0 comments on commit 4d733eb

Please sign in to comment.