Code Monkey home page Code Monkey logo

mr_tea's Introduction

Mr. Tea

Contributors Issues Stargazers Forks
Version Ruby Style Guide

Table of Contents


Overview


Mr. Tea is the final take-home challenge for Mod 4 of 4 for Turing School's Back End Engineering Program.

The challenge was to project-plan and build a JSON API 1.0 spec-compliant REST API that models a tea subscription service, which could be consumed by a separate front end web application framework.

Learning goals and areas of focus consisted of:

  • Showcasing a strong understanding of Rails conventions
  • Creating RESTful routes
  • Producing well-organized, object-oriented code
  • Utilizing test-driven development
  • Producing clear documentation

Project specs:

Framework

Languages

Tools

Gems




Development Principles

Contributors

👤 Taylor Varoglu

Setup

This project requires Ruby 2.7.2 and Rails 5.2.6.

  • Fork and/or clone this repository
  • Install gems and set up your database:
    • $ bundle && bundle update
    • $ rails db:{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:{create,migrate,seed}
    Created database 'mr_tea_development'
    Created database 'mr_tea_test'
  • How to run the test suite:

    $ bundle exec rspec -fd
  • Local deployment, for testing:

    $ 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

Endpoint Documentation

The base path of each endpoint is:

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

Tea Endpoint

Get all teas

GET /api/v1/teas

Example Response:

200 (OK)

{
    "data": [
        {
            "id": "5fa3fd48d5ba620017ec1c09",
            "type": "tea",
            "attributes": {
                "name": "green",
                "description": "Rich in antioxidants and reduces inflammation.",
                "temperature": 80,
                "brew_time": 2
            }
        },
        {
            "id": "5fa3fdb0d5ba620017ec1c0a",
            "type": "tea",
            "attributes": {
                "name": "black",
                "description": "Boosts heart health and lowers cholesterol.",
                "temperature": 85,
                "brew_time": 3
            }
        },
        {
            "id": "5fa3fe47d5ba620017ec1c0b",
            "type": "tea",
            "attributes": {
                "name": "chamomile",
                "description": "Lowers blood sugar and prevents osteoporosis.",
                "temperature": 93,
                "brew_time": 3
            }
        },
        {
            "id": "5fa3feb2d5ba620017ec1c0c",
            "type": "tea",
            "attributes": {
                "name": "hibiscus",
                "description": "Lowers blood pressure and boosts liver health.",
                "temperature": 93,
                "brew_time": 3
            }
        },
        {
            "id": "5fa3ff13d5ba620017ec1c0d",
            "type": "tea",
            "attributes": {
                "name": "jasmine",
                "description": "Relieves stress and helps in weight loss.",
                "temperature": 80,
                "brew_time": 2
            }
        },
        {
            "id": "5fa3ff74d5ba620017ec1c0e",
            "type": "tea",
            "attributes": {
                "name": "mate",
                "description": "Boosts energy and mental focus.",
                "temperature": 80,
                "brew_time": 3
            }
        },
        {
            "id": "5fa3ffbbd5ba620017ec1c0f",
            "type": "tea",
            "attributes": {
                "name": "oolong",
                "description": "Lowers risk of cancer and prevents diabetes.",
                "temperature": 80,
                "brew_time": 2
            }
        },
        {
            "id": "5fa40008d5ba620017ec1c10",
            "type": "tea",
            "attributes": {
                "name": "pu-erh",
                "description": "Protects bone health and reduces stress.",
                "temperature": 87,
                "brew_time": 3
            }
        },
        {
            "id": "5fa40087d5ba620017ec1c11",
            "type": "tea",
            "attributes": {
                "name": "peppermint",
                "description": "Relieves headaches and improves digestion.",
                "temperature": 93,
                "brew_time": 3
            }
        },
        {
            "id": "5fa40117d5ba620017ec1c12",
            "type": "tea",
            "attributes": {
                "name": "rooibos",
                "description": "Good for heart health, digestion and skin.",
                "temperature": 100,
                "brew_time": 5
            }
        }
    ]
}

Subscription Endpoints

Create a new tea subscription for an existing customer

Example Request:

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

With the following JSON body:

{
    "title": "yellow",
    "description": "Strengthens bones and lowers cholesterol.",
    "temperature": 75,
    "brew_time": 3,
    "tea_id": "5fa402618765bf0017f09759",
    "price": 9.5,
    "frequency": "Weekly",
    "status": "Active",
    "customer_id": 3
}

Example Response:

201 (Created)

{
    "data": {
        "id": "4",
        "type": "subscription",
        "attributes": {
            "customer_id": 3,
            "tea_id": "5fa402618765bf0017f09759",
            "title": "yellow",
            "description": "Strengthens bones and lowers cholesterol.",
            "temperature": 75,
            "brew_time": 3,
            "price": 9.5,
            "frequency": "Weekly",
            "status": "Active"
        }
    }
}

Example Request:

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

With the following JSON body:

{}

Example Response:

422 (Unprocessable Entity)

{
    "errors": [
        "Tea can't be blank",
        "Description can't be blank",
        "Temperature can't be blank",
        "Temperature is not a number",
        "Brew time can't be blank",
        "Brew time is not a number",
        "Price can't be blank",
        "Price is not a number",
        "Frequency can't be blank",
        "Status can't be blank"
    ]
}

Example Request:

POST /api/v1/customers/foo/subscriptions

Example Response:

404 (Not Found)

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

Cancel an existing tea subscription

Example Request:

PATCH /api/v1/customers/{:customer_id}/subscriptions/{:id}

With the following JSON body:

{
    "status": "Cancelled"
}

Example Response:

200 (OK)

{
    "data": {
        "id": "4",
        "type": "subscription",
        "attributes": {
            "customer_id": 3,
            "tea_id": "5fa402618765bf0017f09759",
            "title": "yellow",
            "description": "Strengthens bones and lowers cholesterol.",
            "temperature": 75,
            "brew_time": 3,
            "price": 9.5,
            "frequency": "Weekly",
            "status": "Cancelled"
        }
    }
}

Example Request:

PATCH /api/v1/customers/{:customer_id}/subscriptions/{:id}

With the following JSON body:

{
    "status": "Foo"
}

Example Response:

422 (Unprocessable Entity)

{
    "errors": [
        "'Foo' is not a valid status"
    ]
}

Example Request:

PATCH /api/v1/customers/{:customer_id}/subscriptions/bar

Example Response:

404 (Not Found)

{
    "errors": [
        "Couldn't find Subscription with 'id'=bar"
    ]
}

Get all tea subscriptions for an existing customer

Example Request:

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

Example Response:

200 (OK)

{
    "data": [
        {
            "id": "4",
            "type": "subscription",
            "attributes": {
                "customer_id": 3,
                "tea_id": "5fa402618765bf0017f09759",
                "title": "yellow",
                "description": "Strengthens bones and lowers cholesterol.",
                "temperature": 75,
                "brew_time": 3,
                "price": 9.5,
                "frequency": "Weekly",
                "status": "Active"
            }
        },
        {
            "id": "5",
            "type": "subscription",
            "attributes": {
                "customer_id": 3,
                "tea_id": "5fa402618765bf0017f09759",
                "title": "yellow",
                "description": "Strengthens bones and lowers cholesterol.",
                "temperature": 75,
                "brew_time": 3,
                "price": 9.5,
                "frequency": "Weekly",
                "status": "Cancelled"
            }
        }
    ]
}

Schema Diagram


Acknowledgements:

  • T-API:
    • Created by Victoria Lo, this API feeds the Tea data behind the mock Subscription data for each Customer

mr_tea's People

Contributors

tvaroglu avatar

Stargazers

 avatar

Watchers

 avatar

mr_tea's Issues

Create ReadMe

  • Tools Used
  • Project Setup
  • JSON Contracts
  • Schema Diagram

POST `/customers/:id/subscriptions`

MVP endpoint #1: An endpoint to subscribe a customer to a tea subscription

  • Attributes to serialize:
    • Tea ID (from the Tea _id)
    • Title (from the Tea title)
    • Description (from the Tea description)
    • Temperature (from the Tea temperature)
    • Brew Time (from the Tea brew_time)
    • Price
    • Status
    • Frequency

GET `/customers/:id/subscriptions`

MVP endpoint #3: An endpoint to see all of a customer’s subscriptions (active and cancelled)

  • Subscription attributes to serialize:
    • Customer_ID
    • Tea_ID
    • Title
    • Description
    • Temperature
    • Brew Time
    • Price
    • Status
    • Frequency

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.