This is a Rails API for a Tea Subscription Service that has built several endpoints for Customers and their Tea Subscriptions.
This database was designed with the intention of Teas and Customers being linked via a Subscription joins table. Customers are able to subscribe or cancel a tea subscription, without any effect on the Tea database. Subscriptions can be updated to be canceled without having to permanently remove the Subscription from the database. The business logic here would allow a Customer to easily activate their subscription at a later point.
All SUBSCRIPTIONS for a single CUSTOMER (active AND canceled):
GET
/api/v1/customers/$id/subscriptions
"data": [
{
"id": "1",
"type": "subscription"
"attributes": {
"title": "Stress Buster",
"price": 15.25,
"status": "active",
"frequency": "canceled",
"customer_id": 1,
"tea_id": 1
},
{
"id": "5",
"type": "subscription",
"attributes": {
"title": "Sleepy Time",
"price": 10.15,
"status": "active",
"frequency": "weekly",
"customer_id": 1,
"tea_id": 1
}
}]
CREATE SUBSCRIPTION for a single CUSTOMER:
POST
/api/v1/subscriptions
params
inside JSON body: title, price, status, frequency, customer_id, tea_id
{
"data": {
"id": "7",
"type": "subscription",
"attributes": {
"title": "Sleepy Time",
"price": 10.15,
"status": "active",
"frequency": "weekly",
"customer_id": 1,
"tea_id": 1
}
}
}
UPDATE(cancel) SUBSCRIPTION for a single CUSTOMER:
PATCH
/api/v1/subscriptions/remove?$id
params
{ $id, "status": "canceled" }
{
"data": {
"id": "6",
"type": "subscription",
"attributes": {
"title": "Sleepy Time",
"price": 10.15,
"status": "canceled",
"frequency": "weekly",
"customer_id": 1,
"tea_id": 1
}
}
}
- Fork and clone the repo to your local machine
- Install gems and dependencies:
bundle install
- Set up database:
rails db:{drop,create,migrate,seed}
- Run test suite:
bundle exec rspec
(100%SimpleCov
testing coverage) - Start up your local server:
rails s
- Visualize the endpoints in Postman
GEThttp://localhost:3000/api/v1/customers/{{customer_id}}/subscriptions
POSThttp://localhost:3000/api/v1/subscriptions
PATCHhttp://localhost:3000/api/v1/subscriptions/remove?id={{id}}