4D-Coder / tea_subscription_api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


🍵 Tea Subscription API

An application that allows a customer to register for tea subscriptions.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Available Endpoints
  4. Goals

About The Project


(back to top)

Built With:

3.1.1

7.0.4

Postgres 14

(back to top)

Getting Started

To run the application locally, this repository will need to be cloned and set up fully with required gems.


Installation

  1. Clone the repo:

    git@github.com:4D-Coder/tea_subscription_api.git
  2. Install gems:

    bundle install
  3. To establish the database, run:

    rails db:create
  4. To migrate the database configurations into your local development and test environment, run:

    rails db:migrate

Inspect the /db/schema.rb and compare to the 'Schema' section below to ensure this migration has been done successfully.

(back to top)


Testing with RSpec

Once tea_subscription_api is correctly installed, run tests locally to ensure the repository works as intended.


To test the entire RSpec suite, run:

bundle exec rspec

All tests should be passing if the installation was successful.

If any tests are not passing, please report which tests are not passing Here.

(back to top)


Available Endpoints

  • This API can be called locally using a program like Postman.

  • Note: Necessary parameters marked with {}


Start a Subscription (Happy Path)

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

Request:

{
	"title": "Power of Insight",
	"total_price": 60,
	"status": "Active",
	"frequency": "Weekly",
	"teas": [
		{
			"tea_id": 2
		},
		{etc...
		}
	]
}
Code Description
201 Created

Response:

{
	"data": {
		"id": "1",
		"type": "subscription",
		"attributes": {
			"title": "Power of Insight",
			"total_price": 60,
			"status": "Active",
			"frequency": "Weekly",
			"teas": [
				{
					"id": 2,
					"title": "Neurogenesis",
					"description": "smooth brain",
					"temperature": 100,
					"brew_time": 120,
					"unit_price": 5
				},
				{etc...
				}
			],
		},
	},
}

Notes:

  • If subscription data is included in the content of the request, I assume that the subscription is something that is customized by the customer, and is only created alongside an tea that comes from the database (or service) that they’ve selected.
  • I also assume that additional teas can be added to this same subscription later
  • If there isnt a tea in the request body, throw an error
  • In the subscription controller, we will create the subscription and return it as an object with an id
  • For the response body, I’m assuming that once a customer has been successfully subscribed, the content will hold information for the front end to render a cusomer’s subscription details.

(back to top)

Cancel a Subscription (Happy Path)

PATCH /api/v1/customer/:id/subscriptions/:ids

Request:

{
	"title": "Power of Insight",
	"total_price": 60,
	"status": "Active",
	"frequency": "Weekly",
	"teas": [
		{
			"tea_id": 2
		},
		{etc...
		}
	]
}
Code Description
200 OK

Parameters:

CONTENT_TYPE=application/json

Request:

{
	"status": "Cancelled"
}

Response:

{
	"data": {
		"id": "1",
		"type": "subscription",
		"attributes": {
			"title": "Art of Tea",
			"price": 40,
			"status": "Cancelled",
			"frequency": "Monthly",
			"teas": [{
				"id": 1,
				"title": "Oolong",
				"description": "tis very nice",
				"temperature": 150,
				"brew_time": 90,
				"unit_price": 8
				},
				{tea2...
			}]
		}
	}
}

Notes:

  • Response body assumes that the frontend would want to show the user that cancelled subscription info with an updated status of cancelled.
  • GET method will need to show both active and cancelled subscriptions, so a status change on the subscription record also needs to happen with the change
  • Originally this method was a DELETE , but I found it pertinent to preserve data, so that a hypothetical business can see all subscriptions that are active and inactive, along with a record of what teas were being purchased .

(back to top)

Get All Subscriptions (Happy Path)

GET /api/v1/customer/:id/subscriptions

Request:

{
	"title": "Power of Insight",
	"total_price": 60,
	"status": "Active",
	"frequency": "Weekly",
	"teas": [
		{
			"tea_id": 2
		},
		{etc...
		}
	]
}
Code Description
200 OK

Parameters:

CONTENT_TYPE=application/json

Request:

No Parameters

Response:

{
	"data": [
		{
			"id": "1",
			"type": "subscription",
			"attributes": {
				"title": "Art of Tea",
				"price": 40,
				"status": "Active",
				"frequency": "Monthly",
				"teas": [
					{
						"id": 1,
						"title": "Oolong",
						"description": "tis very nice",
						"temperature": 150,
						"brew_time": 90,
						"unit_price": 9
					},
					{etc...}
				],
			},
		},
		{
			"id": "2",
			"type": "subscription",
			"attributes": {
				"title": "Power of Insight",
				"price": 60,
				"status": "Cancelled",
				"frequency": "Weekly",
				"teas": [
					{
						"id": 2,
						"title": "Neurogenesis",
						"description": "smooth brain",
						"temperature": 100,
						"brew_time": 120,
						"unit_price": 20
					},
					{etc...}
				],
			},
		},
	]
}

Notes:

  • Much like when someone starts a subscription, I assume we will want to see all subscriptions (active or cancelled)

(back to top)

Goals

See the take-home requirements here.


Goals Checklist

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

(back to top)


Database Schema


Contributors

GitHub
LinkedIn
Antonio King Hunt

About


Languages

Language:Ruby 99.4%Language:HTML 0.6%