Simple Inventory backend service using GraphQL handling a simple ecommerce-like service.
This service supports:
- Product Management (Add - Lists - Update)
- Promo Management (Add - Lists - Update)
- Cart Management (Add - list)
- Checkout Process
This service is handling following promotions when a checkout process.
- Buy 1 Product X Get 1 Free Product Y
- Buy 3 Products X, Pay Only 2 Product X
- Buy Min 3 Products X, Get 10% Discount for purchases of Products X
Based on these requirements, I define three general rules.
- Buy 1 Get 1 - Buy1Get1
- Buy X Pay Y - BuyXPayY
- Buy Min X, OFF Y% - Discount with minimum quantity
- Execute models/query.sql to create table on database
- Update .env base on your database config
- go build
- ./kuncie
- go to http://localhost:8080/ to open GraphQL playground
The flowchart checkout process
Create new product
mutation createProduct{
createProduct(input: {sku:"234234", name:"Raspberry Pi B", price:30.0, quantity:2}) {
ID
}
}
Update product by SKU
mutation updateProduct {
updateProduct(input: {sku:"234234", name:"Raspberry Pi B", price:30.0, quantity:5}) {
status
}
}
Create new promo
mutation createPromo {
createPromo(input: {sku:"1304SD", promotype:"DISCOUNT", promodetail:{bonussku:"", minqty: 3, payonly:0, discount:10}}) {
ID
}
}
Update promo
mutation updatePromo {
updatePromo(input: {sku:"A304SD", promotype:"DISCOUNT", promodetail:{bonussku:"", minqty: 5, payonly:0, discount:15}}) {
status
}
}
Add product to cart
mutation addCart {
addCart(input:{sku: "A304SD",quantity: 1}){
ID,
sku,
quantity
}
}
Get product by SKU
query findProduct {
product(sku:"A304SD") {
ID
name
price
quantity
}
}
Get All Product
query getAllProduct {
products{
ID
name
sku
price
quantity
}
}
Get promo bu SKU
query getPromo {
promo(sku:"A304SD") {
ID,
promotype,
bonussku,
minqty,
payonly,
discount
}
}
get All Promo
query getAllPromo {
promolist {
ID,
promotype,
bonussku,
minqty,
payonly,
discount
}
}
Get All Cart with status 0 (open)
query getAllCart {
cartlist{
ID,
sku,
quantity
}
}
Checkout with carts
query checkout {
checkout(input: {contents:[{sku: "A304SD",quantity: 1},{ sku: "A304SD", quantity:1}, { sku: "A304SD", quantity:1}]}) {
total
}
}