- Clone this repository:
git clone https://github.com/PlanetEfficacy/candy_shop
- Install gems:
bundle
- Setup database:
rake db:create
- Migrate database:
rake db:migrate
- Seed database:
rake db:seed
- Run test suite:
rspec
- Run server:
rails s
- Navigate to
localhost:3000/api/v1/...
in your browser
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
}
]
| ||
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 } |
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
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.
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
- 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.
- I need to be able to update quantity of products available to ship and distributed.
- 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.
- 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.
- I need to be able to tell the total value of my inventory as well as total value of specific products.