Skip to content

Instantly share code, notes, and snippets.

@JimmyLin39
Created November 23, 2017 03:02
Show Gist options
  • Save JimmyLin39/5e9329fd8c71cfb00b8c871ef0e7aef1 to your computer and use it in GitHub Desktop.
Save JimmyLin39/5e9329fd8c71cfb00b8c871ef0e7aef1 to your computer and use it in GitHub Desktop.
Lighthouse Labs midterm project routes

Midterm

Site Header:

  • if a user is logged in, the header shows:
    • the user's username
    • a HOME Link to /resources
    • a profile Link
      • make GET request to /profile
    • a search bar
      • make a GET request to /search
    • a logout button
      • makes a POST request to /logout

Routes

GET /

  • if user is logged in:
    • redirect to /resources
  • if user is not logged in:
    • redirect to /login

GET /resources

  • if user is logged in:
    • return HTML with
    • the site header
    • a list (or table) of resources the user has created, each list item containing:
      • Title link to /resources/:id
      • The resource URL
        • redirect to
      • Description
      • Tags
      • Like
        • unlike button
        • make a DELETE request to /delete
    • (stretch) a side bar contains all the tags user had
      • each tag link make a GET request to /resources/:tagid
  • if user is not logged in:
    • redirect to /login

GET /resources/new

  • if user is logged in:
    • return HTML with
    • the site header
    • a form which contains:
      • a Title
      • a text input field for the URL
      • an optional Description
      • Tags
      • mark it as Like for the given user
      • a submit button
        • makes a POST request to /resources
  • if user is not logged in:
    • redirects to the /login page

GET /resources/:id

  • if user is logged in:
    • return HTML with
    • the site header
    • Title
    • URL
    • Description
    • Tag
    • Comments input form
    • Comments Submit button
      • make a POST request to /resources/:id
    • Like button
      • like
        • make a POST request to /like
      • unlike
        • make a DELETE request to /delete
    • Rating input form
  • if user is not logged in:
    • redirect to /login
  • if resources id not exist:
    • returns HTML with a relevant error message

GET /resources/:id/profile

  • if user is logged in:
    • return HTML with
    • the site header
    • edit Username
    • edit email
    • edit password
    • a Submit button
      • make a POST request to /resources/:id/profile
  • if user is not logged in:
    • redirect to /login
  • if resources id not exist:
    • returns HTML with a relevant error message

PUT /resources/:id/profile

  • if user is logged in:
    • update username/ email/ password
  • if user is not logged in:
    • redirect to /login

POST /resources

  • if user is logged in:
    • create a new row in resource table
    • create a new row in tag table
    • create a new row in like table
    • redirect to /resources
  • if user is not logged in:
    • redirect to /login

PUT /resources/:id

  • if user is logged in:
    • update the comment
    • update rating
    • update like
      • make a POST request to /resources
  • if user is not logged in:
    • redirect to /login

POST /like

  • if user is logged in:
    • create a new row in like table
  • if user is not logged in:
    • redirect to /login

DELETE /delete

  • if user is logged in:
    • delete a row in like table
  • if user is not logged in:
    • redirect to /login

GET /search

  • if user is logged in:
    • show the search result
  • if user is not logged in:
    • redirect to /login (stretch) GET /resources/:tagid
  • if user is logged in:
    • show all the resources belong to that tag
  • if user is not logged in:
    • redirect to /login (stretch) PUT /resources/:tagid
  • if user is logged in:
    • update resources belong to tag
  • if user is not logged in:
    • redirect to /login

GET /login

  • if user is logged in:
    • redirects to /resources
  • if user is not logged in:
    • returns HTML with:
    • a login form which contains:
      • input fields for email and password
      • submit button that
        • makes a POST request to /login
    • a register form which contains:
      • input fields for email and password
      • a register button
        • makes a POST request to /register

POST /login

  • if email and password params match an existing user:
    • sets a cookie
    • redirects to /resources
  • if email and password params don’t match an existing user:
    • returns HTML with a relevant error message

POST /register

  • if email or password are empty:
    • returns HTML with a relevant error message
  • if email already exists:
    • returns HTML with a relevant error message
  • otherwise:
    • creates a new user
    • encrypts the new user’s password with bcrypt
    • sets a cookie
    • redirects to /resources

POST /logout

  • deletes cookie
  • redirects to /login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment