From df080efcb3cec56ffd937468d9303d2ce9a85da6 Mon Sep 17 00:00:00 2001 From: Andrey Bejarano Date: Thu, 1 Sep 2022 21:03:28 -0300 Subject: [PATCH] clase31 --- clase31/src/controllers/genresController.js | 19 +++++++++++++ clase31/src/controllers/moviesController.js | 30 +++++++++++++++++++++ clase31/src/routes/genresRoutes.js | 4 +-- clase31/src/routes/moviesRoutes.js | 6 ++--- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/clase31/src/controllers/genresController.js b/clase31/src/controllers/genresController.js index e69de29..0363411 100644 --- a/clase31/src/controllers/genresController.js +++ b/clase31/src/controllers/genresController.js @@ -0,0 +1,19 @@ +const db = require('../database/models'); + +const genresController = { + list: (req, res) => { + db.Genre.findAll() + .then(genres => { + res.render('genresList.ejs', { genres }) + }) + }, + detail: (req, res) => { + db.Genre.findByPk(req.params.id) + .then(genre => { + res.render('genresDetail.ejs', { genre }); + }); + } + +} + +module.exports = genresController; \ No newline at end of file diff --git a/clase31/src/controllers/moviesController.js b/clase31/src/controllers/moviesController.js index 38229e5..c41d940 100644 --- a/clase31/src/controllers/moviesController.js +++ b/clase31/src/controllers/moviesController.js @@ -9,6 +9,36 @@ const moviesController = { .catch(err => { res.send(err); }) + }, + detail: (req, res) => { + db.Movie.findByPk(req.params.id) + .then(movie => { + res.render('moviesDetail.ejs', { movie }); + }); + }, + new: (req, res) => { + db.Movie.findAll({ + order: [ + ['release_date', 'DESC'] + ], + limit: 5 + }) + .then(movies => { + res.render('newestMovies', { movies }); + }); + }, + recomended: (req, res) => { + db.Movie.findAll({ + where: { + rating: { [db.Sequelize.Op.gte]: 8 } + }, + order: [ + ['rating', 'DESC'] + ] + }) + .then(movies => { + res.render('recommendedMovies.ejs', { movies }); + }); } } diff --git a/clase31/src/routes/genresRoutes.js b/clase31/src/routes/genresRoutes.js index f158755..c3d5ca0 100644 --- a/clase31/src/routes/genresRoutes.js +++ b/clase31/src/routes/genresRoutes.js @@ -2,8 +2,8 @@ const express = require('express'); const router = express.Router(); const genresController = require('../controllers/genresController'); -//router.get('/genres', genresController.list); -//router.get('/genres/detail/:id', genresController.detail); +router.get('/genres', genresController.list); +router.get('/genres/detail/:id', genresController.detail); module.exports = router; \ No newline at end of file diff --git a/clase31/src/routes/moviesRoutes.js b/clase31/src/routes/moviesRoutes.js index 708abd2..cb8c1f5 100644 --- a/clase31/src/routes/moviesRoutes.js +++ b/clase31/src/routes/moviesRoutes.js @@ -3,9 +3,9 @@ const router = express.Router(); const moviesController = require('../controllers/moviesController'); router.get('/movies', moviesController.list); -//router.get('/movies/new', moviesController.new); -//router.get('/movies/recommended', moviesController.recomended); -//router.get('/movies/detail/:id', moviesController.detail); +router.get('/movies/new', moviesController.new); +router.get('/movies/recommended', moviesController.recomended); +router.get('/movies/detail/:id', moviesController.detail); module.exports = router; \ No newline at end of file