Giter VIP home page Giter VIP logo

m7-2-dbs--mongo-continued's Introduction

MongoDB - Day 2

Today you are going to take an app that "works" without a database, and integrate a database into it.

Remember the Ticket Booker? ๐Ÿ˜ฌ

Currently, the backend is generating the seats for the theater. Let's migrate that to a database: MongoDB.

Setup

yarn install to get all of the dependencies.

yarn start to start both the server and the FE app. You don't need to run 2 terminals for this.


Exercise 1 - Setup the database!

Get the seats into a database > collection. Each seat should be a document in the collection.

You could use a util function like the one you created in the last workshop...

Keep in mind, that under normal circumstances, the FE should not be affected by any changes you make here. Meaning it shouldn't break because you change the code in the backend. Be mindful of what the FE expects as data as well as how you are storing it in the database.

Don't forget to provide an _id to each document. You could do that before getting rid of the code that currently generates the seats. Each seat should look something like this.

{
  _id: 'A-1',
  price: 225,
  isBooked: false
}

Exercise 2 - Write that function!

Once you've migrated the data, it's time to get rid of the code that is generating the seats, and write a function that queries the database to retrieve all of the seats.

Inside of handlers.js, there is an empty function called getSeats that should replace the anonymous function that is called at the /api/seat-availability endpoint. Don't forget to require it.

Exercise 3 - Booking a seat

In handlers.js, write a function that will handle booking the seat. It needs to update the database.

While you're at it, remove the anonymous function that is called at /api/book-seat and create a proper function in the handlers.js file.

Exercise 4 - Who booked that?

If you verify the data that is being sent to the server when a user buys a ticket, you will notice that there is some data that we are currently not handling: fullName and email.

What should we do with that?

There are two options that come to mind:

  1. Create a new collection that contains all of the user documents, along with a reference to the seat they booked.
  2. Add that data to the seat document directly.

Both are viable and it really depends on what will be done with the data. It's totally up to you!


๐ŸŸก - Minimally complete workshop (75%) - ๐ŸŸก

Exercise 5 - Uhoh! Incoming requirements

There is talk of creating an admin panel to manage the bookings. The FE is not built yet, but it would be good to enable the required functionality now in the BE.

Administrators would like to be able to

  1. view the bookings. that's already done (exercise 1)
  2. delete a booking, i.e. make the seat available for purchase once more.
  3. update the name or email of customer.

You will need to test this implementation with Insomnia.

You could always try to improve the FE as well. There some benefit/difficulty in adding features to code you didn't write...


๐ŸŸข - Complete workshop (100%) - ๐ŸŸข

m7-2-dbs--mongo-continued's People

Contributors

scottanthonymorin avatar aya-sato avatar tiffanydow1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.