feat: client 增删改查
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
)
|
||||
|
||||
type ClientApi struct {
|
||||
}
|
||||
|
||||
func (s *ClientApi) SaveClient(c *gin.Context) {
|
||||
var client system.Client
|
||||
err := c.ShouldBindJSON(&client)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = ClientService.SaveClient(client)
|
||||
if err != nil {
|
||||
global.Logger.Error("保存客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("保存客户端成功!", c)
|
||||
}
|
||||
|
||||
func (s *ClientApi) UpdateClient(c *gin.Context) {
|
||||
var client system.Client
|
||||
err := c.ShouldBindJSON(&client)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = ClientService.UpdateClient(client)
|
||||
if err != nil {
|
||||
global.Logger.Error("更新客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("更新客户端成功!", c)
|
||||
}
|
||||
|
||||
func (s *ClientApi) GetClientList(c *gin.Context) {
|
||||
var pageInfo systemReq.GetClientList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := ClientService.GetClientList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取客户端列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
func (s *ClientApi) Delete(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = ClientService.DeleteClientByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除客户端成功!", c)
|
||||
}
|
||||
|
||||
func (s *ClientApi) Detail(c *gin.Context) {
|
||||
var idInfo request.GetById
|
||||
err := c.ShouldBindJSON(&idInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
client, err := ClientService.GetClientById(idInfo.ID)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取客户端详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(client, c)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user