Go-Order-API
Simple app product order with Gin-Gonic HTTP Respons Framework, GORM for Object relation model, PostgreSQL for database.
π Description
This Backend Application is used for simple order product, in this application there are two models / ERD Schema likes User / Costumer & Products.
Also have several features like JWT, Authentification & Authorization.
There are 3 main modules :
- Customer Management (Get with paginate, Get Detail, Insert, Update, Delete,
Search)
- Order Management (Get with paginate, Get Detail, Insert, Update, Delete,
Search)
- Authentikasi Management (Get Login Data, Insert Login Data)
Notes :
- I'am using UUID for user_id, don't forget to create extenxion in SQL console after create the database with this query below :
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
- In this application there are two types of users (Roles). admins and costumer.
Admin can do Costumer Management but Role Costumer can't, Registration page can only register Costumer roles, Admins can only be registered through seeding data.
ERD (Entity Relation Database)
![erd.jpg](https://res.cloudinary.com/dw5qffbop/image/upload/v1665874871/erd_c15gne.png)
Table Specification
Costumer's Table
![cost.jpg](https://res.cloudinary.com/dw5qffbop/image/upload/v1665882605/table-cost_miwqjk.png)
Order's Table
![order.jpg](https://res.cloudinary.com/dw5qffbop/image/upload/v1665882605/table-user_sz493j.png)
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
3. go run . seed // to seeding data Role admin if u want Email : "admin@gmail.com" Pass : admin12345678
π οΈ Installation Steps
- Clone the repository
https://github.com/adiet95/go-order-api.git
- Install dependencies
go mod tidy
Wait a minute, if still error run
go mod vendor
- Add Env File
DB_USER = Your DB User
DB_HOST = Your DB Host
DB_NAME = Your DB Name
DB_PASS = Your DB Password
JWT_KEYS = Your JWT Key
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
- Seeding data admin
go run . seed
Purpose to login as Admin's Role
{
"email": "admin@gmail.com",
"password": "admin12345678"
}
- Run the app
go run . serve
π You are all set
π RESTful endpoints
POST /register
Create new user
Request Header
not needed
Request Body
{
"user_name": <your username> (STRING),
"full_name": <your username> (STRING),
"email": <your email> (STRING),
"password": <your password> (STRING),
"address": <your address> (STRING),
"phone": <your phone> (STRING)
}
POST /login
Process Login
Request Header
not needed
Request Body
{
"email": <your email> (STRING),
"password": <your password> (STRING)
}
GET /user
Get Data Costumer
Request Header
Bearer Token
Request Body
not needed
Request Query Params
limit = (limit for pagination)
offset = (offset for pagination)
POST /user
Post Data Costumer
Request Header
Bearer Token
Request Body
{
"email" : "(STRING)",
"password" : "(STRING)",
"address" : "(STRING)",
"full_name" : "(STRING)",
"phone" : "(STRING)"
}
Request Query Params
no need
PUT /user
Update Data Costumer
Request Header
Bearer Token
Request Body
{
"email" : "(STRING)",
"password" : "(STRING)",
"address" : "(STRING)",
"full_name" : "(STRING)",
"phone" : "(STRING)"
}
Request Query Params
no need
DELETE /user
Delete Data Costumer
Request Header
Bearer Token
Request Body
no need
Request Query Params
email = (Delete by email)
GET /user/detail
Get Detail Data Costumer Email
Request Header
Bearer Token
Request Body
no need
Request Query Params
email = (Get detail data by email)
GET /user/search
Search Data Costumer by Full_Name
Request Header
Bearer Token
Request Body
no need
Request Query Params
name = (Search data by full_name)
GET /order
Get Data Order
Request Header
Bearer Token
Request Body
not needed
Request Query Params
limit = (limit for pagination)
offset = (offset for pagination)
POST /order
Post Data Order
Request Header
Bearer Token
Request Body
{
"order_name" : "Test",
"invoice" : "test inv",
"address" : "test address",
"telphone" : "0813",
"amount" : 2,
"price" : 10000,
"status" : "paid"
}
Request Query Params
no need
PUT /order
Update Data Order
Request Header
Bearer Token
Request Body
{
"order_name" : "Test",
"invoice" : "test inv",
"address" : "test address",
"telphone" : "0813",
"amount" : 2,
"price" : 10000,
"status" : "paid"
}
Request Query Params
id = (id you want to update)
DELETE /order
Delete Data Order
Request Header
Bearer Token
Request Body
no need
Request Query Params
id = (Delete by id)
GET /order/detail
Get Data Detail by ID
Request Header
Bearer Token
Request Body
no need
Request Query Params
id = (Get detail data by id)
GET /order/search
Search Data Order by Name
Request Header
Bearer Token
Request Body
no need
Request Query Params
name = (Search data by name)
π» Built with
π About Me