Code Monkey home page Code Monkey logo

mock_take_home's Introduction

Tea Subscription Management API

Setup

  1. fork and clone this repository
  2. run bundle to install gems and dependencies
  3. run rails db:create db:migrate to create a local database
  4. seed database with your comapny's customer base and tea offerings.
  5. run rails s

You are now running the API! Pleas note these instructions are intended for local deployment on port 3000. Depending on your particular deployment solution, your base URL may be different from that noted in the instructions below.

Endpoints

New Subscription Endpoint

To create a new subsciption; send a POST request to /api/v1/subscriptions with the queary parameters customer_id and tea_id representing valid database id's for both; and a frequency paramater of:

  • weekly
  • semi_weekly
  • monthly
  • bi_monthly
  • semi_monthly
  • semi_anually

Example Request

post "http://localhost:300/api/v1/subscriptions?customer_id=1&tea_id=3&frequency=monthly"

Example Response

{
    "data": {
        "id": "2",
        "type": "subscription",
        "attributes": {
            "title": "Cedric's Gen Mai Cha subscription",
            "description": "Tea delivered to 130 Green Acres Dr, Burlington, VT, 05401",
            "frequency": "monthly",
            "price": 1250,
            "status": "active",
            "created_at": "2022-08-05T06:01:15.083Z",
            "updated_at": "2022-08-05T06:01:15.083Z"
        }
    }
}

Cancel Subscription Endpoint

To cancel an existing subscription; send a PATCH request to http://localhost:300/api/v1/subscriptions with a valid subscription_id queary parameter. If found, the subscription's status will be updated to cancelled

Example Request

    patch "http://localhost:300/api/v1/subscriptions?subscription_id=2"

Example Response

{
    "data": {
        "id": "2",
        "type": "subscription",
        "attributes": {
            "title": "Cedric's Gen Mai Cha subscription",
            "description": "Tea delivered to 130 Green Acres Dr, Burlington, VT, 05401",
            "frequency": "monthly",
            "price": 1250,
            "status": "cancelled",
            "created_at": "2022-08-05T06:01:15.083Z",
            "updated_at": "2022-08-05T06:29:15.725Z"
        }
    }
}

Pull A User's Subscriptions

To reques a complete list of a user's subscriptions, active and cancelled; send a GET request to "http://localhost:300/api/v1/subscriptions" with a valid user ID. It will return a list list of all subscriptions ordered by created_at by default.

Example Request

get "http://localhost:300/api/v1/subscriptions?customer_id=1"

Example Response

{
    "data": [
        {
            "id": "1",
            "type": "subscription",
            "attributes": {
                "title": "Gen Mai Cha Monthly",
                "description": "whoops",
                "frequency": "bi_monthly",
                "price": 2100,
                "status": "active",
                "created_at": "2022-08-05T03:22:08.244Z",
                "updated_at": "2022-08-05T03:22:08.244Z"
            }
        },
        {
            "id": "2",
            "type": "subscription",
            "attributes": {
                "title": "Cedric's Gen Mai Cha subscription",
                "description": "Tea delivered to 130 Green Acres Dr, Burlington, VT, 05401",
                "frequency": "monthly",
                "price": 1250,
                "status": "active",
                "created_at": "2022-08-05T06:01:15.083Z",
                "updated_at": "2022-08-05T06:01:15.083Z"
            }
        }
    ]
}

Database

Screen Shot 2022-08-05 at 12 59 48 AM

The Schema for this PostgreSQL database is a simple many-to-many setup with subscriptions connecting one single customer to one tea. Given the constraints of the prompt, there is no way to tailor a quantity, and so assuming that each tea is sold in a fixed quantity and therefore an equal price (for simplicity's sake), price was therefore based entirely upon the user's indicated frequency parameter, incorporating a slight logorithmic discount scale with quantity purchased and calculating price for an assumed monthly billing cycle. These are all set in the method ::price_setter(freq) in app/models/subscription.rb

mock_take_home's People

Contributors

josenecal avatar

Watchers

 avatar

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.