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

[RMT - PT - 112023] Marta Bravo #1989

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ npm-debug.log

# Environment Variables should NEVER be published
# For learning purposes, we keep .env available for you
# .env
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
26 changes: 23 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('dotenv/config');

// ℹ️ Connects to the database
require('./db');
require('./configs/db.config');

// Handles http requests (express is node js framework)
// https://www.npmjs.com/package/express
Expand All @@ -22,13 +22,33 @@ require('./config')(app);
const projectName = 'lab-express-cinema';
const capitalized = string => string[0].toUpperCase() + string.slice(1).toLowerCase();

app.locals.title = `${capitalized(projectName)}- Generated with Ironlauncher`;
app.set("view engine", "hbs");
app.set("views", `${__dirname}/views`);


app.locals.title = `${capitalized(projectName)}`;


// 👇 Start handling routes here
const index = require('./routes/index');
const index = require('./configs/routes.config');
app.use('/', index);

const logger = require('morgan');

// Application middlewares
app.use(logger("dev"));
app.use(express.urlencoded());
app.use((req, res, next) => {
res.locals.currentPath = req.path;
next();
});

const routes = require ('./configs/routes.config');
app.use('/', routes);

// ❗ To handle errors. Routes that don't exist or errors that you handle in specific routes
require('./error-handling')(app);

module.exports = app;


95 changes: 95 additions & 0 deletions bin/movies.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require('dotenv/config');
require('../configs/db.config');

const Movie = require('../models/movie.model');


