Skip to content
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
7 changes: 5 additions & 2 deletions db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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 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;
68 changes: 66 additions & 2 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -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%;
}
33 changes: 31 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -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;
185 changes: 101 additions & 84 deletions seeds/movies.seed.js
Original file line number Diff line number Diff line change
@@ -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
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();
});
22 changes: 22 additions & 0 deletions views/details.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="movie-details">
<img src={{movie.image}} alt={{movie.title}} />
<div class="movie-about">
<a href="/movies">Go back</a>
<h1>{{movie.title}}</h1>
<h2>Director: {{movie.director}}</h2>
<h3>Stars</h3>
<ul>
{{#each movie.stars}}
<li>{{this}}</li>
{{/each}}
</ul>
<p>{{movie.description}}</p>
<div>
{{#each movie.showtimes}}
<span>{{this}} | </span>
{{/each}}
</div>

</div>

</div>
9 changes: 7 additions & 2 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<h1>{{title}}</h1>
<p>Welcome to {{title}}</p>
{{!-- <h1>{{title}}</h1>
<p>Welcome to {{title}}</p> --}}

<div class="homepage">
<div class="homecontent"><h1>Cinema</h1><h1>Root Learn</h1>
<a href="/movies"><button>CHECK MOVIES</button></a></div>
</div>
Loading