Github CI codecov Ruby Style Guide

Tea Party API

This REST API is a partial design of a back end for a tea subscription service. It offers clients the ability to send request to get all subscriptions for a customer, create a new customer subscription, or deactivate a customer subscription.

Built with

Rails 5.2.8.1
Ruby 2.7.4
RSpec 3.1.2
PostgreSQL

Setup

  1. Fork and clone this repository
  2. cd into the root directory
  3. Run bundle install
  4. Run rails db:{drop,create,migrate} to setup the databases
  5. Run bundle exec rspec to run the test suite
  6. Run rails server to start the rails server at http://localhost:3000
  • Example of requests you can send are available below

API Endpoints

Get all subscriptions for a given customer

Request

get '/api/v1/subscriptions'

Body

{ "customer_id" = "1" }

Response

{
"data": [
    {
        "id": "1",
        "type": "subscription",
        "attributes": {
            "title": "Hibiscus",
            "price": 6.81,
            "active": false,
            "frequency": "quarterly",
            "customer_id": 1,
            "tea_id": 9,
            "created_at": "2023-04-13T00:49:06.976Z",
            "updated_at": "2023-04-13T00:49:06.976Z"
        }
    },
    {
        "id": "10",
        "type": "subscription",
        "attributes": {
            "title": "Che Dang",
            "price": 58.74,
            "active": true,
            "frequency": "monthly",
            "customer_id": 1,
            "tea_id": 3,
            "created_at": "2023-04-13T00:49:07.019Z",
            "updated_at": "2023-04-13T00:49:07.019Z"
        }
    },
    {
        "id": "19",
        "type": "subscription",
        "attributes": {
            "title": "Shui Xian",
            "price": 17.71,
            "active": true,
            "frequency": "quarterly",
            "customer_id": 1,
            "tea_id": 10,
            "created_at": "2023-04-13T00:49:07.055Z",
            "updated_at": "2023-04-13T00:49:07.055Z"
          }
      }
    ]
  }

Create a new subscription for a given customer

Request

post '/api/v1/subscriptions'

Body

{
    "title": 'Test Tea Subscription',
    "price": 5.99,
    "frequency": 1,
    "customer_id": 5,
    "tea_id": 10
  }

Response

{
  "success": "Subscription added successfully"
}

Deactivate a customer subscription

Request

patch '/api/v1/subscriptions/<subscription_id>'

Body

{ "customer_id" : "1" }

Response

{
  "data": {
      "id": "4",
      "type": "subscription",
      "attributes": {
          "title": "Darjeeling",
          "price": 20.65,
          "active": false,
          "frequency": "quarterly",
          "customer_id": 1,
          "tea_id": 6,
          "created_at": "2023-04-13T19:21:00.526Z",
          "updated_at": "2023-04-13T21:07:12.001Z"
          }
      }
 }

Database Diagram

Database schema