/tea-time

Tea Subscription Service API

Primary LanguageRuby

Contributors Issues Stargazers Forks Version

Tea Time


Tea time is a JSON API 1.0 spec-compliant REST API built in Rails with endpoints for users to subscribe a customer to a tea subscription, cancel a customer's tea subscription, and to see all of a customer's tea subscriptions (including active and cancelled).

Table of Contents


Contributors

👤 Brian Fletcher


Setup

This project requires Ruby 2.7.2 and Rails 5.2.6.

  • Fork this repository
  • Install gems and set up your database:
    • bundle
    • rails db:{drop,create,migrate,seed}
  • Run the test suite with bundle exec rspec -fd
  • Run your development server with rails s

Project Configurations

  • Ruby Version

    $ ruby -v
    ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
  • System Dependencies

    $ rails -v
    Rails 5.2.6
  • Database Creation

    $ rails db:{drop,create,migrate,seed}
    Created database 'tea-time_development'
    Created database 'tea-time_test'
  • How to Run the Test Suite

    $ bundle exec rspec -fd
  • Local Deployment, for testing and navigating endpoints:

    $ rails s
    => Booting Puma
    => Rails 5.2.6 application starting in development
    => Run `rails server -h` for more startup options
    Puma starting in single mode...
    * Version 3.12.6 (ruby 2.7.2-p137), codename: Llamas in Pajamas
    * Min threads: 5, max threads: 5
    * Environment: development
    * Listening on tcp://localhost:3000
    Use Ctrl-C to stop

Endpoints

The base path of each endpoint in development / testing is:

http://localhost:3000/api/v1
  • For GET requests, you can send the endpoint requests through your internet browser, or utilize an API client (i.e. Postman)
  • For POST and PATCH requests, you will need to use an API client
  • A fully functional Postman collection is included with this repository, to further assist with UAT and endpoint exploration

Subscription Endpoints

Create a new tea subscription for an existing customer
Happy Path

Example Request:

POST /api/v1/customers/{:id}/customer_subscriptions

With the following JSON body:

{
    "tea_id": "5",
    "subscription_id": "2",
}

OR with the following URL for query parameters:

POST /api/v1/customers/{:id}/customer_subscriptions?tea_id=5&subscription_id=2

Example Response:

201 (Created)

{
    "data": {
        "id": "13",
        "type": "customer_subscriptions",
        "attributes": {
            "tea_id": 5,
            "customer_id": 1,
            "subscription_id": 2,
            "active": true
        }
    }
}
Sad Path

Example Request:

POST /api/v1/customers/{:id}/customer_subscriptions

With the following JSON body:

{
    "tea_id": "2",
    "subscription_id": "1500",
}

Example Response

404 (Not Found)

{
    "errors": [
        "Couldn't find Subscription with 'id'=1500"
    ]
}
Show all of a customer's tea subscriptions (active and inactive)
Happy Path

Example request:

GET /api/v1/customers/{:id}/customer_subscriptions

Example Response:

201 (Created)

{
    "data": [
        {
            "id": "1",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 1,
                "customer_id": 1,
                "subscription_id": 1,
                "active": false
            }
        },
        {
            "id": "2",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 2,
                "customer_id": 1,
                "subscription_id": 1,
                "active": true
            }
        },
        {
            "id": "3",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 3,
                "customer_id": 1,
                "subscription_id": 2,
                "active": true
            }
        },
        {
            "id": "4",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 4,
                "customer_id": 1,
                "subscription_id": 2,
                "active": false
            }
        },
        {
            "id": "11",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 1,
                "customer_id": 1,
                "subscription_id": 1,
                "active": true
            }
        },
        {
            "id": "12",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 1,
                "customer_id": 1,
                "subscription_id": 1,
                "active": false
            }
        },
        {
            "id": "13",
            "type": "customer_subscriptions",
            "attributes": {
                "tea_id": 5,
                "customer_id": 1,
                "subscription_id": 2,
                "active": true
            }
        }
    ]
}
Sad Path

Example request:

GET /api/v1/customers/{:bad_id}/customer_subscriptions

Example Response:

{
    "errors": [
        "Couldn't find Customer with 'id'=10000"
    ]
}
Cancel a customer's tea subscription

Example Request:

PATCH /api/v1/customers/{:id}/customer_subscriptions/1

With the following JSON body:

{
    "active": "false",
}

Example Response:

{
    "data": {
        "id": "1",
        "type": "customer_subscriptions",
        "attributes": {
            "tea_id": 1,
            "customer_id": 1,
            "subscription_id": 1,
            "active": false
        }
    }
}

Schema