Code Monkey home page Code Monkey logo

tea_time's Introduction

Tea Time

Table of Contents

Getting Started

Versions

  • Ruby: 3.2.2
  • Rails: 7.1.3

Project Description

Tea Time is a simple API that lets you start and cancel a tea subscription for a customer and retrieve all tea subscriptions that a customer has had.

This app was designed and built by myself as part of the intermission work, from Turing School of Software and Design.

Key Skills to Demonstrate
  • A strong understanding of Rails
  • Ability to create restful routes
  • Demonstration of well-organized code, following OOP
  • Test Driven Development
  • Clear documentation
Setup
  1. Fork and/or Clone this Repo from GitHub.
  2. In your terminal use $ git clone <ssh or https path>.
  3. Change into the cloned directory using $ cd example.
  4. Install the gem packages using $ bundle install.
  5. Database Migrations can be set up by running:
$ rails db:{drop,create,migrate,seed}
Testing

Test using the terminal utilizing RSpec:

$ bundle exec rspec spec/<follow directory path to test specific files>

or test the whole suite with $ bundle exec rspec

Test Results as of 6/29/24: 100.0%

Database Schema
ActiveRecord::Schema[7.1].define(version: 2024_06_27_232609) do
  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "customer_subscriptions", force: :cascade do |t|
    t.bigint "customer_id", null: false
    t.bigint "subscription_id", null: false
    t.integer "status", default: 1
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["customer_id"], name: "index_customer_subscriptions_on_customer_id"
    t.index ["subscription_id"], name: "index_customer_subscriptions_on_subscription_id"
  end

  create_table "customers", force: :cascade do |t|
    t.string "first_name"
    t.string "last_name"
    t.string "email"
    t.string "address"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.index ["email"], name: "index_customers_on_email", unique: true
  end

  create_table "subscriptions", force: :cascade do |t|
    t.string "title"
    t.integer "price"
    t.integer "status"
    t.integer "frequency"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  create_table "teas", force: :cascade do |t|
    t.string "title"
    t.string "description"
    t.integer "temperature"
    t.integer "brew_time"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

  add_foreign_key "customer_subscriptions", "customers"
  add_foreign_key "customer_subscriptions", "subscriptions"
end

End Points

Customer Subscriptions

Create CustomerSubscription

Request:

POST /api/v1/customer_subscriptions
Content-Type: application/json
Accept: application/json

Body:

{ 
    "customer_subscription": 
        {
             "customer_id": 1,
             "subscription_id": 3
        }
 }

Response: status: 201

{
    "data": {
        "id": "1",
        "type": "customer_subscription",
        "attributes": {
            "status": "active",
            "title": "It's Tea",
            "price": 5000,
            "frequency": 3
        },
        "relationships": {
            "customer": {
                "data": {
                    "id": "1",
                    "type": "customer"
                }
            },
            "subscription": {
                "data": {
                    "id": "3",
                    "type": "subscription"
                }
            }
        }
    }
}
Cancel/Reactivate CustomerSubscription

Request:

PATCH api/v1/customer_subscriptions/1
Content-Type: application/json
Accept: application/json

Body:

{
    "status": "cancelled"
}

Response: status: 200

{
    "data": {
        "id": "1",
        "type": "customer_subscription",
        "attributes": {
            "status": "cancelled",
            "title": "It's Tea",
            "price": 5000,
            "frequency": 3
        },
        "relationships": {
            "customer": {
                "data": {
                    "id": "1",
                    "type": "customer"
                }
            },
            "subscription": {
                "data": {
                    "id": "3",
                    "type": "subscription"
                }
            }
        }
    }
}
Get All CustomerSubscriptions for a Customer

Request:

GET /api/v1/customer_subscriptions/1
Content-Type: application/json
Accept: application/json

Response: status: 200

{
    "data": [
        {
            "id": "1",
            "type": "customer_subscription",
            "attributes": {
                "status": "active",
                "title": "Expensive Tea",
                "price": 10000,
                "frequency": 1
            },
            "relationships": {
                "customer": {
                    "data": {
                        "id": "1",
                        "type": "customer"
                    }
                },
                "subscription": {
                    "data": {
                        "id": "1",
                        "type": "subscription"
                    }
                }
            }
        },
        {
            "id": "2",
            "type": "customer_subscription",
            "attributes": {
                "status": "active",
                "title": "Least Expensive Tea",
                "price": 100,
                "frequency": 12
            },
            "relationships": {
                "customer": {
                    "data": {
                        "id": "1",
                        "type": "customer"
                    }
                },
                "subscription": {
                    "data": {
                        "id": "2",
                        "type": "subscription"
                    }
                }
            }
        },
        ...,
        ...
    ]
}

This endpoint also accepts query params to filter subscriptions with a status of active or cancelled.

Example:

GET /api/v1/customer_subscriptions/1?status=cancelled
Content-Type: application/json
Accept: application/json

or

GET /api/v1/customer_subscriptions/1?status=active
Content-Type: application/json
Accept: application/json

Contributors

tea_time's People

Contributors

jaredmhobson avatar

Watchers

 avatar

tea_time's Issues

Create CustomerSubscription Endpoint

POST CustomerSubscription

