64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package backend
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/errorcode"
|
|
"PaymentCenter/app/http/controllers"
|
|
"PaymentCenter/app/http/entities"
|
|
"PaymentCenter/app/http/entities/backend"
|
|
"PaymentCenter/app/models/paychannelmodel"
|
|
"PaymentCenter/app/services"
|
|
"github.com/ahmetb/go-linq/v3"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func PayChannelList(c *gin.Context) {
|
|
req, _ := controllers.GetRequest(c).(*backend.PayChannelListRequest)
|
|
req.SetDefault()
|
|
payChannelList, total, code := services.PayChannelList(*req)
|
|
|
|
result := make([]backend.PayChannelResponse, 0, len(payChannelList))
|
|
linq.From(payChannelList).SelectT(func(in paychannelmodel.PayChannel) (out backend.PayChannelResponse) {
|
|
out.ResponseFromDb(in)
|
|
return
|
|
}).ToSlice(&result)
|
|
data := entities.PageRsp{
|
|
Total: total,
|
|
Data: result,
|
|
}
|
|
controllers.HandCodeRes(c, data, code)
|
|
}
|
|
|
|
func PayChannelCreate(c *gin.Context) {
|
|
req, _ := controllers.GetRequest(c).(*backend.PayChannelCreateRequest)
|
|
payChannel, err := req.RequestToDb()
|
|
if err != nil {
|
|
controllers.Error(c, errorcode.ParamError, err.Error())
|
|
return
|
|
}
|
|
code := services.PayChannelCreate(&payChannel)
|
|
|
|
data := backend.PayChannelResponse{}
|
|
data.ResponseFromDb(payChannel)
|
|
controllers.HandCodeRes(c, data, code)
|
|
}
|
|
|
|
func PayChannelUpdate(c *gin.Context) {
|
|
req, _ := controllers.GetRequest(c).(*backend.PayChannelUpdateRequest)
|
|
payChannel, err := req.RequestToDb()
|
|
if err != nil {
|
|
controllers.Error(c, errorcode.ParamError, err.Error())
|
|
return
|
|
}
|
|
code := services.PayChannelUpdate(&payChannel)
|
|
|
|
data := backend.PayChannelResponse{}
|
|
data.ResponseFromDb(payChannel)
|
|
controllers.HandCodeRes(c, data, code)
|
|
}
|
|
|
|
func PayChannelDelete(c *gin.Context) {
|
|
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
|
|
code := services.PayChannelDelete(*req)
|
|
controllers.HandCodeRes(c, nil, code)
|
|
}
|