This is a Rails API for a Tea Subscription service. The API allows you to manage customers, teas, and subscriptions.
- Ruby 3.2.2
- Rails 7.0.8
- PostgreSQL 14.9
Testing Only:
- rspec-rails 5.1.2
- shoulda-matchers 5.3.0
- simplecov 0.22.0
-
Clone the repository
git clone https://github.com/MWoodshop/takehome_tea.git
-
Navigate to the project directory
cd takehome_tea
-
Install dependencies
bundle install
-
Setup database
rails db:create db:migrate
/api/v0
Get All Customers
URL: /customers
Method: GET
Response:
[
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "joe@example.com",
"address": "123 Main St, Anytown, OH, 12345",
"created_at": "2023-10-31T20:30:34.889Z",
"updated_at": "2023-10-31T20:30:34.889Z"
},
{
"id": 2,
"first_name": "Jane",
"last_name": "Smith",
"email": "jsmith@example.com",
"address": "456 Main St, Howell, NJ, 07731",
"created_at": "2023-10-31T20:30:34.890Z",
"updated_at": "2023-10-31T20:30:34.890Z"
}
]
Get a Specific Customer
URL: /customers/:customer_id
Method: GET
Response:
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "joe@example.com",
"address": "123 Main St, Anytown, OH, 12345",
"created_at": "2023-10-31T20:30:34.889Z",
"updated_at": "2023-10-31T20:30:34.889Z"
}
Create New Customer
URL: /customers
Method: POST
Request:
{
"first_name": "Cameron",
"last_name": "Diaz",
"email": "cdiaz@hollywood.com",
"address": "123 Hollywood Blvd., Hollywood, CA, 90210"
}
Response:
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "joe@example.com",
"address": "123 Main St, Anytown, OH, 12345",
"created_at": "2023-10-31T20:30:34.889Z",
"updated_at": "2023-10-31T20:30:34.889Z"
}
Edit an Existing Customer
URL: /customers/:customer_id
Method: PUT or PATCH
Request:
{
"first_name": "NewerCameron"
}
Response:
{
"first_name": "NewerCameron",
"id": 4,
"last_name": "Diaz",
"email": "cdiaz@hollywood.com",
"address": "123 Hollywood Blvd., Hollywood, CA, 90210",
"created_at": "2023-11-03T15:27:09.326Z",
"updated_at": "2023-11-03T15:30:45.442Z"
}
Delete a Customer
URL: /customers/:customer_id
Method: DELETE
Response:
{
"message": "Customer removed successfully"
}
Get All Teas
URL: /teas
Method: GET
Response:
[
{
"id": 1,
"title": "Green Tea",
"description": "A tea made from unoxidized leaves.",
"temperature": 80,
"brewtime": 120,
"created_at": "2023-10-31T20:30:34.881Z",
"updated_at": "2023-10-31T20:30:34.881Z"
},
{
"id": 2,
"title": "Black Tea",
"description": "Fully oxidized, black tea is the most popular type of tea.",
"temperature": 100,
"brewtime": 300,
"created_at": "2023-10-31T20:30:34.882Z",
"updated_at": "2023-10-31T20:30:34.882Z"
}
]
Get a Specific Tea
URL: /teas/:tea_id
Method: GET
Response:
{
"id": 1,
"title": "Green Tea",
"description": "A tea made from unoxidized leaves.",
"temperature": 80,
"brewtime": 120,
"created_at": "2023-10-31T20:30:34.881Z",
"updated_at": "2023-10-31T20:30:34.881Z"
}
Create New Tea
URL: /teas
Method: POST
Request:
{
"title": "Blue Tea",
"description": "Made with Star Wars Blue Milk!",
"temperature": 90,
"brewtime": 120
}
Response:
{
"id": 5,
"title": "Blue Tea",
"description": "Made with Star Wars Blue Milk!",
"temperature": 90,
"brewtime": 120,
"created_at": "2023-11-03T15:39:55.263Z",
"updated_at": "2023-11-03T15:39:55.263Z"
}
Edit an Existing Tea
URL: /teas/:tea_id
Method: PUT or PATCH
Request:
{
"title": "Newer Tea Title"
}
Response:
{
"title": "Newer Tea Title",
"id": 1,
"description": "A tea made from unoxidized leaves.",
"temperature": 80,
"brewtime": 120,
"created_at": "2023-10-31T20:30:34.881Z",
"updated_at": "2023-11-03T15:40:27.226Z"
}
Delete a Tea
URL: /teas/:tea_id
Method: DELETE
Response:
{
"message": "Tea removed successfully"
}
Get All Subscriptions
URL: /subscriptions
Method: GET
Response:
[
{
"id": 2,
"title": "Black Tea Subscription",
"price": "12.5",
"frequency": "weekly",
"created_at": "2023-10-31T20:30:34.896Z",
"updated_at": "2023-10-31T20:30:34.896Z"
},
{
"id": 3,
"title": "Green Tea Subscription",
"price": "13.0",
"frequency": "weekly",
"created_at": "2023-10-31T20:30:34.897Z",
"updated_at": "2023-10-31T20:30:34.897Z"
}
]
Get a Specific Subscription
URL: /subscriptions/:subscription_id
Method: GET
Response:
{
"id": 1,
"title": "Green Tea Subscription",
"price": "16.0",
"frequency": "monthly",
"created_at": "2023-10-31T20:30:34.895Z",
"updated_at": "2023-11-02T16:13:42.646Z"
}
Create New Subscription
URL: /subscriptions
Method: POST
Request:
{
"title": "New Test Subscription",
"price": 15.00,
"frequency": "monthly"
}
Response:
{
"id": 5,
"title": "New Test Subscription",
"price": "15.0",
"frequency": "monthly",
"created_at": "2023-11-03T15:42:42.431Z",
"updated_at": "2023-11-03T15:42:42.431Z"
}
Edit an Existing Subscription
URL: /subscriptions/:subscription_id
Method: PUT or PATCH
Request:
{
"price": 16.00,
"frequency": "monthly"
}
Response:
{
"price": "16.0",
"frequency": "monthly",
"id": 1,
"title": "Green Tea Subscription",
"created_at": "2023-10-31T20:30:34.895Z",
"updated_at": "2023-11-02T16:13:42.646Z"
}
Delete a Subscription
URL: /subscriptions/:subscription_id
Method: DELETE
Response:
{
"message": "Subscription removed successfully"
}
Get All Teas by Subscription
URL: /subscriptions/:subscription_id/teas
Method: GET
Response:
[
{
"id": 2,
"title": "Black Tea",
"description": "Fully oxidized, black tea is the most popular type of tea.",
"temperature": 100,
"brewtime": 300,
"created_at": "2023-10-31T20:30:34.882Z",
"updated_at": "2023-10-31T20:30:34.882Z"
},
{
"id": 3,
"title": "Oolong Tea",
"description": "Partially oxidized, Oolong has qualities of both green and black tea.",
"temperature": 85,
"brewtime": 240,
"created_at": "2023-10-31T20:30:34.884Z",
"updated_at": "2023-10-31T20:30:34.884Z"
}
]
Add Tea to Subscription
URL: /subscriptions/:subscription_id/teas/:tea_id
Method: POST
Response:
{
"message": "Tea added to subscription successfully"
}
Remove a Tea from Subscription
URL: /subscriptions/:subscription_id/teas/:tea_id
Method: DELETE
Response:
{
"message": "Tea removed from subscription successfully"
}
Get All Subscriptions by Customer (both active and inactive)
URL: /customers_subscriptions/by_customer/:customer_id
Method: GET
Response:
[
{
"id": 1,
"customer_id": 1,
"subscription_id": 1,
"created_at": "2023-10-31T20:30:34.938Z",
"updated_at": "2023-10-31T20:30:34.938Z",
"status": "active"
},
{
"id": 2,
"customer_id": 1,
"subscription_id": 2,
"created_at": "2023-10-31T20:30:34.941Z",
"updated_at": "2023-10-31T20:30:34.941Z",
"status": "active"
},
{
"id": 3,
"customer_id": 1,
"subscription_id": 3,
"created_at": "2023-10-31T20:30:34.943Z",
"updated_at": "2023-10-31T20:30:34.943Z",
"status": "active"
},
{
"id": 4,
"customer_id": 1,
"subscription_id": 4,
"created_at": "2023-10-31T20:30:34.945Z",
"updated_at": "2023-11-01T20:40:41.259Z",
"status": "inactive"
}
]
Get All Customers by Subscription
URL: /customers_subscriptions/by_subscription/:subscription_id
Method: GET
Response:
[
{
"id": 1,
"customer_id": 1,
"subscription_id": 1,
"created_at": "2023-10-31T20:30:34.938Z",
"updated_at": "2023-10-31T20:30:34.938Z",
"status": "active"
},
{
"id": 5,
"customer_id": 2,
"subscription_id": 1,
"created_at": "2023-10-31T20:31:16.509Z",
"updated_at": "2023-11-02T16:09:07.336Z",
"status": "inactive"
}
]
Add a Customer to a Subscription
URL: /customers_subscriptions/:customer_id/:subscription_id
Method: POST
Response:
{
"status": "active",
"id": 5,
"customer_id": 2,
"subscription_id": 1,
"created_at": "2023-10-31T20:31:16.509Z",
"updated_at": "2023-11-03T15:52:28.782Z"
}
Remove a Customer from a Subscription
URL: /customers_subscriptions/:customer_id/:subscription_id/cancel
Method: POST
Response:
{
"message": "Subscription cancelled successfully"
}
To run the test suite, execute
bundle exec rspec