Code Monkey home page Code Monkey logo

tea-subscription's Introduction

Tea Subscription Service API 🍵

Rails API for a Tea Subscription Service with the following endpoints:

  • An endpoint to subscribe a customer to a tea subscription
  • An endpoint to cancel a customer’s tea subscription
  • An endpoint to see all of a customer’s subsciptions (active and cancelled)

Completion of this take home challenge requires the following:

  • A strong understanding of Rails
  • Ability to create restful routes
  • Demonstration of well-organized code, following OOP
  • Test Driven Development
  • Clear documentation

Technology

Built with:

  • Ruby 2.7.4
  • Rails 5.2.8.1
  • RSpec 3.11

Setup

  1. Ensure that you have the prerequisites or equivalent
  2. Clone this repo and navigate to the root folder cd tea-subscription
  3. Run bundle install
  4. Run rails db:{drop,create,migrate,seed}
  5. (Optional) To run the test suite, run bundle exec rspec
  6. Run rails s

You should now be able to hit the API endpoints using Postman. Default host is http://localhost:3000

Database Schema

Screen Shot 2022-11-10 at 12 30 01 AM

Endpoints

Subscribe a customer to a tea subscription

POST /api/v1/customers/1/subscriptions

  • Required Params

    • title, price, frequency, tea_id, and customer_id
    • Send required data in JSON format in the body of the request as displayed in the example below
  • Example Request

    • POST http://localhost:3000/api/v1/customers/1/subscriptions

    body: {
      "title": "Green Tea",
      "price": 2.99,
      "frequency": "weekly",
      "tea_id": 1,
      "customer_id": 1
    }
  • Example Response

    {
        "data": {
            "id": 3,
            "type": "subscription",
            "attributes": {
                "title": "Green Tea",
                "price": 2.99,
                "status": "active",
                "frequency": "weekly",
                "customer_id": 1,
                "tea_id": 1
            }
        }
    }
    
    

Cancel a customer’s tea subscription

PATCH /api/v1/customers/1/subscriptions/1

  • Required Params
    • status: 'inactive'
  • Example Request
    • PATCH http://localhost:3000/api/v1/customers/1/subscriptions/1
    • Does not remove record, just changes status to inactive.
  • Example Response
    {
        "data": {
            "id": 3,
            "type": "subscription",
            "attributes": {
                "title": "Green Tea",
                "price": 2.99,
                "status": "inactive",
                "frequency": "weekly",
                "customer_id": 1,
                "tea_id": 1
            }
        }
    }

See all of a customer’s subscriptions (active and inactive)

GET /api/v1/customers/1/subscriptions

  • Required Params
    • N/A
  • Example Request
    • GET http://localhost:3000/api/v1/customers/2/subscriptions
  • Example Response
    {
      "data": [
          {
              "id": "1",
              "type": "subscription",
              "attributes": {
                  "title": "Green Tea",
                  "price": 2.99,
                  "status": "inactive",
                  "frequency": "weekly",
                  "tea_id": 1,
                  "customer_id": 1
              }
          }
          {
              "id": "2",
              "type": "subscription",
              "attributes": {
                  "title": "Chai Tea",
                  "price": 5.35,
                  "status": "active",
                  "frequency": "weekly",
                  "tea_id": 2,
                  "customer_id": 2
              }
          }
      ]
    }

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.