jimriddle1 / tea-subscription

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Overview

  • Take Home challenge in which the task was to expose three endpoints of a sample tea subscription service
  • Explores a many to many relationship, where Customers have many Teas through Subscriptions, and vice versa

Learning Goals

  • Sad path testing and functionality
  • Expose an API for CRUD functionality

Schema -

Screen Shot 2022-09-22 at 4 17 10 PM


API Usage


CREATE

Create Subscription

  • This endpoint creates a subscription
[GET] /api/v1/customers/1/subscriptions

Example:

[POST] /api/v1/customers/#{customer.id}/subscriptions?tea_id=2&title=first_subscription&price=50 dollars&frequency=monthly

RESPONSE:

{
	"data": {
		"id": "2",
		"type": "subscription",
		"attributes": {
			"title": "first_subscription",
			"price": "50 dollars",
			"status": "active",
			"frequency": "monthly"
		}
	}
}

CANCEL

Cancel Subscription

  • This endpoint cancels a subscription
[PATCH] /api/v1/customers/#{customer.id}/subscriptions/#{subscription.id}

Example:

[PATCH] /api/v1/customers/1/subscriptions/1?status=cancelled

RESPONSE:

{
	"data": {
		"id": "1",
		"type": "subscription",
		"attributes": {
			"title": "first_subscription",
			"price": "40 dollars",
			"status": "cancelled",
			"frequency": "weekly"
		}
	}
}

VIEW

Subscription Index

  • This endpoint shows all subscription of a given user
[GET]  /api/v1/customers/#{customer.id}/subscriptions

Example:

[GET]  /api/v1/customers/1/subscriptions

RESPONSE:

{
	"data": [
		{
			"id": "1",
			"type": "subscription",
			"attributes": {
				"title": "first_subscription",
				"price": "40 dollars",
				"status": "cancelled",
				"frequency": "weekly"
			}
		},
		{
			"id": "2",
			"type": "subscription",
			"attributes": {
				"title": "first_subscription",
				"price": "50 dollars",
				"status": "active",
				"frequency": "monthly"
			}
		}
	]
}

Feel like messing around?

Installation

  1. Clone this directory to your local repository using the SSH key:

$ git clone git@github.com:jimriddle1/tea_subscription.git

  1. Install gems for development using Bundler:

$ bundle install

  1. Set up your database with:

$ rails db:{drop,create,migrate}

  1. Run the test suite with:

$ bundle exec rspec

  1. Run your development server with:

$ rails s

About


Languages

Language:Ruby 99.4%Language:HTML 0.6%