Vending machine (beverage)
- There are items in the vending machine like coke, soda, pepsi each with a particular price.
- A user should be able to get prices of all the items in the machine.
- A user should be able to select any item and insert cash to buy it.
- The machine only performs one activity at a time. For eg If the machine is in process of dispensing an item, the user can't try to buy a new item or insert cash.
- The machine should display appropriate error messages in every situation. For eg in above condition it can throw "already dispensing item can't select a new item".
- The vending machine should also return the remaining change after dispensing the item if any.
Assumptions A single slot in the vending machine User can only buy one item of any type.
Schema:
-
Items
- id
- name
- vending_machine_id
- price
- quantity
- meta-data
-
Transaction
- id
- item_id
- price - 30
- payment_method - ENUM -> CASH, CREDIT
- credit_amount - 50
- debit_amount - 20
- status - CAPTURED, CREATED, FAILED
- reason
-
VendingMachine
- id
- name
- meta-data
-
Denominations
- id
- vending_machine_id
- denomination
- quantity
-> APIs POST -> /item/add/{vending_machine_id} { 'name', price }
GET /item/all/{vending_machine_id} -> Table: Items { id items: [{}, {},....] } GET /item/{item_id} -> Table: Items { id: . . }
POST /buy/ { item_id cash } Status code: 200 OK status code: 403 Forbidden request