GithubHelp home page GithubHelp logo

vjp888 / be-inquantifiable-selves-express Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 1.27 MB

The backend Component to a calorie tracking application

Home Page: https://inquantifiable-selves.herokuapp.com/

JavaScript 91.49% HTML 7.95% CSS 0.56%

be-inquantifiable-selves-express's People

Contributors

blake-enyart avatar csheesley avatar vjp888 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

csheesley

be-inquantifiable-selves-express's Issues

GET /api/v1/meals

GET /api/v1/meals

As a visitor,
When I make a GET request to /api/v1/meals

  • A list of all meals with their names and ingredients is returned, along with a 200 status code.

Endpoint Format:

Request

GET /api/v1/meals
Content-Type: application/json
Accept: application/json

Response

[
    {
        "id": 1,
        "name": "Breakfast",
        "foods": [
            {
                "id": 1,
                "name": "Banana",
                "calories": 150
            },
            {
                "id": 6,
                "name": "Yogurt",
                "calories": 550
            },
            {
                "id": 12,
                "name": "Apple",
                "calories": 220
            }
        ]
    },
    {
        "id": 2,
        "name": "Snack",
        "foods": [
            {
                "id": 1,
                "name": "Banana",
                "calories": 150
            },
            {
                "id": 9,
                "name": "Gum",
                "calories": 50
            },
            {
                "id": 10,
                "name": "Cheese",
                "calories": 400
            }
        ]
    },
    {
        "id": 3,
        "name": "Lunch",
        "foods": [
            {
                "id": 2,
                "name": "Bagel Bites - Four Cheese",
                "calories": 650
            },
            {
                "id": 3,
                "name": "Chicken Burrito",
                "calories": 800
            },
            {
                "id": 12,
                "name": "Apple",
                "calories": 220
            }
        ]
    }
]

Create MealFood Model

  • npx sequelize model:generate --name MealFood --attributes foodId:integer,mealId:iteger

  • Make adjustment to allow for foreign key for 'Food'

  • Make adjustment to allow for foreign key for 'Meal'

  • Make adjustments to Meal Model to allow for many to many relationship (belongsToMany)

  • Make adjustments to Food Model to allow for many to many relationship (belongsToMany)

Create Meal Model

  • npx sequelize model:generate --name Meal --attributes name:citext

Testing

  • Model attributes can not be blank

Create PATCH route and UPDATE action - PATCH /api/v1/foods/:id

  • Establish RESTful route to controller
  • Add route to app.js file
  • Create Controller CRUD Action
  • Create Controller Logic
  • Update food record in the database

Testing

Happy Path:

  • Returns status Response 202 when food record updated

Sad Path:

  • Returns status Response 400 when food is not successfully updated
  • Returns status Response 400 when either name or calorie fields are blank in Request body
  • Returns stats Response 404 when food not found

PATCH /api/v1/foods/:id

PATCH /api/v1/foods/:id

As a visitor

When I make a successful PATCH request to /api/v1/foods/:id

  • That food is updated in the database, and a 202 status code is returned

When I make an unsuccessful PATCH request to /api/v1/foods/:id

  • A 400 status code is returned with an error message "error": "resource not found"

Endpoint Format:

Request:

PATCH /api/v1/foods/:id
Content-Type: application/json
Accept: application/json

{ "food": { "name": "Mint", "calories": "14"} }

Response:

status: 202
body: 
{
    "id": 1,
    "name": "Mint",
    "calories": 14
}

or

status: 400
body: 
{
    "error": "resource not found"
}

Create GET and SHOW action - GET /api/meals/:meal_id/foods

  • Establish RESTful route that points to controller
  • Add router to app.js file
  • Add required dependencies in index.js for controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action

Testing

Happy Path

  • Returns status Response 200 and meal with associated food records

Edge Case

Sad Path:

  • Returns Status Response 404 when there is no meal for that ID

DELETE /api/v1/meals/:mealId/foods/:foodId

DELETE /api/v1/meals/:mealId/foods/:foodId

As a user
When I make a successful DELETE request to DELETE /api/v1/meals/:mealId/foods/:foodId

  • The food with :id is deleted from the meal with :meal_id
  • And I receive a 204 status code, and a confirmation message in the body.

When I make an unsuccessful DELETE request to /api/v1/meals/:mealId/foods/:foodId

  • A 404 status code is returned

