https://github.com/margdaly/tea_subscription
A REST API for a Tea Subscription Service
https://github.com/margdaly/tea_subscription
postgresql-database rails restful-api ruby subscription tea
Last synced: about 1 month ago
JSON representation
A REST API for a Tea Subscription Service
- Host: GitHub
- URL: https://github.com/margdaly/tea_subscription
- Owner: margdaly
- Created: 2023-08-05T21:59:44.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-25T18:12:36.000Z (about 2 years ago)
- Last Synced: 2024-08-23T20:13:28.946Z (about 1 year ago)
- Topics: postgresql-database, rails, restful-api, ruby, subscription, tea
- Language: Ruby
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Tea Subscription API ☕
![]()
## Project Goals
Create a REST API for a Tea Subscription Service
- Easily consumed by a Frontend Developer
- Restful routes
- Well-organized code, following OOP
- Test Driven DevelopmentExposes three endpoints to manage tea subscriptions
- subscribe a customer to a tea subscription
- cancel a customer's tea subscription
- see all of a customer's subscriptions (active and cancelled)## Built With
* Ruby v 2.7.4
* Rails v 5.2.8
* PostgreSQL## Getting Started
1. Fork and Clone this repository locally
2. Install gem packages
`bundle install`
4. Set up the database
`rails db:{drop,create,migrate,seed}`
4. Make sure all tests are passing by running
`bundle exec rspec`
5. Start up your local server by running
`rails s`
6. You can make the sample request for each endpoint by running the examples in [Postman](https://app.getpostman.com/run-collection/26085409-1cb627ef-d500-4f6f-b849-9b655205c7ed?action=collection%2Ffork&collection-url=entityId%3D26085409-1cb627ef-d500-4f6f-b849-9b655205c7ed%26entityType%3Dcollection%26workspaceId%3Df402ed1d-531c-4451-ad21-b6367689bff9).
## Database Diagram
## Endpoints
### POST `/api/v0/subscribe`
success
**create a new subscription****Parameters**
| Name | Type | Description |
| ----------- | ----------- | ----------- |
| **customer_id** | number | customer's id |
| **tea_id** | number | tea's id |
| **frequency** | 'weekly', 'monthly', or 'seasonal' | how often |**Request**
```json
{
"customer_id": 3,
"tea_id": 6,
"frequency": "monthly"
}
```
**Response**
status **200**
```
{
"data": {
"id": "13",
"type": "subscription",
"attributes": {
"customer_id": 3,
"tea_id": 6,
"title": "Sleepytime Tea",
"price": "$49.56",
"status": "active",
"frequency": "monthly"
}
}
}
```error
**Invalid Tea ID**
**Request**
```json
{
"customer_id": 3,
"tea_id": 0,
"frequency": "monthly"
}
```
**Response**
status **404**
```
{
"errors": [
{
"status": "404",
"title": "Record Invalid",
"detail": "Validation failed: Tea must exist"
}
]
}
```### PATCH `/api/v0/cancel`
success
**cancel a subscription****Parameters**
| Name | Type | Description |
| ----------- | ----------- | ----------- |
| **customer_id** | number | customer's id |
| **tea_id** | number | tea's id |**Request**
```json
{
"customer_id": 1,
"tea_id": 1
}
```
**Response**
status **200**
```
{
"data": {
"id": "1",
"type": "subscription",
"attributes": {
"customer_id": 1,
"tea_id": 1,
"title": "Green Tea",
"price": "$49.56",
"status": "cancelled",
"frequency": "monthly"
}
}
}
```error
**Invalid Customer ID**
**Request**
```json
{
"customer_id": 0,
"tea_id": 1
}
```
**Response**
status **404**
```
{
"errors": [
{
"status": "404",
"title": "Record Invalid",
"detail": "Couldn't find Subscription"
}
]
}
```### GET `/api/v0/customers/:id
success
**get customer details****Response**
status **200**
```
{
"data": {
"id": "2",
"type": "customer",
"attributes": {
"first_name": "Harriet",
"last_name": "Murphy",
"email": "haphy@mail.com",
"address": "24 Beachwood Ave",
"subscriptions": [
{
"id": 7,
"title": "Mint Tea",
"price": "$49.56",
"status": "active",
"frequency": "monthly",
"customer_id": 2,
"tea_id": 4,
"created_at": "2023-08-06T17:43:10.359Z",
"updated_at": "2023-08-06T17:43:10.359Z"
},
{
"id": 8,
"title": "Chamomile Tea",
"price": "$49.56",
"status": "active",
"frequency": "monthly",
"customer_id": 2,
"tea_id": 5,
"created_at": "2023-08-06T17:43:10.360Z",
"updated_at": "2023-08-06T17:43:10.360Z"
},
{
"id": 9,
"title": "Sleepytime Tea",
"price": "$214.76",
"status": "cancelled",
"frequency": "weekly",
"customer_id": 2,
"tea_id": 6,
"created_at": "2023-08-06T17:43:10.361Z",
"updated_at": "2023-08-06T17:43:10.361Z"
}
]
}
}
}
```error
**Invalid Customer ID**
**Response**
status **404**
```
{
"errors": [
{
"status": "404",
"title": "Record Invalid",
"detail": "Couldn't find Customer with 'id'=0"
}
]
}
```