A-Suggestion-Box-HW

Assignment following MongoDB Intro Lessons. Due September 27, 2021

Requirements

Overview

Mongo Express Node suggestion-box-hw

Use Postman and Robo 3T to test your routes Use MongoDB and Mongoose and name database suggestion-hw Use Async and Await (Don't forget the try and catch block) Use controllers for business logic.

  • Remember to be inside folder and npm i*
  • Only .gitignore the node_modules

Instructions

Create Server

  • Create an express server using express-generator:
    • express suggestion-box-hw --view=ejs
    • Delete all view related items

Connect Database

  • Connect to mongodb with mongoose.
    • Remember to name database suggestion-hw.

Create Routes

  • In routes folder create a suggestions folder
    • Then create suggestionRouter.js inside suggestion folder
      • Make sure you connect it through app.js with the path '/api/suggestions'
    • In suggestion folder,
      • Create model folder
      • Controller folder.

Create Data Models

  • In model folder,
    • create a file called Suggestion.js:
      • Build a schema for Suggestions called SuggestionSchema
        • Title
          • string
          • lowercase
          • unique
          • required
        • Author
          • string
          • lowercase
        • Suggestion
          • string
          • lowercase
          • required
        • Likes
          • number
          • default to 0
        • Anonymous
          • boolean
        • TimeCreated
          • date with default Date.now

Build Controllers

  • create a file called suggestionController.js
  • getAllSuggestions
  • getSingleSuggestion
  • get one suggestion based on id using parameters
  • createSuggestion- does not need id or time from user
  • updateSuggestion- user can only update title and suggestion
  • deleteSuggestion - suggestion deletes based on id

Use Postman Routes

  • Hook it up to suggestionRouter.js
    • GET /all-suggestions
    • GET /single-suggestion
    • POST /create-suggestion
    • UPDATE /update-suggestion
    • DELETE /delete-suggestion

Extra Credit

  • Make a GET /by-author-suggestion using query
  • getSuggestionsByAuthor- if i query a author's name i should get a list of their suggestions

Hint:

in url www.shop.com/products/?item=shoes in code req.query.item equals shoes