Skip to content

kdhubb/tea_to_you_api

Repository files navigation

Tea to You

This is a RESTful API service for a tea subscription application. In this MVP, there are three endpoints exposed, one to subscribe a customer to a new tea subscription, one to cancel a subscription, and one to get all of a customer's subscriptions. This project was completed as a "take home" practice project as part of the Mod 4 curriculum at Turing School of Software and Design.


Tech Stack

Ruby, Rails, ActiveRecord, PostgreSQL, SimpleCov, RSpec

PostgreSQL Rails CSS3

Usage

To Setup Install:

  • Ruby 3.2.2
  • Rails 7.0.7
  • Fork and clone

Then run:

  • bundle install
  • rails db:{create,migrate,seed}

JSON Contract

Subscribe a customer to a tea subscription

POST '/api/v1/subscriptions' JSON Body:

{
  "customer_id":"integer",
  "title":"string",
  "price":"float",
  "frequency":"string",
  "teas": [
    {
      "tea_id":"integer"
    },
    {
      "tea_id":"integer"
    }
  ] 
}

Example response:

{
  "data": {
    "id":"integer",
    "type":"subscription",
    "attributes": {
      "customer_id":"integer",
      "title":"string",
      "price":"float",
      "status":"active",
      "frequency":"string"
      "teas": [
        {
          "tea_id":"integer"
        },
        {
          "tea_id":"integer"
        }
      ] 
    }
  }
}

Cancel a customer's tea subscription

PATCH '/api/v1/subscriptions/id'

(The id in the route above is the subscription id)

JSON Body:

{
  "customer_id":"integer",
  "status":"cancelled"
}

Example response:

{
    "data": {
        "id": "27",
        "type": "subscription",
        "attributes": {
            "customer_id": 115,
            "title": "Grandma's Tea",
            "price": 17.0,
            "status": "cancelled",
            "frequency": "monthly",
            "teas": [
                {
                    "tea_id": 14
                },
                {
                    "tea_id": 8
                }
            ]
        }
    }
}

See all of a customer's subscriptions

GET '/api/v1/subscriptions'

JSON Body:

{
  "customer_id":"integer"
}

Example response:

{
  "data":[
    {
      "id":"integer",
      "type":"subscription",
      "attributes": {
        "customer_id":"integer",
        "title":"string",
        "price":"float",
        "status":"active",
        "frequency":"string"
        "teas": [
          {
            "tea_id":"integer"
          },
          {
            "tea_id":"integer"
          }
        ] 
      }
    },
    {
      "id":"integer",
      "type":"subscription",
      "attributes": {
        "customer_id":"integer",
        "title":"string",
        "price":"float",
        "status":"active",
        "frequency":"string"
        "teas": [
          {
            "tea_id":"integer"
          },
          {
            "tea_id":"integer"
          }
        ] 
      }
    }
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published