Rails API for a Tea Subscription Service with the following endpoints:
- An endpoint to subscribe a customer to a tea subscription
- An endpoint to cancel a customer’s tea subscription
- An endpoint to see all of a customer’s subsciptions (active and cancelled)
Completion of this take home challenge requires the following:
- A strong understanding of Rails
- Ability to create restful routes
- Demonstration of well-organized code, following OOP
- Test Driven Development
- Clear documentation
Built with:
- Ruby 2.7.4
- Rails 5.2.8.1
- RSpec 3.11
- Ensure that you have the prerequisites or equivalent
- Clone this repo and navigate to the root folder
cd tea-subscription
- Run
bundle install
- Run
rails db:{drop,create,migrate,seed}
- (Optional) To run the test suite, run
bundle exec rspec
- Run
rails s
You should now be able to hit the API endpoints using Postman.
Default host is http://localhost:3000
-
Required Params
title
,price
,frequency
,tea_id
, andcustomer_id
- Send required data in JSON format in the body of the request as displayed in the example below
-
Example Request
POST http://localhost:3000/api/v1/customers/1/subscriptions
body: { "title": "Green Tea", "price": 2.99, "frequency": "weekly", "tea_id": 1, "customer_id": 1 }
-
Example Response
{ "data": { "id": 3, "type": "subscription", "attributes": { "title": "Green Tea", "price": 2.99, "status": "active", "frequency": "weekly", "customer_id": 1, "tea_id": 1 } } }
- Required Params
- status: 'inactive'
- Example Request
PATCH http://localhost:3000/api/v1/customers/1/subscriptions/1
- Does not remove record, just changes status to inactive.
- Example Response
{ "data": { "id": 3, "type": "subscription", "attributes": { "title": "Green Tea", "price": 2.99, "status": "inactive", "frequency": "weekly", "customer_id": 1, "tea_id": 1 } } }
- Required Params
- N/A
- Example Request
GET http://localhost:3000/api/v1/customers/2/subscriptions
- Example Response
{ "data": [ { "id": "1", "type": "subscription", "attributes": { "title": "Green Tea", "price": 2.99, "status": "inactive", "frequency": "weekly", "tea_id": 1, "customer_id": 1 } } { "id": "2", "type": "subscription", "attributes": { "title": "Chai Tea", "price": 5.35, "status": "active", "frequency": "weekly", "tea_id": 2, "customer_id": 2 } } ] }