Skip to content

Commit

Permalink
Initial Travis config, Fixed delete handler
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbaptista committed Jun 21, 2017
1 parent 46143f0 commit a030944
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:6.9-slim
MAINTAINER Roy Meissner <meissner@informatik.uni-leipzig.de>
MAINTAINER Paul Baptista <pbaptist@uni-bonn.de>

RUN mkdir /nodeApp
WORKDIR /nodeApp
Expand Down
32 changes: 16 additions & 16 deletions application/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ let host = 'localhost';
//read mongo URL from /etc/hosts
const fs = require('fs');
try {
const lines = fs.readFileSync('/etc/hosts').toString().split('\n');
lines.filter((line) => line.includes('mongodb')).forEach((line) => {
const entries = line.split(' ');
host = entries[entries.length - 1];
console.log('Using ' + host + ' as database host.');
});
const lines = fs.readFileSync('/etc/hosts').toString().split('\n');
lines.filter((line) => line.includes('mongodb')).forEach((line) => {
const entries = line.split(' ');
host = entries[entries.length - 1];
console.log('Using ' + host + ' as database host.');
});
} catch (e) {
console.log('Exception: Windows or no read rights to read /etc/hosts (bad)');
console.log('Exception: Windows or no read rights to read /etc/hosts (bad)');
}
//read mongo URL from ENV
host = (!co.isEmpty(process.env.DATABASE_URL)) ? process.env.DATABASE_URL : host;
if(host !== 'localhost')
console.log('Using ' + host + ' as database host.');
console.log('Using ' + host + ' as database host.');

let port = 27017;
//read mongo port from ENV
if (!co.isEmpty(process.env.DATABASE_PORT)){
port = process.env.DATABASE_PORT;
console.log('Using ' + port + ' as database port.');
port = process.env.DATABASE_PORT;
console.log('Using ' + port + ' as database port.');
}

module.exports = {
MongoDB: {
PORT: port,
HOST: host,
NS: 'local',
SLIDEWIKIDATABASE: 'slidewiki'
}
MongoDB: {
PORT: port,
HOST: host,
NS: 'local',
SLIDEWIKIDATABASE: 'slidewiki'
}
};
29 changes: 29 additions & 0 deletions application/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ module.exports = {
});
},

//Get a question from database or return NOT FOUND
getRelatedQuestions: function(request, reply) {
questionDB.getAllRelated(request.params.related_object,
request.params.related_object_id
).then((questions) => {
if (co.isEmpty(question))
reply(boom.notFound());
else
reply(co.rewriteID(question));
}).catch((error) => {
request.log('error', error);
reply(boom.badImplementation());
});
},


//Create Question with new id and payload or return INTERNAL_SERVER_ERROR
newQuestion: function(request, reply) {
questionDB.insert(request.payload).then((inserted) => {
Expand Down Expand Up @@ -64,4 +80,17 @@ module.exports = {
});
},

//Create Question with new id and payload or return INTERNAL_SERVER_ERROR
deleteQuestion: function(request, reply) {
questionDB.remove(request.params.id).then((deleted) => {
if (co.isEmpty(deleted))
reply(co.rewriteID(deleted));
else
reply(boom.notFound());
}).catch((error) => {
request.log('error', error);
reply(boom.badImplementation());
});
},

};
17 changes: 17 additions & 0 deletions application/database/questionDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,29 @@ module.exports = {
}));
},

remove: function (identifier) {
return helper.connectToDatabase()
.then((db) => db.collection('questions'))
.then((col) => col.remove({
_id: identifier
}));
},

getAll: function (identifier) {
return helper.connectToDatabase()
.then((db) => db.collection('questions'))
.then((col) => col.find());
},

getAllRelated: function (relObject, relObjectId) {
return helper.connectToDatabase()
.then((db) => db.collection('questions'))
.then((col) => col.find({
related_object: relObject,
related_object_id: objectId
}));
},

insert: function (question) {
//TODO check for root and parent deck ids to be existent, otherwise create these
return helper.connectToDatabase()
Expand Down
6 changes: 3 additions & 3 deletions application/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ module.exports = function(server) {
//Get all questions of Deck or Slide with its id and return it (...).
server.route({
method: 'GET',
path: '/{related_object}/deck/{id}/questions',
handler: handlers.getDeckQuestions,
path: '/{related_object}/{related_object_id}/questions',
handler: handlers.getRelatedQuestions,
config: {
validate: {
params: {
id: Joi.string().alphanum().lowercase()
related_object: Joi.string().valid(['slide','deck']),
related_object_id: Joi.string().alphanum(),
}
},
tags: ['api'],
Expand Down
21 changes: 6 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
template:
image: slidewiki/microservicetemplate
questionservice:
image: slidewiki/questionservice:latest-dev
restart: on-failure:5
expose:
- "80"
Expand All @@ -9,16 +9,7 @@ template:
- APPLICATION_PORT=80
- DATABASE_PORT=27017
- DATABASE_URL=mongodb # use a url or the name, defined in the docker-compose file
- VIRTUAL_HOST=microservicetemplate.experimental.slidewiki.org
- LETSENCRYPT_HOST=microservicetemplate.experimental.slidewiki.org
- [email protected]
- SERVICE_URL_DECK=http://deckservice.experimental.slidewiki.org
- SERVICE_URL_DISCUSSION=http://discussionservice.experimental.slidewiki.org
- SERVICE_URL_ACTIVITIES=http://activitiesservice.experimental.slidewiki.org
- SERVICE_URL_NOTIFICATION=http://notificationservice.experimental.slidewiki.org
- SERVICE_URL_USER=http://userservice.experimental.slidewiki.org
- SERVICE_URL_SEARCH=http://searchservice.experimental.slidewiki.org
- SERVICE_URL_IMAGE=http://imageservice.experimental.slidewiki.org
- SERVICE_URL_FILE=http://fileservice.experimental.slidewiki.org
- SERVICE_URL_PDF=http://pdfservice.experimental.slidewiki.org
- SERVICE_URL_IMPORT=http://importservice.experimental.slidewiki.org
- VIRTUAL_HOST=questionservice.experimental.slidewiki.org
- LETSENCRYPT_HOST=questionservice.experimental.slidewiki.org
- [email protected]
- LETSENCRYPT_TEST=true
2 changes: 1 addition & 1 deletion mongodb/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mongo:latest
FROM mongo:3.4
MAINTAINER Kurt Junghanns <[email protected]>

# ---------------- #
Expand Down
4 changes: 2 additions & 2 deletions travis_scripts/dockerhub.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker build -t slidewiki/microservicetemplate ./
docker push slidewiki/microservicetemplate
docker build -t slidewiki/questionservice:latest-dev .
docker push slidewiki/questionservice:latest-dev

0 comments on commit a030944

Please sign in to comment.