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

add events get route and fetching from the database #5

Merged
merged 1 commit into from
Mar 3, 2018
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
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var cors = require('cors')
var db = require('./model/db');



// route imports
var index = require('./routes/index');
var events = require('./routes/events');

<<<<<<< HEAD



=======
>>>>>>> add events route and fetching from the database
// TODO: add your route file here:
var events = require('./routes/events');

Expand Down
5 changes: 0 additions & 5 deletions data/myevents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ title: "Test3",
subtitle: "This is a subtitle",
date: "17/Dec/2017 12:00",
location: "Athens, Greece",
shortdescription: "Hello421",
organizer: "IEEE ATEITH SB",
image:image,
description: "Greatly hearted has who believe. Drift allow green son walls"+
Expand All @@ -24,7 +23,6 @@ title: "Test4",
subtitle: "",
date: "22/Dec/2017 13:00",
location: "Athens, Greece",
shortdescription: "Hello235",
organizer: "IEEE ATEITH SB",
image:"./img/ReactJS.png",
description: "Greatly hearted has who believe. Drift allow green son walls"+
Expand All @@ -43,7 +41,6 @@ title: "Test5",
subtitle: "This is a subtitle",
date: "29/Dec/2017 14:30",
location: "Athens, Greece",
shortdescription: "Hello63278",
organizer: "IEEE ATEITH SB",
image:"./img/ReactJS.png",
description: "Greatly hearted has who believe. Drift allow green son walls"+
Expand All @@ -62,7 +59,6 @@ title: "Test1",
subtitle: "This is a subtitle",
date: "10/Dec/2016 15:00",
location: "Thessaloniki, Greece",
shortdescription: "Hello",
organizer: "IEEE ATEITH SB",
image:"./img/ReactJS.png",
description: "Greatly hearted has who believe. Drift allow green son walls"+
Expand All @@ -81,7 +77,6 @@ title: "Test2",
subtitle: "This is a subtitle",
date: "15/Dec/2016 16:00",
location: "Athens, Greece",
shortdescription: "Hello3",
organizer: "IEEE ATEITH SB",
image:"./img/ReactJS.png",
description: "Greatly hearted has who believe. Drift allow green son walls"+
Expand Down
15 changes: 15 additions & 0 deletions model/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var mongoose = require('mongoose')

var user = encodeURIComponent('branch_webpage');
var passwd = encodeURIComponent('passwd');
var authMechanism = 'DEFAULT';

var url = `mongodb://${user}:${passwd}@cluster0-shard-00-00-vyvir.mongodb.net:27017,cluster0-shard-00-01-vyvir.mongodb.net:27017,cluster0-shard-00-02-vyvir.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin`;
mongoose.connect(url);

var connection = mongoose.connection;
connection.on('error', console.error.bind(console, 'connection error:'));
connection.once('open', function() {
console.log("Connected to the database");
console.log(`using ${user} and ${passwd}`);
});
13 changes: 13 additions & 0 deletions model/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var mongoose = require('mongoose');

const eventSchema = new mongoose.Schema({
title: {type: String, default: 'empty_title', trim: true},
body: {type: String, default: 'empty_body', trim: true}
});

var EventData = mongoose.model('Event', eventSchema);

var exports = module.exports = {
mongoose,
EventData
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"debug": "~2.6.9",
"ejs": "~2.5.7",
"express": "~4.15.5",
"mongoose": "^5.0.7",
"morgan": "~1.9.0",
"serve-favicon": "~2.4.5"
}
Expand Down
Binary file added public/images/expressjs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions routes/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var eventsData = require('./../data/myevents');

var express = require('express');
var router = express.Router();

var EventModel = require('./../model/event.js');
var EventData = EventModel.EventData;


/* GET home page. */
router.get('/', function(req, res, next) {
console.log("this is a line");
const empty = {empty: "error"}

EventData.find((err, lalas)=>{
if (err) return console.error(err);
res.setHeader('Content-Type', 'application/json');
res.send(lalas);
})
//res.send(empty);
});

module.exports = router;
3 changes: 3 additions & 0 deletions views/error.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>