- Your mom has an online store name is "Kitara Store".
- She has one big problem, in many time customer order requested, the products will produce minus quantity.
- When the product stock is limited and many customers order in the same time, the issue always occur.
- use many layer checking & transactional on order
- Go 1.13+
- Go mod (for dependencies)
update dependencies:
- go mod download
- go mod verify
- go mod tidy
- Go 1.13+
- Mysql
- GORM
- Go Gin Framework
- Go Mock
You need to ensure that mysql already running on your machine and edit environment file .env with your setting.
Run migration with command go run main.go migrate
ensuring all dependencies with go mod
build application with script go build main.go
run application ./main
run app with auto build go run main.go
execute this command to run test with go test framework
go test github.com/mariojuzar/kitara-store/tests
-
Get All Product
GET /api/v1/productsThis endpoint is to show the seed data products that available from migration. You can use this product id to test for the lock order
-
Lock Order
POST /api/v1/order/lockThis endpoint used to lock order from customer. This endpoint accept user_id and product that want to order. This endpoint support lock order for multiple product.
Sample request:
{ "user_id": 2, "products": [ { "product_id": 1, "quantity": 2 }, { "product_id": 2, "quantity": 1 } ] }When succes lock the order, the expected response:
{ "server_time": "2020-08-17T16:10:24.537827+07:00", "code": 200, "message": "OK", "data": { "order_id": 11, "order_details": [ { "order_detail_id": 21, "product_id": 1, "product_name": "masker", "quantity": 2 }, { "order_detail_id": 22, "product_id": 2, "product_name": "sikat gigi", "quantity": 1 } ] } }If some product not available then the expected result:
{ "server_time": "2020-08-17T16:10:44.537827+07:00", "code": 400, "message": "some product not available", "data": null }But, this endpoint only support for lock order for single store. If many store in request then system will reject it
{ "server_time": "2020-08-17T16:11:24.537827+07:00", "code": 400, "message": "product must in same store", "data": null }