Endpoint Format:

Request:

DELETE /api/v1/meals/:mealId/foods/:foodId
Content-Type: application/json
Accept: application/json

Response:

status: 204
body:
{
    "message": "Successfully deleted FOODNAME from MEALNAME"
}

or

status: 404
body: 
{
    "error": "RESOURCE not found"
}

*interpolate missing resource

POST /api/v1/meals/:mealId/foods/:foodId

POST /api/v1/meals/:meal_id/foods/:id

As a user
When I make a successful POST request to /api/v1/meals/:mealId/foods/:foodId

  • The food record with :foodId is associated with the meal record with :mealId
  • And I receive a 201 status code, and a confirmation message in the body.

When I make an unsuccessful POST request to /api/v1/meals/:mealId/foods/:foodId

  • A 404 status code is returned, with an error message in the body.

Endpoint Format:

Request:

POST /api/v1/meals/:mealId/foods/:foodId
Content-Type: application/json
Accept: application/json

Response:

status: 201
body:
{
    "message": "successfully added FOODNAME to MEALNAME"
}

or

status: 404
body: 
{
    "error": "RESOURCE not found"
}

*interpolate missing resource

POST /api/v1/foods

POST /api/v1/foods

As a user
When I make a successful POST request to /api/v1/foods

  • A new food item is added to the database, and I receive a status code 201 response.

When I make an unsuccessful POST request to /api/v1/foods

  • I receive a 400 status code response

both name and calories are required fields

Endpoint Format:

Request:

POST /api/v1/foods
Content-Type: application/json
Accept: application/json

body:
{ "food": 
  {
     "name": "Name of food here",
     "calories": "Calories here"
   }
}

Response:

status: 201
body:
{ 
  "message": "FOODNAME has been added"

}

or

status: 400
body:
{ 
  "error": "null value in column \"RESOURCE\" violates not-null constraint"
}

*missing resource (name or calories) information is provided from error.message

DELETE /api/v1/foods/:id

DELETE /api/v1/foods/:id

As a user
If I make a delete request to /api/v1/foods/:id

  • If that :id exists, that food item will be deleted and a 204 status code is returned.
  • If that :id does not exist, a 404 status code is returned.

Endpoint Format:

Request:

DELETE /api/v1/foods/:id
Content-Type: application/json
Accept: application/json

Response:

status: 204

or

status: 404
body: 
{
    "error": "Cannot read property 'destroy' of null"
}

*error message updated to use what .catch, .error.message returns

Create Delete Route and Destroy Action - DELETE /api/v1/meals/:meal_id/foods/:id

  • Establish RESTful route that points to controller
  • Add router to app.js file
  • Add required dependencies in index.js for controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action
  • Deletes MealFood Record in Database

Testing
Happy path:

  • Returns status Response 204
  • Does not Delete a Meal or Food Resource and only breaks the connection

Edge Path:

Sad Path:

  • Returns status Response 404 if Meal/Food can not be found

Create Seeder File - (Foods, Meals, MealFoods)

Examples

Foods

  {
        id: 1,
        name: 'Banana',
        calories: 150,
        createdAt: new Date(),
        updatedAt: new Date()
      }

Meals

  {
        id: 1,
        name: 'Breakfast' ,
        createdAt: new Date(),
        updatedAt: new Date()
      }

MealFoods

{
        MealId: 1,
        FoodId: 1,
        createdAt: new Date(),
        updatedAt: new Date()
      }

Create a unique validator for food model

We discovered an issue with attempting to setup a validator to prevent a user from creating foods with the same name.

A possible blocker is because we chose to use the CITEXT datatype which doesn't seem to work with conventional unique validators.

Ice Boxed this issue for the time being as it was eating up too much time.

Create GET route and INDEX action - GET /api/v1/foods

  • Establish RESTful route that points to controller
  • Add router to app.js file
  • Add required dependencies in index.js for controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action

Testing
Happy Path:

  • Returns status Response 200 and all food records in the database

Edge Case:

  • Returns status Response 200 when DB is empty

Sad Path:

GET /api/v1/foods

GET /api/v1/foods

As a user
When I make a GET request to /api/v1/foods
It returns a list of all foods


Endpoint Format:

Request:

