Site.getAll created, basic Index generating

This commit is contained in:
Sean Clarke 2020-01-05 16:10:46 -05:00
parent 2ee5504efc
commit 78ae7f3a03
5 changed files with 28 additions and 3 deletions

View File

@ -11,5 +11,11 @@ module.exports = {
res.render('site', { title: site.site, site: site });
}
});
},
getAll: function(req, res){
Site.getAll(function(err, sites){
if(err) throw err;
res.render('index', { title: "Home", sites: sites });
});
}
}

View File

@ -30,4 +30,15 @@ Site.findById = function(id, callback){
});
};
// get a listing of all sites
Site.getAll = function(callback){
var sql = "SELECT * FROM sites";
con.query(sql, function(err, result){
if (err) return callback(err);
console.log("Site.getAll retrieved: " + result.length + "records.");
callback(err, result);
});
}
module.exports = Site;

View File

@ -1,9 +1,13 @@
var express = require('express');
var router = express.Router();
var sitesController = require('../controllers/sites')
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'UNESCO Tracker - Sean Clarke' });
});
// router.get('/', function(req, res, next) {
// res.render('index', { title: 'UNESCO Tracker - Sean Clarke' });
// });
router.get('/', sitesController.getAll);
module.exports = router;

View File

@ -3,5 +3,8 @@ extends layout
block content
h1= title
p Welcome to #{title}
each site in sites
h3= site.site
include footer.pug

View File

@ -2,6 +2,7 @@ extends layout
block content
h1= site.site
img(src= site.img_url alt= site.site)
h3= "Date Inscribed: " + site.date_inscribed
h4= "Located: " + site.latitude + " " + site.longitude