Golang Ecommerce API using MySQL DB and Fiber
- Install dependencies.
go get ./...
- Add Config at
.env
file at root folder.
PORT = 9000
JWT_SECRET = "secret"
MYSQL_USER = "root"
MYSQL_PASSWORD = ""
MYSQL_HOST = "localhost"
MYSQL_PORT = 3306
MYSQL_DATABASE = "ecommerce_go"
- Import table and data using
schema.sql
anddata.sql
at./scripts
folder.
- Setting enviroment variable using
docker-compose.yml
at root folder. - If MYSQL_HOST and MYSQL_PORT are changed, make sure to change
mysql:3306
part in CMD at dockerfile at root folder.
CMD ["./wait-for.sh" , "mysql:3306" , "--timeout=300" , "--" , "./komodo-backend"]
- Use this command at root folder to start the app.
go run main.go
- Run test using this command at root folder.
go test ./...
- Clear docker compose
docker-compose rm -v
- Run this command to start docker compose.
docker-compose up --build
No | Path | Method | Payload | Description |
---|---|---|---|---|
1 | /buyers/register | POST | { "email":"buyer@mail.com", "name":"john buyer", "password":"12345", "sendingAddress":"Jl jalan"} |
Buyer register |
2 | /buyers/login | POST | { "email":"buyer@mail.com", "password":"12345"} |
Buyer login |
3 | /sellers/register | POST | { "email":"seller@mail.com", "name":"john seller", "password":"12345", "pickupAddress":"Jl jalan"} |
Seller register |
4 | /sellers/login | POST | { "email":"seller@mail.com", "password":"12345"} |
Seller login |
5 | /products | GET | Get all products | |
6 | /products | POST | { "name":"pro1", "description":"check", "price":91051551.13, "sellerId":1} |
Create a product |
7 | /orders/find/byuser | GET | Get all orders by buyer/seller id inside JWT token | |
8 | /orders | POST | {"buyerId": 1,"sellerId": 1,"deliverySourceAddress": "source","deliveryDestinationAddress": "destination","items": [{"productId": 1,"quantity": 12},{"productId": 2,"quantity": 8},{"productId": 3,"quantity": 10}]} |
Create an order |
9 | /orders/:id/accept | PUT | Accept order |
No | Path | Method | Need Login? | Access by |
---|---|---|---|---|
1 | /buyers/register | POST | no | all |
2 | /buyers/login | POST | no | all |
3 | /sellers/register | POST | no | all |
4 | /sellers/login | POST | no | all |
5 | /products | GET | yes | all |
6 | /products | POST | yes | seller |
7 | /orders/find/byuser | POST | yes | all |
8 | /orders | POST | yes | buyer |
9 | /orders/:id/accept | PUT | yes | seller |