Go-Cart
Mini Service Shopping Cart with Gin-Gonic HTTP Respons Framework, GORM for Object relation model, PostgreSQL for database.
π Description
This Backend Service Shopping Cart is used for simple add product to cart.
There are 3 main routers :
- Add Cart (Can add product if product is no exist also update quantity product if name product exist)
Attributes ProductCode, ProductName, Quantity
2. Delete Product (Delete by prodcut code)
3. Get Product (Get all product, Get by product name, Get by quantity)
Notes :
- I'am using UUID for cart_id, don't forget to create extenxions in SQL console after create the database with this query below :
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
- For answers no. 01 & 02, i put it in a folder soal_01 & soal_02, change directory to folder and run
go run .
- For answer no. 03 - 05 i put in a folder soal_03-05, open the .pdf file / .svg
Several command you must know in this app :
1. go run . serve //to run the app / server
2. go run . migrate -u //for database migration
# or
go run . migrate -d //for rollback
π οΈ Installation Steps
- Clone the repository
https://github.com/adiet95/go-cart.git
- Install dependencies
go mod tidy
Wait a minute, if still error run :
go mod vendor
- Add Env File
USER = Your DB User
HOST = Your DB Host
DB = Your DB Name
PASS = Your DB Password
PORT = Your Port
- Database Migration and Rollback
go run main.go migrate --up //for database migration table
# or
go run main.go migrate --down //for rollback the database
- Run the app
go run . serve
π You are all set
π REST API Endpoints
GET /cart
Get Data Cart
Request Body
not needed
Request Query Params
not needed
POST /cart
Post Data Cart
Request Body
{
"product_code" : "a-03",
"product_name" : "kabel-1",
"quantity" : 2
}
Request Query Params
no need
DELETE /cart
Delete Data Cart by Product Code
Request Body
no need
Request Query Params
code = (input product code)
GET /cart/name
Search Data Cart by product name
Request Body
no need
Request Query Params
name = (input product name)
GET /cart/qty
Search Data Cart by quantity
Request Body
no need
Request Query Params
qty = (input quantity)
π» Built with
π About Me