Skip to content

zeeshan-haidar/tea_subscription_api

 
 

Repository files navigation

README - Tea Subscription API

Overview

This is a Rails API for a Tea Subscription Service that has built several endpoints for Customers and their Tea Subscriptions.

🍵 Technologies Used:


Postgres

Git

🍵 Database Schema:

This database was designed with the intention of Teas and Customers being linked via a Subscription joins table. Customers are able to subscribe or cancel a tea subscription, without any effect on the Tea database. Subscriptions can be updated to be canceled without having to permanently remove the Subscription from the database. The business logic here would allow a Customer to easily activate their subscription at a later point.

Screen-Shot-2022-11-09-at-1-03-55-PM.png

🍵 API Endpoints:

All SUBSCRIPTIONS for a single CUSTOMER (active AND canceled):

GET /api/v1/customers/$id/subscriptions

  "data": [
      { 
          "id": "1",
          "type": "subscription"
          "attributes": { 
                  "title": "Stress Buster", 
                  "price": 15.25, 
                  "status": "active", 
                  "frequency": "canceled", 
                  "customer_id": 1, 
                  "tea_id": 1 
                  }, 
                      {
            "id": "5",
            "type": "subscription",
            "attributes": {
                "title": "Sleepy Time",
                "price": 10.15,
                "status": "active",
                "frequency": "weekly",
                "customer_id": 1,
                "tea_id": 1
            }
        }]

Screen-Shot-2022-11-09-at-1-22-33-PM.png

CREATE SUBSCRIPTION for a single CUSTOMER:

POST /api/v1/subscriptions

params inside JSON body: title, price, status, frequency, customer_id, tea_id

    {
    "data": {
        "id": "7",
        "type": "subscription",
        "attributes": {
            "title": "Sleepy Time",
            "price": 10.15,
            "status": "active",
            "frequency": "weekly",
            "customer_id": 1,
            "tea_id": 1
        }
    }
}

Screen-Shot-2022-11-09-at-1-24-25-PM.png

UPDATE(cancel) SUBSCRIPTION for a single CUSTOMER:

PATCH /api/v1/subscriptions/remove?$id

params { $id, "status": "canceled" }

{
    "data": {
        "id": "6",
        "type": "subscription",
        "attributes": {
            "title": "Sleepy Time",
            "price": 10.15,
            "status": "canceled",
            "frequency": "weekly",
            "customer_id": 1,
            "tea_id": 1
        }
    }
}

Screen-Shot-2022-11-09-at-1-25-42-PM.png

🍵 Local Setup

  1. Fork and clone the repo to your local machine
  2. Install gems and dependencies: bundle install
  3. Set up database: rails db:{drop,create,migrate,seed}
  4. Run test suite: bundle exec rspec (100% SimpleCov testing coverage)
  5. Start up your local server: rails s
  6. Visualize the endpoints in Postman
    GET http://localhost:3000/api/v1/customers/{{customer_id}}/subscriptions
    POST http://localhost:3000/api/v1/subscriptions
    PATCH http://localhost:3000/api/v1/subscriptions/remove?id={{id}}

About

Mod 4 Take Home Challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Ruby 99.4%
  • HTML 0.6%