Mr. Tea is the final take-home challenge for Mod 4 of 4 for Turing School's Back End Engineering Program.
The challenge was to project-plan and build a JSON API 1.0 spec-compliant REST API that models a tea subscription service, which could be consumed by a separate front end web application framework.
Learning goals and areas of focus consisted of:
- Showcasing a strong understanding of
Rails
conventions - Creating
RESTful
routes - Producing well-organized,
object-oriented
code - Utilizing
test-driven development
- Producing clear
documentation
Project specs:
๐ค Taylor Varoglu
- Github: Taylor Varoglu
- LinkedIn: Taylor Varoglu
This project requires Ruby 2.7.2 and Rails 5.2.6.
- Fork and/or clone this repository
- Install gems and set up your database:
$ bundle && bundle update
$ rails db:{create,migrate,seed}
- Run the test suite with
$ bundle exec rspec -fd
- Run your development server with
$ rails s
-
Ruby version:
$ ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
-
$ rails -v Rails 5.2.6
-
Database creation:
$ rails db:{create,migrate,seed} Created database 'mr_tea_development' Created database 'mr_tea_test'
-
How to run the test suite:
$ bundle exec rspec -fd
-
Local deployment, for testing:
$ rails s => Booting Puma => Rails 5.2.6 application starting in development => Run `rails server -h` for more startup options Puma starting in single mode... * Version 3.12.6 (ruby 2.7.2-p137), codename: Llamas in Pajamas * Min threads: 5, max threads: 5 * Environment: development * Listening on tcp://localhost:3000 Use Ctrl-C to stop
The base path
of each endpoint is:
/api/v1
- For
GET
requests, you can send the requests through your internet browser, or utilize an API client (i.e. Postman) - For
POST
orPATCH
requests, you will need to use an API client to provide the required request body - A fully functional Postman collection is included with this repository, to further assist with UAT and endpoint exploration
Get all teas
GET /api/v1/teas
Example Response:
200 (OK)
{
"data": [
{
"id": "5fa3fd48d5ba620017ec1c09",
"type": "tea",
"attributes": {
"name": "green",
"description": "Rich in antioxidants and reduces inflammation.",
"temperature": 80,
"brew_time": 2
}
},
{
"id": "5fa3fdb0d5ba620017ec1c0a",
"type": "tea",
"attributes": {
"name": "black",
"description": "Boosts heart health and lowers cholesterol.",
"temperature": 85,
"brew_time": 3
}
},
{
"id": "5fa3fe47d5ba620017ec1c0b",
"type": "tea",
"attributes": {
"name": "chamomile",
"description": "Lowers blood sugar and prevents osteoporosis.",
"temperature": 93,
"brew_time": 3
}
},
{
"id": "5fa3feb2d5ba620017ec1c0c",
"type": "tea",
"attributes": {
"name": "hibiscus",
"description": "Lowers blood pressure and boosts liver health.",
"temperature": 93,
"brew_time": 3
}
},
{
"id": "5fa3ff13d5ba620017ec1c0d",
"type": "tea",
"attributes": {
"name": "jasmine",
"description": "Relieves stress and helps in weight loss.",
"temperature": 80,
"brew_time": 2
}
},
{
"id": "5fa3ff74d5ba620017ec1c0e",
"type": "tea",
"attributes": {
"name": "mate",
"description": "Boosts energy and mental focus.",
"temperature": 80,
"brew_time": 3
}
},
{
"id": "5fa3ffbbd5ba620017ec1c0f",
"type": "tea",
"attributes": {
"name": "oolong",
"description": "Lowers risk of cancer and prevents diabetes.",
"temperature": 80,
"brew_time": 2
}
},
{
"id": "5fa40008d5ba620017ec1c10",
"type": "tea",
"attributes": {
"name": "pu-erh",
"description": "Protects bone health and reduces stress.",
"temperature": 87,
"brew_time": 3
}
},
{
"id": "5fa40087d5ba620017ec1c11",
"type": "tea",
"attributes": {
"name": "peppermint",
"description": "Relieves headaches and improves digestion.",
"temperature": 93,
"brew_time": 3
}
},
{
"id": "5fa40117d5ba620017ec1c12",
"type": "tea",
"attributes": {
"name": "rooibos",
"description": "Good for heart health, digestion and skin.",
"temperature": 100,
"brew_time": 5
}
}
]
}
Create a new tea subscription for an existing customer
Example Request:
POST /api/v1/customers/{:id}/subscriptions
With the following JSON
body:
{
"title": "yellow",
"description": "Strengthens bones and lowers cholesterol.",
"temperature": 75,
"brew_time": 3,
"tea_id": "5fa402618765bf0017f09759",
"price": 9.5,
"frequency": "Weekly",
"status": "Active",
"customer_id": 3
}
Example Response:
201 (Created)
{
"data": {
"id": "4",
"type": "subscription",
"attributes": {
"customer_id": 3,
"tea_id": "5fa402618765bf0017f09759",
"title": "yellow",
"description": "Strengthens bones and lowers cholesterol.",
"temperature": 75,
"brew_time": 3,
"price": 9.5,
"frequency": "Weekly",
"status": "Active"
}
}
}
Example Request:
POST /api/v1/customers/{:id}/subscriptions
With the following JSON
body:
{}
Example Response:
422 (Unprocessable Entity)
{
"errors": [
"Tea can't be blank",
"Description can't be blank",
"Temperature can't be blank",
"Temperature is not a number",
"Brew time can't be blank",
"Brew time is not a number",
"Price can't be blank",
"Price is not a number",
"Frequency can't be blank",
"Status can't be blank"
]
}
Example Request:
POST /api/v1/customers/foo/subscriptions
Example Response:
404 (Not Found)
{
"errors": [
"Couldn't find Customer with 'id'=foo"
]
}
Cancel an existing tea subscription
Example Request:
PATCH /api/v1/customers/{:customer_id}/subscriptions/{:id}
With the following JSON
body:
{
"status": "Cancelled"
}
Example Response:
200 (OK)
{
"data": {
"id": "4",
"type": "subscription",
"attributes": {
"customer_id": 3,
"tea_id": "5fa402618765bf0017f09759",
"title": "yellow",
"description": "Strengthens bones and lowers cholesterol.",
"temperature": 75,
"brew_time": 3,
"price": 9.5,
"frequency": "Weekly",
"status": "Cancelled"
}
}
}
Example Request:
PATCH /api/v1/customers/{:customer_id}/subscriptions/{:id}
With the following JSON
body:
{
"status": "Foo"
}
Example Response:
422 (Unprocessable Entity)
{
"errors": [
"'Foo' is not a valid status"
]
}
Example Request:
PATCH /api/v1/customers/{:customer_id}/subscriptions/bar
Example Response:
404 (Not Found)
{
"errors": [
"Couldn't find Subscription with 'id'=bar"
]
}
Get all tea subscriptions for an existing customer
Example Request:
GET /api/v1/customers/{:id}/subscriptions
Example Response:
200 (OK)
{
"data": [
{
"id": "4",
"type": "subscription",
"attributes": {
"customer_id": 3,
"tea_id": "5fa402618765bf0017f09759",
"title": "yellow",
"description": "Strengthens bones and lowers cholesterol.",
"temperature": 75,
"brew_time": 3,
"price": 9.5,
"frequency": "Weekly",
"status": "Active"
}
},
{
"id": "5",
"type": "subscription",
"attributes": {
"customer_id": 3,
"tea_id": "5fa402618765bf0017f09759",
"title": "yellow",
"description": "Strengthens bones and lowers cholesterol.",
"temperature": 75,
"brew_time": 3,
"price": 9.5,
"frequency": "Weekly",
"status": "Cancelled"
}
}
]
}
- T-API:
- Created by Victoria Lo, this API feeds the
Tea
data behind the mockSubscription
data for eachCustomer
- Created by Victoria Lo, this API feeds the