GET /api/v1/foods
Content-Type: application/json
Accept: application/json

Response:

status: 200
body: 
{
 foods: [ 
    {
      "id": 1,
      "name": "Banana",
      "calories": 150
    },
    { 
      "id": 2,
      "name": "Apple",
      "calories": 10
    }
  ]
}

GET /api/v1/meals/:meal_id/foods

GET /api/v1/meals/:meal_id/foods

As a visitor
When I visit /api/v1/meals/:meal_id/foods

And I provide a valid:meal_id

  • All food records associated with that meal are returned, along with a 200 status code.

If I provide an invalid :meal_id

  • I am returned a 404 status code.

Endpoint Format:

Request:

GET /api/v1/foods
Content-Type: application/json
Accept: application/json

Response:

status: 200
body: 
{
    "id": 1,
    "name": "Breakfast",
    "foods": [
        {
            "id": 1,
            "name": "Banana",
            "calories": 150
        },
        {
            "id": 6,
            "name": "Yogurt",
            "calories": 550
        },
        {
            "id": 12,
            "name": "Apple",
            "calories": 220
        }
    ]
}

or

status: 404
body: 
{
    "error": "Meal not found"
}

Create Food Model - GET /api/v1/foods

  • npx sequelize model:generate --name Food --attributes name:citext,calories:integer

Testing
Happy Path:

Edge Case:

Sad Path:

  • Name must be citext, case insensitive, and not blank
  • Calories must be integer and not blank

GET /api/v1/foods/:id

GET /api/v1/foods/:id

As a visitor
When I visit /api/v1/foods/:id

And I provide a valid :id

  • That food record is returned, along with a 200 status code.

If I provide an invalid :id

  • I am returned a 404 status code.

Endpoint Format:

Request:

GET /api/v1/foods/1
Content-Type: application/json
Accept: application/json

Response:

status: 200
body: 
{
    "id": 1,
    "name": "Banana",
    "calories": 150
}

or

status: 404
body: 
{
    "error": "Food not found"
}

Create POST route and CREATE action - POST /api/v1/meals/:meal_id/foods/:id

  • Establish RESTful route that points to controller
  • Add router to app.js file
  • Add required dependencies in index.js for controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action
  • Create FoodMeal record in database

Testing
Happy Path:

  • Returns status Response 201 and creates MealFood record associating existing food record with existing meal record AND Response body has message "Successfully added FOODNAME to MEALNAME"

Edge Case:

Sad Path:

  • Returns status Response 404 when either food or meal record does not exist with error message of "RESOURCE not found"
  • Returns status Response 404 when food AND meal record do not exist with error message of "FOODNAME and MEALNAME not found"

Create GET route for INDEX action - GET /api/v1/meals

  • Establish RESTful route to controller
  • Add route to app.js file
  • Create Controller CRUD Action
  • Create Controller Logic

Testing

  • Returns status Response 200 with body containing all meal records from database

Edge Case Testing

  • Still returns 200 when there are no meals in the database

Sad Path Testing

Create DELETE route and DESTROY action - DELETE api/v1/foods/:id

  • Establish RESTful route that points to controller
  • Add route to app.js file
  • Add required dependencies in index.js of controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action
  • Delete food record in the database

Testing
Happy Path:

  • Request sends id in database and status Response 204

Edge Case:

Sad Path:

  • Request sends id not in database and status Response 404

Final Checklist

  • Documentation is Written in README for this endpoint (request response example)

Happy Case:

Edge Case:

Sad Case:

Create POST Route and Controller - POST /api/v1/foods

  • Establish RESTful route to controller
  • Add route to app.js file
  • Create Controller CRUD Action
  • Create Controller Logic

Testing

  • Returns Status Response 201 when food is created
  • Returns Status Response 400 when food is not successfully created
    • To successfully create a food a user must send both name and calories in the body. if Either is missing it should fail to create the food.

Create GET route and SHOW action - GET /api/v1/foods/:id

  • Establish RESTful route that points to controller
  • Add route to app.js file
  • Add required dependencies in index.js of controller folder
  • Create controller CRUD action
  • Build out logic of the respective CRUD action

Testing
Happy Path:

  • Request with valid id in database and status Response 200 with food record in body

Edge Case:

Sad Path:

  • Request with invalid id not in database and status Response 404 and error message

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.