- Take Home challenge in which the task was to expose three endpoints of a sample tea subscription service
- Explores a many to many relationship, where Customers have many Teas through Subscriptions, and vice versa
- Sad path testing and functionality
- Expose an API for CRUD functionality
- Available Endpoints:
Create Subscription
- This endpoint creates a subscription
[GET] /api/v1/customers/1/subscriptions
Example:
[POST] /api/v1/customers/#{customer.id}/subscriptions?tea_id=2&title=first_subscription&price=50 dollars&frequency=monthly
RESPONSE:
{
"data": {
"id": "2",
"type": "subscription",
"attributes": {
"title": "first_subscription",
"price": "50 dollars",
"status": "active",
"frequency": "monthly"
}
}
}
Cancel Subscription
- This endpoint cancels a subscription
[PATCH] /api/v1/customers/#{customer.id}/subscriptions/#{subscription.id}
Example:
[PATCH] /api/v1/customers/1/subscriptions/1?status=cancelled
RESPONSE:
{
"data": {
"id": "1",
"type": "subscription",
"attributes": {
"title": "first_subscription",
"price": "40 dollars",
"status": "cancelled",
"frequency": "weekly"
}
}
}
Subscription Index
- This endpoint shows all subscription of a given user
[GET] /api/v1/customers/#{customer.id}/subscriptions
Example:
[GET] /api/v1/customers/1/subscriptions
RESPONSE:
{
"data": [
{
"id": "1",
"type": "subscription",
"attributes": {
"title": "first_subscription",
"price": "40 dollars",
"status": "cancelled",
"frequency": "weekly"
}
},
{
"id": "2",
"type": "subscription",
"attributes": {
"title": "first_subscription",
"price": "50 dollars",
"status": "active",
"frequency": "monthly"
}
}
]
}
- Clone this directory to your local repository using the SSH key:
$ git clone git@github.com:jimriddle1/tea_subscription.git
- Install gems for development using Bundler:
$ bundle install
- Set up your database with:
$ rails db:{drop,create,migrate}
- Run the test suite with:
$ bundle exec rspec
- Run your development server with:
$ rails s