diff --git a/app.js b/app.js index 3bfacf5..9ece057 100644 --- a/app.js +++ b/app.js @@ -18,7 +18,8 @@ db.on('error', console.error.bind(console, 'MongoDB connection error:')); var oldRouter = require('./routes/main/1_0'); var newRouter = require('./routes/main/2_0'); var photosRouter = require('./routes/photoRouter'); -var movieRouter = require('./routes/movieRouter'); +var movieRouter = require('./routes/movies/movieRouter'); +var movieShowRouter = require('./routes/movies/movieShow'); var app = express(); @@ -59,6 +60,7 @@ app.use('/', newRouter); app.use('/old', oldRouter); app.use('/api/photos', photosRouter); app.use('/api/movies', movieRouter); +app.use('/movies', movieShowRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/controllers/movieController.js b/controllers/movieController.js index 145508f..bf56893 100644 --- a/controllers/movieController.js +++ b/controllers/movieController.js @@ -13,10 +13,7 @@ module.exports = { list: function (req, res) { MovieModel.find() .then(movies => { - var data = { - movies: movies - }; - return res.json(data); + return res.json(movies); }) .catch(err => { return res.status(500).json({ @@ -26,30 +23,6 @@ module.exports = { }); }, - /** - * movieController.show() - */ - show: function (req, res) { - var id = req.params.id; - - MovieModel.findOne({_id: id}, function (err, movie) { - if (err) { - return res.status(500).json({ - message: 'Error when getting movie.', - error: err - }); - } - - if (!movie) { - return res.status(404).json({ - message: 'No such movie' - }); - } - - return res.json(movie); - }); - }, - /** * movieController.create() */ diff --git a/public/p_movies/script.js b/public/p_movies/script.js new file mode 100644 index 0000000..192bc9d --- /dev/null +++ b/public/p_movies/script.js @@ -0,0 +1,39 @@ +$(document).ready(async function() { + await loadmovie(); +}); + +async function loadmovie() { + await $.get("/api/movies", rendermovie); +} + +function rendermovie(movies) { + + movies.sort(function(a, b) { + return a.title.localeCompare(b.title); + }); + + // movies.sort(function(a, b) { + // aJ = Date.parse(a.released); + // bJ = Date.parse(b.released); + // return bJ - aJ; + // }); + + + movies.forEach(function(movie) { + + var row = document.createElement("div"); + row.className = "col"; + + row.innerHTML = "
"+ + "" + + "
" + + "
"+ movie.title + "
" + + "

"+ movie.released + "

" + + // "

"+ movie.genre + "

" + + "
" + + "
"; + + + $("#movie_tbody").append(row); + }); +} \ No newline at end of file diff --git a/routes/movieRouter.js b/routes/movies/movieRouter.js similarity index 66% rename from routes/movieRouter.js rename to routes/movies/movieRouter.js index 4ce828d..c7d3892 100644 --- a/routes/movieRouter.js +++ b/routes/movies/movieRouter.js @@ -3,12 +3,11 @@ var express = require('express'); var router = express.Router(); -var movieController = require('../controllers/movieController.js'); +var movieController = require('../../controllers/movieController.js'); router.get('/', movieController.list); //router.get('/publish', movieController.publish); -//router.get('/:id', movieController.show); router.post('/', movieController.create); diff --git a/routes/movies/movieShow.js b/routes/movies/movieShow.js new file mode 100644 index 0000000..8548d67 --- /dev/null +++ b/routes/movies/movieShow.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('movies/show'); +}); + +module.exports = router; \ No newline at end of file diff --git a/views/error.hbs b/views/error.hbs index 9fc4e88..9e2882d 100644 --- a/views/error.hbs +++ b/views/error.hbs @@ -1,16 +1,13 @@ - + Document - + + +

{{message}}

diff --git a/views/main/1_0.hbs b/views/main/1_0.hbs index 7ba5b25..5255e63 100644 --- a/views/main/1_0.hbs +++ b/views/main/1_0.hbs @@ -19,6 +19,9 @@ + + +

Hi, I am Nikola Petrov diff --git a/views/movies/show.hbs b/views/movies/show.hbs new file mode 100644 index 0000000..f1c89dd --- /dev/null +++ b/views/movies/show.hbs @@ -0,0 +1,24 @@ + + + + + + Movies + + + + + + + + +
+
+
+ +
+
+
+ + +