RomainC75 / lab-express-cinema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo_ironhack_blue 7

LAB | Express Cinema

Introduction

image

The goal of this exercise is to learn how to seed the database on your own and to be able to create a cinema API, which can give users a list of movies. In addition to that, you will create a single movie GET route, which can return all the information for movies.

Requirements

  • Fork this repo
  • Clone this repo

Submission

Upon completion, run the following commands:

$ git add .
$ git commit -m "done"
$ git push origin master
  • Create Pull Request so your TAs can check up your work.

Instructions

Iteration 0 | Initialize the project

This lab has the starer code based on the IronLauncher, the Express Generator.

After forking and cloning the project, you will have install all the dependencies:

$ npm install

To run the app:

$  npm run dev

Now you are ready to start. 🚀

Iteration 1 | Seed the database

First, we need to seed our database. Below you will find an array of objects with info for 8 movies. You should create two files:

  • In the root, create a folder models and in it add the Movie.model.js file for the Movie model.
  • In the root, create a folder seeds and inside create the movies.seed.js file and write the code necessary to seed the database.

Below you will find the seeds you should add to the seeds/movies.seed.js. As shown below, each of the movies has the same properties (title, director, etc.) so based on the available information, go ahead and create the Movie model in the models/Movie.model.js file.

// To insert in "seeds/movies.seed.js"

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'],
  },
]

// Add here the script that will be run to actually seed the database (feel free to refer to the previous lesson)

// ... your code here

Iteration 2 | List the Movies

Now when you have all movies in the database, you can proceed to sending them to the user.

Proceed to creating the GET /movies route.

We need to return a list of all the movies we have in our database.

We don't want to return all of the information we know about each movie, just the highlights. Use .select() on your mongoose query to specify that just the 'title' and 'director' should be sent.

Test the GET /movies route in Postman. Do you receive the expected data?

Iteration 3 | Display Movie Details

Finally, you have to create a route to receive all the details about each movie. You need a GET /movie/:id route, where the API user can receive all the info about each movie by specifying its id.

As before, test this in Postman by creating a GET /movie/:id route. Specify the id as one of the ids received from by your GET /movies request.

Bonus: A Frontend

Following the practice of calling the API from the frontend with fetch or axios, create a small webpage that can show all the movies to the user. Add some basic styling.

You can go further and create forms for creating and updating, as well as a button for deleting.

Happy coding!

About


Languages

Language:JavaScript 85.7%Language:HTML 10.2%Language:SCSS 4.0%Language:Shell 0.0%