- Ruby version 2.4.1
- Rails version 5.1.6
https://calorie-me.herokuapp.com/
git clone repo
cd quantified_self
bundle update
rails db:{create,migrate,seed}
rails s
http://localhost:3000
rspec
- Retrieve all foods currently in the database
- If successful, this request will return a response in the following format:
[{
"id": 1,
"name": "Strawberries",
"calories": 10
},
{
"id": 2,
"name": "Blueberries",
"calories": 15
},
{
"id": 3,
"name": "Pineapple",
"calories": 20
},
{
"id": 4,
"name": "Banana",
"calories": 150
}]
- Retrieve a single food based on the :id
- If the food is not found, a 404 will be returned.
- If successful, this request will return a response in the following format:
{
"id": 2,
"name": "Cookie",
"calories": 88
}
- Create a single food
- Both name and calories are required parameters.
- If the food is not successfully created, a 400 status code will be returned.
- If successful, this request will return a response in the following format:
{
"id": 3,
"name": "Waffle",
"calories": 67
}
- Update an existing food
- Only field(s) updated are required parameters.
- If the food is not successfully updated, a 400 status code will be returned.
- If successful, this request will return a response in the following format:
{
"id": 4,
"name": "Banana",
"calories": 140
}
- Delete and exisiting food
- If the food can’t be found, a 404 will be returned.
- If successful, the request will return a 204 status code.
- Retrieve all the meals along with their associated foods
- If successful, this request will return a response in the following format:
[
{
"id": 1,
"name": "Breakfast",
"foods": [
{
"id": 4,
"name": "Banana",
"calories": 140
},
{
"id": 3,
"name": "Waffle",
"calories": 67
},
{
"id": 12,
"name": "Honey",
"calories": 60
}
]
},
{
"id": 2,
"name": "Lunch",
"foods": [
{
"id": 3,
"name": "Avocado",
"calories": 67
},
{
"id": 4,
"name": "Toast",
"calories": 15
},
]
}
]
- Retrieve all foods associated with a single meal
- If the meal is not found, a 404 will be returned.
- If successful, this request will return a response in the following format:
{
"id": 1,
"name": "Breakfast",
"foods": [
{
"id": 1,
"name": "Banana",
"calories": 140
},
{
"id": 6,
"name": "Waffle",
"calories": 67
},
{
"id": 12,
"name": "Honey",
"calories": 60
}
]
}
- Add a single food to a meal
- If the food is not successfully added to the meal, a 400 status code will be returned.
- If successful, this request will return a response in the following format:
{
"message": "Successfully added Honey to Breakfast"
}
- Delete a single food from a meal
- If the food is not listed for the meal, a 404 will be returned.
- If successful, this request will return a response in the following format:
{
"message": "Successfully removed Banana from Breakfast"
}
- Retrieve a list of foods (based on consumption), organized by
timesEaten
in descending order (up to three) - Only foods consumed more than once will be considered
- If successful, this request will return a response in the following format:
[
{
"timesEaten": 3,
"foods": [
{
"id": 3,
"name": "Honey",
"calories": 10,
"mealsWhenEaten": [
"Breakfast",
"Snack"
]
},
{
"id": 2,
"name": "Waffle",
"calories": 10,
"mealsWhenEaten": [
"Breakfast",
"Lunch"
]
}
]
},
{
"timesEaten": 2,
"foods": [
{
"id": 1,
"name": "Banana",
"calories": 10,
"mealsWhenEaten": [
"Breakfast",
"Lunch"
]
},
]
}
]