vjp888 / be-inquantifiable-selves-express Goto Github PK
View Code? Open in Web Editor NEWThe backend Component to a calorie tracking application
Home Page: https://inquantifiable-selves.herokuapp.com/
The backend Component to a calorie tracking application
Home Page: https://inquantifiable-selves.herokuapp.com/
Happy Case:
Edge Case:
Sad Path:
GET /api/v1/meals
As a visitor,
When I make a GET request to /api/v1/meals
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
}
]
}
]
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)
npx sequelize model:generate --name Meal --attributes name:citext
Testing
Set up Travis CI - use these documents for reference:
http://frontend.turing.io/lessons/module-4/continuous-integration.html
http://frontend.turing.io/lessons/module-4/continuous-integration-walkthrough.html
Happy Case:
Edge Case:
Sad Case:
Testing
Happy Path:
Sad Path:
Happy Case:
Edge Case:
Sad Path:
Happy Case:
Edge Case:
Sad Path:
PATCH /api/v1/foods/:id
As a visitor
When I make a successful PATCH request to /api/v1/foods/:id
When I make an unsuccessful PATCH request to /api/v1/foods/:id
"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"
}
Testing
Happy Path
Edge Case
Sad Path:
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
:id
is deleted from the meal with :meal_id
When I make an unsuccessful DELETE request to /api/v1/meals/:mealId/foods/:foodId
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/:meal_id/foods/:id
As a user
When I make a successful POST request to /api/v1/meals/:mealId/foods/:foodId
:foodId
is associated with the meal record with :mealId
When I make an unsuccessful POST request to /api/v1/meals/:mealId/foods/:foodId
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
As a user
When I make a successful POST request to /api/v1/foods
When I make an unsuccessful POST request to /api/v1/foods
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
As a user
If I make a delete request to /api/v1/foods/:id
:id
exists, that food item will be deleted and a 204 status code is returned.: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
Testing
Happy path:
Edge Path:
Sad Path:
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()
}
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.
Testing
Happy Path:
Edge Case:
Sad Path:
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
As a visitor
When I visit /api/v1/meals/:meal_id/foods
And I provide a valid:meal_id
If I provide an invalid :meal_id
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"
}
npx sequelize model:generate --name Food --attributes name:citext,calories:integer
Testing
Happy Path:
Edge Case:
Sad Path:
GET /api/v1/foods/:id
As a visitor
When I visit /api/v1/foods/:id
And I provide a valid :id
If I provide an invalid :id
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"
}
Happy Case:
Edge Case:
Sad Path:
Testing
Happy Path:
Edge Case:
Sad Path:
Happy Case:
Edge Case:
Sad Path:
Happy Case:
Edge Case:
Sad Path:
Testing
Edge Case Testing
Sad Path Testing
index.js
of controller folderTesting
Happy Path:
Edge Case:
Sad Path:
Happy Case:
Edge Case:
Sad Case:
Happy Case:
Edge Case:
Sad Path:
Testing
index.js
of controller folderTesting
Happy Path:
Edge Case:
Sad Path:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.