GithubHelp home page GithubHelp logo

candy_shop's Introduction

Candy Store

Setup

Directions

  1. Clone this repository: git clone https://github.com/PlanetEfficacy/candy_shop
  2. Install gems: bundle
  3. Setup database: rake db:create
  4. Migrate database: rake db:migrate
  5. Seed database: rake db:seed
  6. Run test suite: rspec
  7. Run server: rails s
  8. Navigate to localhost:3000/api/v1/... in your browser

API Documentation

HTTP Verb Path Params Description
GET http://localhost:3000/api/v1/products na Gets all products
Response [ { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "", "bogo_sale": false }, { "id": 2, "name": "KitKat", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 3, "name": "Snickers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 4, "name": "Marbles", "price": "5.00", "warehouse_quantity": 10000, "store_quantity": 100, "expiration": "", "bogo_sale": false }, { "id": 5, "name": "Twizzlers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2027-01-23", "bogo_sale": false } ]
</td>
GET http://localhost:3000/api/v1/products ?sort_by=price Gets all products sorted by price
Response [ { "id": 4, "name": "Marbles", "price": "5.00", "warehouse_quantity": 10000, "store_quantity": 100, "expiration": "", "bogo_sale": false }, { "id": 2, "name": "KitKat", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 3, "name": "Snickers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 5, "name": "Twizzlers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2027-01-23", "bogo_sale": false }, { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "", "bogo_sale": false } ]`
GET http://localhost:3000/api/v1/products ?sort_by=warehouse Gets all products sorted by warehouse quantity
Response [ { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "", "bogo_sale": false }, { "id": 2, "name": "KitKat", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 3, "name": "Snickers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 5, "name": "Twizzlers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2027-01-23", "bogo_sale": false }, { "id": 4, "name": "Marbles", "price": "5.00", "warehouse_quantity": 10000, "store_quantity": 100, "expiration": "", "bogo_sale": false } ]
GET http://localhost:3000/api/v1/products ?sort_by=store Gets all products sorted by store quantity
Response [ { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "", "bogo_sale": false }, { "id": 2, "name": "KitKat", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 3, "name": "Snickers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2022-01-24", "bogo_sale": false }, { "id": 5, "name": "Twizzlers", "price": "3.00", "warehouse_quantity": 100000, "store_quantity": 1000, "expiration": "2027-01-23", "bogo_sale": false }, { "id": 4, "name": "Marbles", "price": "5.00", "warehouse_quantity": 10000, "store_quantity": 100, "expiration": "", "bogo_sale": false } ]
GET http://localhost:3000/api/v1/products/total na Gets total value of unexpired products in inventory in cents
Response { "total_value": 116150000 }
GET http://localhost:3000/api/v1/products/total ?id=1 Gets total value of product with id 1 in inventory in cents
Response { "total_value": 20200000 }
PATCH http://localhost:3000/api/v1/products/1 { warehouse_quantity: 200} Updates the warehouse quantity of a given product
Response { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 200, "store_quantity": 1000, "expiration": "", "bogo_sale": false }
PATCH http://localhost:3000/api/v1/products/1 { store_quantity: 200} Updates the store quantity of a given product
Response { "id": 1, "name": "Bubble gum", "price": "2.00", "warehouse_quantity": 200, "store_quantity": 200, "expiration": "", "bogo_sale": false }
POST http://localhost:3000/api/v1/sales { product: 1, discount: 50 } Discounts the given products price by a given percent
Response { "id": 1, "name": "Bubble gum", "price": "1.00", "warehouse_quantity": 200, "store_quantity": 200, "expiration": "", "bogo_sale": false }
POST http://localhost:3000/api/v1/bogosales { product: 1 } Discounts the given products price by a given percent
Response { "id": 1, "name": "Bubble gum", "price": "1.00", "warehouse_quantity": 200, "store_quantity": 200, "expiration": "", "bogo_sale": true }

A note on expired products

Edible products are those with non nil expiration dates. In the seed file, one product is expired: Old candy. Note, Old candy will not appear in any of the API responses because of the following scope being applied:

app/models/product.rb

class << self
  ...
  def unexpired
    where('expiration IS NULL').or(where('expiration > ?', two_weeks_from_now))
  end
  ...
end

Original Assignment

Description

I would like an Rails API for my candy store Al's Candies™. We're working on putting together an online storefront and taking my business to the next level. That Hersheys character has been on top for far too long. It's my time to shine.

Directions

Create a Rails API to handle the requirements below.

Commit/comment when/how you naturally would and when you're finished submit a pull request so I can check it out. Finishing all requirements is not required. If this takes you longer than 4hrs I would say submit what you have because I'll have enough to go off of at that point.

Any questions feel free to ping me

Reqs

  1. I need an easy way to be able to view all of my products. This list of products needs to show me the price, quantity available to ship, and quantity distributed to my Al's Candies™ stores. It would also be nice to be able to sort by those attributes as well.
  2. I need to be able to update quantity of products available to ship and distributed.
  3. I need to be able to apply sale prices to products that are online and/or in store. My sales are always a % off original price or BOGO.
  4. My edible products also require a sell by date and an expiration date. The sell by date is always 2 weeks before the expiration date. Once the sell by date passes we remove the remaining product from our inventory.
  5. I need to be able to tell the total value of my inventory as well as total value of specific products.

candy_shop's People

Contributors

jesse-spevack 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.