Note: If you see a 🌶 , this represents that it is a bonus portion that has some spice to it.
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
- 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
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 driverhome_course
- home course of the driverteam_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 carmodel
- 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.
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 SELECT
ing all rows and columns in the drivers
, teams
, and cars
tables.
Add the environment variable data_source with the name of the database file.
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.
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.
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.
Open Postman and test your queries.