PaymentCenter/app/http/controllers/backend/merchant.go

55 lines
1.5 KiB
Go

package backend
import (
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/merchantmodel"
"PaymentCenter/app/services"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
)
func MerchantList(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.MerchantListRequest)
req.SetDefault()
merchantList, total, code := services.MerchantList(*req)
result := make([]backend.MerchantResponse, 0, len(merchantList))
linq.From(merchantList).SelectT(func(in merchantmodel.Merchant) (out backend.MerchantResponse) {
out.ResponseFromDb(in)
return
}).ToSlice(&result)
data := entities.PageRsp{
Total: total,
Data: result,
}
controllers.HandCodeRes(c, data, code)
}
func MerchantCreate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.MerchantCreateRequest)
merchant := req.RequestToDb()
code := services.MerchantCreate(&merchant)
data := backend.MerchantResponse{}
data.ResponseFromDb(merchant)
controllers.HandCodeRes(c, data, code)
}
func MerchantUpdate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.MerchantUpdateRequest)
merchant := req.RequestToDb()
code := services.MerchantUpdate(&merchant)
data := backend.MerchantResponse{}
data.ResponseFromDb(merchant)
controllers.HandCodeRes(c, data, code)
}
func MerchantDelete(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
code := services.MerchantDelete(*req)
controllers.HandCodeRes(c, nil, code)
}