diff --git a/db/index.js b/db/index.js index c8cf065..85d5793 100644 --- a/db/index.js +++ b/db/index.js @@ -5,12 +5,15 @@ const mongoose = require("mongoose"); // ℹ️ 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 -const MONGO_URI = process.env.MONGODB_URI || "mongodb://localhost/lab-express-cinema"; +const MONGO_URI = + process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/lab-express-cinema"; mongoose .connect(MONGO_URI) .then((x) => { - console.log(`Connected to Mongo! Database name: "${x.connections[0].name}"`); + console.log( + `Connected to Mongo! Database name: "${x.connections[0].name}"` + ); }) .catch((err) => { console.error("Error connecting to mongo: ", err); diff --git a/models/Movie.model.js b/models/Movie.model.js new file mode 100644 index 0000000..4925cdf --- /dev/null +++ b/models/Movie.model.js @@ -0,0 +1,31 @@ +const mongoose = require("mongoose"); + +const movieSchema = new mongoose.Schema({ + title: { + type: String, + required: true, + }, + director: { + type: String, + required: true, + }, + stars: { + type: [String], + required: true, + }, + image: { + type: String, + required: true, + }, + description: { + type: String, + required: true, + }, + showtimes: { + type: [String], + required: true, + }, +}); + +const Movie = mongoose.model("Movie", movieSchema); +module.exports = Movie; diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 9453385..72506a1 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -1,8 +1,72 @@ body { - padding: 50px; + padding: 0px; + margin: 0; font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; } +.homepage { + height: 100%; + background: url("./../images/cinema.jpg"); + background-repeat: no-repeat; + background-size: cover; + font-size: 3.5rem; + display: flex; + flex-direction: column; + justify-content: center; + align-items: end; + color: #fff; +} + a { - color: #00B7FF; + color: #00b7ff; +} + +.homecontent { + position: relative; + right: 200px; + bottom: 50px; +} + +.homecontent h1 { + margin: 0; +} + +.homecontent button { + border-radius: 50px; + font-size: 1.5rem; + font-weight: 700; + padding: 15px 50px; + margin-top: 20px; + background-color: #fff; + cursor: pointer; +} + +.movies-list { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: center; +} + +.movie-card { + display: flex; + flex-direction: column; + align-items: center; + gap: 20px; + font-weight: 700; + margin: 100px; +} + +.movie-details { + display: flex; + flex-direction: row; + gap: 20px; +} + +.movie-details img { + margin: 10px; +} + +.movie-about p { + width: 50%; } diff --git a/routes/index.js b/routes/index.js index 3647403..3d63e92 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,7 +1,36 @@ -const express = require('express'); +const express = require("express"); const router = express.Router(); +const Movie = require("../models/Movie.model"); + /* GET home page */ -router.get('/', (req, res, next) => res.render('index')); +router.get("/", (req, res, next) => res.render("index")); + +// GET movies page +router.get("/movies", (req, res, next) => { + Movie.find() + .then((allTheMovieFromDB) => { + console.log("Retrieved movies from DB:", allTheMovieFromDB); + res.render("movies", { movies: allTheMovieFromDB }); + }) + .catch((error) => { + console.log("Error while getting the movies from the DB: ", error); + + next(error); + }); +}); + +//GET movie details page +router.get("/movies/:movieId", (req, res, next) => { + const { movieId } = req.params; + + Movie.findById(movieId) + .then((theMovie) => res.render("details", { movie: theMovie })) + .catch((error) => { + console.log("Error while retrieving book details: ", error); + + next(error); + }); +}); module.exports = router; diff --git a/seeds/movies.seed.js b/seeds/movies.seed.js index 39e1359..277b2ef 100644 --- a/seeds/movies.seed.js +++ b/seeds/movies.seed.js @@ -1,89 +1,106 @@ 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"] - } - ]; - + { + 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"], + }, +]; // Add here the script that will be run to actually seed the database (feel free to refer to the previous lesson) - +// ... your code here +const mongoose = require("mongoose"); +const Movie = require("./../models/Movie.model"); +const MONGO_URI = + process.env.MONGODB_URI || "mongodb://127.0.0.1:27017/lab-express-cinema"; -// ... your code here \ No newline at end of file +mongoose + .connect(MONGO_URI) + .then((x) => { + console.log(`Connected to the database: "${x.connection.name}"`); + }) + .then(() => { + Movie.insertMany(movies).then(() => { + console.log("DONE"); + mongoose.connection.close(); + }); + }) + .catch((error) => { + console.error("Error connecting to the database", error); + mongoose.connection.close(); + }); diff --git a/views/details.hbs b/views/details.hbs new file mode 100644 index 0000000..55129dc --- /dev/null +++ b/views/details.hbs @@ -0,0 +1,22 @@ +
{{movie.description}}
+Welcome to {{title}}
+{{!--Welcome to {{title}}
--}} + + \ No newline at end of file diff --git a/views/layout.hbs b/views/layout.hbs index f2c4e0c..66419f9 100644 --- a/views/layout.hbs +++ b/views/layout.hbs @@ -1,16 +1,15 @@ - - - - - -