For this exercise, we will abstract SQL queries into model files to declutter our controller files - effectively moving completely into an MVC (model view controller) framework.
We will also be introducing a Users table so users can create accounts on the app.
- Fork and clone this repository to your computer
- Run
yarn install
to install dependencies - Create a new Postgres database by running
createdb pokemons -U <your_username>
- Run
psql -U <your_username> -d pokemons -a -f tables.sql
- this will create 2 new tables for you - apokemons
table andusers
table in the database - Seed data into the newly created
pokemons
table by runningpsql -U <your_username> -d pokemons -a -f seed.sql
(Note: this will run 3 INSERT queries to seed 3 pokemons into the table.) - Look in the starter file called
index.js
, runnodemon
to start local server on port 3000 - Open
localhost:3000
on your browser and see the home page
- Add in missing logic implementation in
controllers/pokemon.js
forupdateForm
andupdate
- Add in missing logic implementation in
controllers/user.js
forlogin
- Add a "Logout" button on home page that sends POST request to
/users/logout
to log out a user (hint: remember to remove cookies) - Ensure that you can create a new user account
- Ensure that you can create a new pokemon
Add the ability for users to own newly created pokemons.
- Drop the database from earlier and implement a slightly different entity relationship - modify
tables.sql
to create a third table calleduser_pokemons
that has a primary keyid
, and 2 foreign keyspokemon_id
anduser_id
- Modify the
pokemon/new.handlebars
file to accept a new field called "user_id" - Modify the backend logic to assign any newly created pokemon to the specified user based on the value of the new
user_id
field - Update the
user/user.handlebars
file to show all pokemons that a specified user owns (eg./users/1
should show the 1st user's account information and names of pokemons that she owns)
- Singular vs plural naming is important. For this exercise, let's assume that the plural of pokemon is pokemons...
- We have changed our table names to be plural. So user is now users table, and pokemon is now pokemons table.