109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"miniapp/global"
|
||
|
"miniapp/model/common"
|
||
|
"miniapp/model/common/request"
|
||
|
r "miniapp/model/common/response"
|
||
|
)
|
||
|
|
||
|
type BannerApi struct {
|
||
|
}
|
||
|
|
||
|
// GetBannerList 获取轮播图列表
|
||
|
func (b *BannerApi) GetBannerList(ctx *gin.Context) {
|
||
|
var p request.PageInfo
|
||
|
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误" + err.Error())
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
list, total, err := bannerService.GetBannerList(p)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("获取轮播图列表失败" + err.Error())
|
||
|
r.FailWithMessage("获取轮播图列表失败", ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithDetailed(r.PageResult{List: list, Total: total, Page: p.Page, PageSize: p.PageSize}, "获取成功", ctx)
|
||
|
}
|
||
|
|
||
|
// CreateBanner 创建轮播图
|
||
|
func (b *BannerApi) CreateBanner(ctx *gin.Context) {
|
||
|
var banner common.Banner
|
||
|
if err := ctx.ShouldBindJSON(&banner); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误" + err.Error())
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := bannerService.CreateBanner(&banner)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("创建失败" + err.Error())
|
||
|
r.FailWithMessage("创建失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("创建成功", ctx)
|
||
|
}
|
||
|
|
||
|
// UpdateBanner 更新轮播图
|
||
|
func (b *BannerApi) UpdateBanner(ctx *gin.Context) {
|
||
|
var banner common.Banner
|
||
|
if err := ctx.ShouldBindJSON(&banner); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误" + err.Error())
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := bannerService.UpdateBanner(&banner)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("更新失败" + err.Error())
|
||
|
r.FailWithMessage("更新失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("更新成功", ctx)
|
||
|
}
|
||
|
|
||
|
// DeleteBanner 删除轮播图
|
||
|
func (b *BannerApi) DeleteBanner(ctx *gin.Context) {
|
||
|
var banner common.Banner
|
||
|
if err := ctx.ShouldBind(&banner); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误" + err.Error())
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := bannerService.DeleteBanner(&banner)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("删除失败" + err.Error())
|
||
|
r.FailWithMessage("删除失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("删除成功", ctx)
|
||
|
}
|
||
|
|
||
|
// GetBannerById 根据id获取轮播图
|
||
|
func (b *BannerApi) GetBannerById(ctx *gin.Context) {
|
||
|
Id := ctx.Param("id")
|
||
|
if Id == "" {
|
||
|
global.GVA_LOG.Error("参数错误")
|
||
|
r.FailWithMessage("参数错误", ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
banner, err := bannerService.GetBannerById(Id)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("获取失败" + err.Error())
|
||
|
r.FailWithMessage("获取失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithDetailed(banner, "获取成功", ctx)
|
||
|
}
|