MacFlyOSX / 10week-initial_D-long-practice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Let's make something new: Combining this week's info

Note: If you see a ๐ŸŒถ , this represents that it is a bonus portion that has some spice to it.

Step 1: Let's start with the setup

Complete the following in the server folder:

  • create an app.js file
  • create a routes folder
  • create a .env file (start by defining your PORT)
  • install all dependencies

Step 2: Set up your app.js file

  • Make sure to require everything you need to, set up express, and have your app listen on the port that you set in your .env file
  • Set up your root so that if you perform a 'GET' method on that page, you will receive the following response:
{
  "message": "Welcome to the Initial D database!",
    "pages": "/drivers, /courses, /teams"
}
  • Make sure to set a default error response if your server hits a page that doesn't have a route

Step 3: It's the sql before the actual movie!

Write the proper SQL statements in the seed-data.sql file to create the following tables in your .sql file:

  • Drivers
    • id - the driver's primary key (have it auto increment)
    • name - first name of the driver
    • home_course - home course of the driver
    • team_id - connect driver to team (can set to default with null)
  • Cars
    • id - the car's primary key (have it auto increment)
    • make - make of car
    • model - the model of the car
  • Teams
    • id - the team's primary key (auto increment)
    • name - the team's name

Make a join table (car_owners) so that you can link drivers with their cars (note that some drivers will have the same make/model, which we will say is the same car).

Notice that the insert records are already written for you.

You're welcome.

Check the seed-data.sql file to double check your CREATE statements match the INSERT statements.

Create your database using sqlite3 and read your seed-data file.

Verify everything works by SELECTing all rows and columns in the drivers, teams, and cars tables.

Add the environment variable data_source with the name of the database file.

Step 4: Take a different route? But of course.

Create a courses route (js file) that will handle the following:

  • Make sure to instantiate SQLITE and the database
  • 'GET /courses' - will return a list of all unique course names
  • ๐ŸŒถ 'GET /courses/:name' - will return a list of all the drivers' names and cars (make & model) whose home course is :name
    • pay attention to the input for :name... make sure that you set up some js code to handle it so that it will always match the name in the db
  • ๐ŸŒถ 'PUT /courses/:name' - edit a course's name for all drivers that have that course as their home course
    • pay attention to the input for :name... make sure that you set up some js code to handle it so that it will always match the name in the db (Looking over subqueries might be helpful)

Make sure to connect the route to the main app.js file.

Step 5: You have to route for your team, right?

Create a teams route (js file) that will handle the following:

  • Make sure to instantiate SQLITE and the database
  • 'GET /teams' - will return a list of all unique team names
  • ๐ŸŒถ๐ŸŒถ 'GET /teams/:name' - will return a list of all the drivers' names and cars (make & model) that are on that team
    • pay attention to the input for :name... make sure that you set up some js code to handle it so that it will always match the name in the db
  • 'POST /teams' - will create a new team
  • ๐ŸŒถ๐ŸŒถ 'PUT /teams/:name/:driver' - will change the input driver's team to the team :named

Make sure to connect the route to the main app.js file.

Step 6: Name that driver!

Create a drivers route (js file) that will handle the following:

  • Make sure to instantiate SQLITE and the database
  • 'GET /drivers' - will return a list of all drivers' names
  • ๐ŸŒถ๐ŸŒถ 'GET /drivers/:name' - will return the driver's name, home course, team, and car (make & model)
    • pay attention to the input for :name... make sure that you set up some js code to handle it so that it will always match the name in the db
  • ๐ŸŒถ 'PUT /drivers/:name' - edit a driver's name, home course, and team id
    • pay attention to the input for :name... make sure that you set up some js code to handle it so that it will always match the name in the db
  • ๐ŸŒถ๐ŸŒถ 'POST /drivers' - will create a new driver (example of the correct fields are below). Make sure that you connect the driver with their car using the join table. Looking over subqueries might be helpful
{
        "name": <name>,
 "home_course": <course-name>,
     "team_id": <team-id>,
    "car_make": <car-make>,
   "car_model": <car-model>
}

Make sure to connect the route to the main app.js file.

Step 7: Driver Test time!

Open Postman and test your queries.

GREAT JOB WITH FINISHING THIS!!

About