---
# System prepended metadata

title: Wine-os App Resubmit

---

# Wine-os App Resubmit

All the work you did over the first weekend definitely shows because most of your sequelize functionality is there!~~The main reason your app isn't functioning is because there is a lack of connection between your API, your database, and your routes. In order to simplify this app and get you to passing, I'm giving you a detailed road map of your user stories, info you'll need to get from the api, models, and routes.~~ Utilize TAs, and please keep us updated throughout the process! Please resubmit a working project by **Monday, September 6th at 9am PST**.

This may seem like a huge revamping of your app, but you have a lot of the database functionality and routing in place, so you won't have to write it all from scratch (unless that's what you want to do)

## What you have left:

* [ ] Add/finish installation instructions to the readme
* [x] Protect your note CRUD routes so one user can't edit/delete another user's notes
* [x] Fix the redirects on the note post/update routes so they redirect to the wine show page, not the wine index page
* [x] Add the `/notes` route so a user can view all the wines that they have made notes on
* [x] Remove bottom script tag from your `layout.ejs` and line 13 from your `server.js` (they're not doing anything)
* [x] Change the link text on the wine cards from 'add a tasting note' to just 'tasting notes' or something like that (so the user knows that's where they go to view the tasting notes and edit/delete them too)
* [x] Have *something* relevant displaying on the user profile page (like the name and a link to the `/notes` route)
* [x] Make sure all of your tasting notes routes are in the tasting notes controller file (and not in the wine controller)

## User Stories

* [X] A user can log in.
* [x] A user can view all wines _(query the api)_
* [x] A user can view all notes for a wine _(query the database)_
* [x] A user can add a note _(POST to database)_
* [x] A user can edit a note they wrote _(PUT to the databse)_
* [x] A user can delete a note they wrote _(DELETE to the databse)_

## API vs. Seeding

~~Rather than worrying about using your API to seed your database (which it looks like you were trying to do), use the api for finding a list of wines. Your api can take up to 10 requests per minute, which isn't a lot, so be mindful of the number of times you hit the route that queries it.~~

I get why it makes sense to seed the db - that's totally cool if you have a seed file that works and you can put instructions on how to run it in your readme.

## Models

* [x] User
* [x] Note

### User
| Column Name | Data Type | Notes |
| --------------- | ------------- | ------------------------------ |
| id | Integer | Serial Primary Key, Auto-generated |
| name | String | Must be provided |
| email | String | Must be unique / used for login |
| password | String | Stored as a hash |
| createdAt | Date | Auto-generated |
| updatedAt | Date | Auto-generated |

### Note
| Column Name | Data Type | Notes |
| --------------- | ------------- | ------------------------------ |
| id | Integer | Serial Primary Key, Auto-generated |
| body | Text | Must be provided _(ie "full bodied with notes of chocolate")_ |
| userId | Integer | Must be provided |
| title | String | Must be provided _(This is to identify different notes, can be the name of the wine)_ |
| wineId | Integer | Must be provided, from API _(This will correlate to the ID provided by the API so you can use it to get details about a specific wine)_|
| createdAt | Date | Auto-generated |
| updatedAt | Date | Auto-generated |

### Routes

#### GET ROUTES
* [x] `/profile` THIS NEEDS TO HAVE SOME INFO ON IT IF ITS GOING TO EXIST
* [x] `/wines`
* [x] `/wines/:wineId`
* [ ] `/notes`
* [ ] ~~`/notes/new/:wineID/:wineName`~~
* [x] `/notes/:id`
* [ ] ~~`/notes/edit/:id`~~
#### POST, PUT, DELETE ROUTES (these need to be properly protected and redirected)
* [ ] POST `/notes` 
* [ ] PUT `/notes/:id`
* [ ] DELETE `/notes/:id`


Your auth routes are done, so I am not including them here.

| Method | Path | Location | Purpose | Links or Redirects to |
| ------ | ---------------- | -------------- | ------------------- |---|
| GET | /profile | server.js | show basic user data like name and email| LINKS: /notes |
| GET | /wines | wines.js | Show a list of all wines from the **api** | LINKS: /wines/:wineId |
| GET | /wines/:wineId | wine.js | Show the wine information from the **api** as well as ALL notes from the **database** with that associated wineId| LINKS: /notes/new/:wineId
| GET | /notes | wineTasting.js | This will show a list of all the wines a user has made a note on in the **database**  | LINKS: /notes/:id
| ~~GET~~ | ~~/notes/new/:wineID/:wineName~~ | ~~wineTasting.js~~ | ~~will show a form to create a new note about a wine _(the :wineName is optional, but useful for the new form so it's a little clearer what the tasting is about)_~~| ~~ACTION: /notes~~
| GET | /notes/:id | wineTasting.js | Show a specific note from the **database** | LINKS: /wines/:wineId AND /notes/edit/:id
| ~~GET~~ | ~~/notes/edit/:id~~ | ~~wineTasting.js~~ | ~~show a form to edit a specific note~~ | ~~ACTION: /notes/:id (both PUT and DELETE)~~
| POST | /notes | wineTasting.js | will add a wine to the **database** | REDIRECTS: /notes/:id 
| PUT | /notes/:id | wineTasting.js | edit a specific note | REDIRECTS: /notes/:id
| DELETE | /notes/:id | wineTasting.js | delete a specific note | REDIRECTS: /notes

## Suggested Plan

There is a lot to implement here, but if you go step by step and utilize TA support, you will be able to make good progress while understanding each step.

1. Stub out your routes—get your routes to the point where, when you hit them, they `res.send('HIT /notes')` or something along those lines.
2. Get your Get routes rendering—render your ejs pages, if they will eventually have information in them (for example `/notes/:id`) then simply create a stub EJS that has everything but the info that will come from the database (you can write something like `"coming soon!"` in a `<p>` tag)
3. Get information from your api—write a test route that, when hits, queries the API and `res.send` the data to your front end. Get that working for the two types of request you'll be making.
4. Hook up your API to your API-dependent GET routes—get information rendering on the page in the way that you want.
5. Test your forms—hook up your forms to your routes, check that they work by console logging the information passed up to the form and redirecting back home. Make sure that you can console log all the information that your database will need (to see what your DB needs, look to your schema)
6. Test adding a note
7. Test deleting a note
8. Test updating a note
9. Style—If you have time, this part is optional
10. Deploy up to heroku—it might be easier to start fresh on this deploy to clean up your database on Heroku
11. Message your instructors with the link!