Table of Contents
3.1.1
7.0.4
Postgres 14
To run the application locally, this repository will need to be cloned and set up fully with required gems.
-
Clone the repo:
git@github.com:4D-Coder/tea_subscription_api.git
-
Install gems:
bundle install
-
To establish the database, run:
rails db:create
-
To migrate the database configurations into your local development and test environment, run:
rails db:migrate
Inspect the /db/schema.rb
and compare to the 'Schema' section below to ensure this migration has been done successfully.
Once tea_subscription_api
is correctly installed, run tests locally to ensure the repository works as intended.
To test the entire RSpec suite, run:
bundle exec rspec
All tests should be passing if the installation was successful.
If any tests are not passing, please report which tests are not passing Here.
-
This API can be called locally using a program like Postman.
-
Note: Necessary parameters marked with {}
POST /api/v1/customers/:id/subscriptions
Request:
{
"title": "Power of Insight",
"total_price": 60,
"status": "Active",
"frequency": "Weekly",
"teas": [
{
"tea_id": 2
},
{etc...
}
]
}
Code | Description |
---|---|
201 | Created |
Response:
{
"data": {
"id": "1",
"type": "subscription",
"attributes": {
"title": "Power of Insight",
"total_price": 60,
"status": "Active",
"frequency": "Weekly",
"teas": [
{
"id": 2,
"title": "Neurogenesis",
"description": "smooth brain",
"temperature": 100,
"brew_time": 120,
"unit_price": 5
},
{etc...
}
],
},
},
}
Notes:
- If subscription data is included in the content of the request, I assume that the subscription is something that is customized by the customer, and is only created alongside an tea that comes from the database (or service) that they’ve selected.
- I also assume that additional teas can be added to this same subscription later
- If there isnt a tea in the request body, throw an error
- In the subscription controller, we will create the subscription and return it as an object with an id
- For the response body, I’m assuming that once a customer has been successfully subscribed, the content will hold information for the front end to render a cusomer’s subscription details.
PATCH /api/v1/customer/:id/subscriptions/:ids
Request:
{
"title": "Power of Insight",
"total_price": 60,
"status": "Active",
"frequency": "Weekly",
"teas": [
{
"tea_id": 2
},
{etc...
}
]
}
Code | Description |
---|---|
200 | OK |
Parameters:
CONTENT_TYPE=application/json
Request:
{
"status": "Cancelled"
}
Response:
{
"data": {
"id": "1",
"type": "subscription",
"attributes": {
"title": "Art of Tea",
"price": 40,
"status": "Cancelled",
"frequency": "Monthly",
"teas": [{
"id": 1,
"title": "Oolong",
"description": "tis very nice",
"temperature": 150,
"brew_time": 90,
"unit_price": 8
},
{tea2...
}]
}
}
}
Notes:
- Response body assumes that the frontend would want to show the user that cancelled subscription info with an updated status of cancelled.
- GET method will need to show both active and cancelled subscriptions, so a status change on the subscription record also needs to happen with the change
- Originally this method was a DELETE , but I found it pertinent to preserve data, so that a hypothetical business can see all subscriptions that are active and inactive, along with a record of what teas were being purchased .
GET /api/v1/customer/:id/subscriptions
Request:
{
"title": "Power of Insight",
"total_price": 60,
"status": "Active",
"frequency": "Weekly",
"teas": [
{
"tea_id": 2
},
{etc...
}
]
}
Code | Description |
---|---|
200 | OK |
Parameters:
CONTENT_TYPE=application/json
Request:
No Parameters
Response:
{
"data": [
{
"id": "1",
"type": "subscription",
"attributes": {
"title": "Art of Tea",
"price": 40,
"status": "Active",
"frequency": "Monthly",
"teas": [
{
"id": 1,
"title": "Oolong",
"description": "tis very nice",
"temperature": 150,
"brew_time": 90,
"unit_price": 9
},
{etc...}
],
},
},
{
"id": "2",
"type": "subscription",
"attributes": {
"title": "Power of Insight",
"price": 60,
"status": "Cancelled",
"frequency": "Weekly",
"teas": [
{
"id": 2,
"title": "Neurogenesis",
"description": "smooth brain",
"temperature": 100,
"brew_time": 120,
"unit_price": 20
},
{etc...}
],
},
},
]
}
Notes:
- Much like when someone starts a subscription, I assume we will want to see all subscriptions (active or cancelled)
See the take-home requirements here.
- Exhibit a strong understanding of rails.
- A strong understanding of Rails
- Ability to create restful routes
- Demonstration of well-organized code, following OOP
- Test Driven Development
- Clear documentation
GitHub
Antonio King Hunt |