Details

  • This endpoint should follow the pattern of POST api/v1/customer_subscriptions and should pass in a customer id and subscription id as JSON in the body of the request
  • This endpoint will create a new customer_subscription resource
  • A successful response will return a response with a 201 status code, and return the newly created customer_subscription resource
  • If any number of attributes are left out in the body of the request, a status code of 400, as well as a descriptive error message should be sent back in the response.
  • If an invalid customer id or subscription id is passed in, a 404 status code as well as a descriptive message should be sent back with the response.

Happy Path

Request:

POST /api/v1/customer_subscriptions
Content-Type: application/json  
Accept: application/json  

Body:

{ 
    customer_subscription: 
        {
             "customer_id": 1,
             "subscription_id": 3
        }
 }

Response: status: 201

{
    "data": {
        "id": "1",
        "type": "customer_subscription",
        "attributes": {
            "status": "active",
            "title": "It's Tea",
            "price": 5000,
            "frequency": 3
        },
        "relationships": {
            "customer": {
                "data": {
                    "id": "1",
                    "type": "customer"
                }
            },
            "subscription": {
                "data": {
                    "id": "3",
                    "type": "subscription"
                }
            }
        }
    }
}

Sad Path 1

Request:

POST /api/v1/customer_subscriptions
Content-Type: application/json  
Accept: application/json  

Body:

{ 
    customer_subscription: 
        {
             "subscription_id": 3
        }
 }

Response: status: 400

 {
     "errors": [
         {
             "detail": "Validation failed: Customer can't be blank"
         }
     ]
 }

Sad Path 2

Request:

POST /api/v1/customer_subscriptions
Content-Type: application/json  
Accept: application/json  

Body:

{ 
    customer_subscription: 
        {
             "customer_id": 123123,
             "subscription_id": 3
        }
 }

Response: status: 404

 {
     "errors": [
         {
             "detail": "Couldn't find Customer with 'id'=123123"
         }
     ]
 }

Cancel CustomerSubscription Endpoint

UPDATE a customer_subscription

Details

  • This endpoint should follow the pattern of PATCH /api/v1/customer_subscriptions/:id and can pass a string of active or cancelled to the attribute status via the body of the request.
  • This endpoint should update an existing customer_subscription's status sent in via the body.

Happy Path

Request:

PATCH /api/v1/customer_subscriptions/1
Content-Type: application/json
Accept: application/json

Body:

{
    "status": "cancelled"
}

Response: status: 200

{
    "data": {
        "id": "1",
        "type": "customer_subscription",
        "attributes": {
            "status": "cancelled",
            "title": "It's Tea",
            "price": 5000,
            "frequency": 3
        },
        "relationships": {
            "customer": {
                "data": {
                    "id": "1",
                    "type": "customer"
                }
            },
            "subscription": {
                "data": {
                    "id": "3",
                    "type": "subscription"
                }
            }
        }
    }
}

Sad Path

Request:

PATCH /api/v1/customer_subscriptions/123123 (where '123123' is an invalid customer_subscription id)
Content-Type: application/json
Accept: application/json

Response: status: 404

{
    "errors": [
        {
            "status": "404",
            "title": "Couldn't find CustomerSubscription with 'id'=123123"
        }
    ]
}

Create Schema

Tea

  • Title : String
  • Description : String
  • Temperature : Integer
  • Brew Time : Integer (minutes)

Customer

  • First Name : String
  • Last Name : String
  • Email : String
  • Address : String

Subscription

  • Title : String
  • Price : Integer (pennies)
  • Status : Integer (enum) (disabled, enabled)
  • Frequency : Integer (months)

CustomerSubscription

  • Customer ID : Integer
  • Subscription ID : Integer
  • Status : Integer (enum) (cancelled, active) (default: active)

See All CustomerSubscriptions Endpoint

GET all subscriptions for a customer

Details

  • This endpoint should follow the pattern of GET /api/v1/customer_subscriptions.
  • If a valid customer id is passed in the body, a JSON object is sent back with a top-level data key that points to a collection of that customer's customer_subscriptions Each customer_subscription contains all of it’s attributes.
  • If an invalid customer id is passed in, a 404 status as well as a descriptive error message should be sent back in the response.

Happy Path

Request:

GET /api/v1/customer_subscriptions/1
Content-Type: application/json  
Accept: application/json  

Body:

{
    customer_subscription:
        {
             "customer_id": "1",
         }
}

Response: status: 200

{
    "data": [
        {
            "id": "1",
            "type": "customer_subscription",
            "attributes": {
                "status": "active",
                "title": "Expensive Tea",
                "price": 10000,
                "frequency": 1
            },
            "relationships": {
                "customer": {
                    "data": {
                        "id": "1",
                        "type": "customer"
                    }
                },
                "subscription": {
                    "data": {
                        "id": "1",
                        "type": "subscription"
                    }
                }
            }
        },
        {
            "id": "2",
            "type": "customer_subscription",
            "attributes": {
                "status": "active",
                "title": "Least Expensive Tea",
                "price": 100,
                "frequency": 12
            },
            "relationships": {
                "customer": {
                    "data": {
                        "id": "1",
                        "type": "customer"
                    }
                },
                "subscription": {
                    "data": {
                        "id": "2",
                        "type": "subscription"
                    }
                }
            }
        },
  ...,
  ...,
  }
}

Sad Path

Request:

GET /api/v1/customer_subscriptions
Content-Type: application/json  
Accept: application/json  

Body:

{
    subscription:
        {
             "customer_id": "123123",
         }
}

Response: status: 404

{
       "errors": [
           {
               "detail": "Couldn't find Customer with 'id'=123123"
           }
       ]
   }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.