Skip to content

Commit

Permalink
clase31
Browse files Browse the repository at this point in the history
  • Loading branch information
andreybejarano committed Sep 2, 2022
1 parent 3cb683f commit df080ef
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
19 changes: 19 additions & 0 deletions clase31/src/controllers/genresController.js
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions clase31/src/controllers/moviesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions clase31/src/routes/genresRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions clase31/src/routes/moviesRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit df080ef

Please sign in to comment.