const movies = [
{
title: "A Wrinkle in Time",
director: "Ava DuVernay",
stars: ["Storm Reid", "Oprah Winfrey", "Reese Witherspoon"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMjMxNjQ5MTI3MV5BMl5BanBnXkFtZTgwMjQ2MTAyNDM@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"Following the discovery of a new form of space travel as well as Meg's father's disappearance, she, her brother, and her friend must join three magical beings - Mrs. Whatsit, Mrs. Who, and Mrs. Which - to travel across the universe to rescue him from a terrible evil.",
showtimes: ["13:00", "15:30", "18:00", "20:10", "22:40"]
},
{
title: "The Strangers: Prey at Night",
director: "Johannes Roberts",
stars: ["Christina Hendricks", "Bailee Madison", "Martin Henderson"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTY1OTIwODgzMV5BMl5BanBnXkFtZTgwMzUyMDgzNDM@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"A family's road trip takes a dangerous turn when they arrive at a secluded mobile home park to stay with some relatives and find it mysteriously deserted. Under the cover of darkness, three masked psychopaths pay them a visit to test the family's every limit as they struggle to survive.",
showtimes: ["13:50", "16:20", "19:20", "22:10"]
},
{
title: "The Hurricane Heist",
director: "Rob Cohen",
stars: ["Toby Kebbell", "Maggie Grace", "Ryan Kwanten"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMzg3Y2MyNjgtMzk4ZS00OTU3LWEwZmMtN2Y0NTdlZjU0NGFiXkEyXkFqcGdeQXVyMTMxODk2OTU@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"Thieves attempt a massive heist against the U.S. Treasury as a Category 5 hurricane approaches one of its Mint facilities.",
showtimes: ["13:10", "15:40", "18:20", "20:50", "23:10"]
},
{
title: "Gringo",
director: "Nash Edgerton",
stars: ["Joel Edgerton", "Charlize Theron", "David Oyelowo"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMjAyMTk2MTQ3Ml5BMl5BanBnXkFtZTgwNDQ2ODE0NDM@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"GRINGO, a dark comedy mixed with white-knuckle action and dramatic intrigue, explores the battle of survival for businessman Harold Soyinka (David Oyelowo) when he finds himself crossing the line from law-abiding citizen to wanted criminal.",
showtimes: ["13:40", "15:50", "19:00", "21:20", "23:50"]
},
{
title: "Thoroughbreds",
director: "Cory Finley",
stars: ["Anya Taylor-Joy", "Olivia Cooke", "Anton Yelchin"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BNDcyNDA4NDAzN15BMl5BanBnXkFtZTgwODQxMDQ5NDM@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"Two upper-class teenage girls in suburban Connecticut rekindle their unlikely friendship after years of growing apart. Together, they hatch a plan to solve both of their problems-no matter what the cost.",
showtimes: ["13:00", "15:30", "18:00", "20:10", "22:40"]
},
{
title: "The Leisure Seeker",
director: "Paolo Virzì",
stars: ["Helen Mirren", "Donald Sutherland", "Janel Moloney"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTg1NTg2MzcyNF5BMl5BanBnXkFtZTgwNjMwMDIzNDM@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"A runaway couple goes on an unforgettable journey in the faithful old RV they call The Leisure Seeker, traveling from Boston to The Ernest Hemingway Home in Key West. They recapture their passion for life and their love for each other on a road trip that provides revelation and surprise right up to the very end.",
showtimes: ["13:40", "15:50", "19:00", "21:20", "23:50"]
},
{
title: "Black Panther",
director: "Ryan Coogler",
stars: ["Chadwick Boseman", "Michael B. Jordan", "Lupita Nyong'o"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTg1MTY2MjYzNV5BMl5BanBnXkFtZTgwMTc4NTMwNDI@._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"T'Challa, the King of Wakanda, rises to the throne in the isolated, technologically advanced African nation, but his claim is challenged by a vengeful outsider who was a childhood victim of T'Challa's father's mistake.",
showtimes: ["13:50", "16:20", "19:20", "22:10"]
},
{
title: "Red Sparrow",
director: "Francis Lawrence",
stars: ["Jennifer Lawrence", "Joel Edgerton", "Matthias Schoenaerts"],
image:
"https://images-na.ssl-images-amazon.com/images/M/MV5BMTA3MDkxOTc4NDdeQTJeQWpwZ15BbWU4MDAxNzgyNTQz._V1_UX182_CR0,0,182,268_AL_.jpg",
description:
"Ballerina Dominika Egorova is recruited to 'Sparrow School,' a Russian intelligence service where she is forced to use her body as a weapon. Her first mission, targeting a C.I.A. agent, threatens to unravel the security of both nations.",
showtimes: ["13:00", "15:30", "18:00", "20:10", "22:40"]
}
];


Movie.create(movies)
.then((movies) => console.log(`${movies.length} movies created`))
.catch((error) => console.error(error));


2 changes: 2 additions & 0 deletions db/index.js → configs/db.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// https://www.npmjs.com/package/mongoose
const mongoose = require("mongoose");

mongoose.set('strictQuery', false);

// ℹ️ Sets the MongoDB URI for our app to have access to it.
// If no env has been set, we dynamically set it to whatever the folder name was upon the creation of the app

Expand Down
4 changes: 4 additions & 0 deletions routes/index.js → configs/routes.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const express = require('express');
const router = express.Router();
const movies = require('../controllers/movie.controller');

/* GET home page */
router.get('/', (req, res, next) => res.render('index'));
router.get('/movies', movies.list);
router.get('/movies/:id', movies.details);


module.exports = router;
18 changes: 18 additions & 0 deletions controllers/movie.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Movie = require('../models/movie.model');
const mongoose = require('mongoose');

module.exports.list = (req, res, next) => {
Movie.find()
.then((movies) => {
console.log(movies)
res.render('movies/list', {movies})

})
.catch((error) => console.error(error));
}

module.exports.details = (req, res, next) => {
Movie.findById(req.params.id)
.then((movie) => res.render('/movies/details', {movie}))
.catch((error) => console.error(error));
}
31 changes: 31 additions & 0 deletions models/movie.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const movieSchema = new Schema (
{
title: {
type: String,
required: [true, 'Title is required'],
minlength: [2, 'Title needs at least 2 chars']
},
director: {
type: String
},
stars: {
type: [String]
},
image: {
type: String
},
description: {
type: String,
},
showtimes: {
type: [String]
},
},
{timestamps: true}
);

const Movie = mongoose.model('Movie', movieSchema);
module.exports = Movie;
Loading