57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
|
package app
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"go.uber.org/zap"
|
||
|
"miniapp/global"
|
||
|
"miniapp/model/app"
|
||
|
"miniapp/model/app/request"
|
||
|
r "miniapp/model/common/response"
|
||
|
)
|
||
|
|
||
|
type VisionApi struct{}
|
||
|
|
||
|
func (VisionApi) GetList(ctx *gin.Context) {
|
||
|
var p request.VisionListRequest
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
r.FailWithMessage("参数错误:"+err.Error(), ctx)
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 获取列表
|
||
|
list, total, err := visionService.GetVisionList(p)
|
||
|
if err != nil {
|
||
|
r.FailWithMessage(err.Error(), ctx)
|
||
|
global.GVA_LOG.Error("获取列表失败", zap.Error(err))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithData(r.PageResult{
|
||
|
List: list,
|
||
|
Total: total,
|
||
|
Page: p.Page,
|
||
|
PageSize: p.PageSize,
|
||
|
}, ctx)
|
||
|
}
|
||
|
|
||
|
func (VisionApi) Create(ctx *gin.Context) {
|
||
|
var p app.Vision
|
||
|
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
r.FailWithMessage(err.Error(), ctx)
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// 创建
|
||
|
err := visionService.CreateVision(&p)
|
||
|
if err != nil {
|
||
|
r.FailWithMessage(err.Error(), ctx)
|
||
|
global.GVA_LOG.Error("创建失败", zap.Error(err))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.Ok(ctx)
|
||
|
}
|