141 lines
3.6 KiB
Go
141 lines
3.6 KiB
Go
package radio
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
common "sundynix-go/model/commom/request"
|
|
"sundynix-go/model/commom/response"
|
|
"sundynix-go/model/radio/request"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ProgramApi struct{}
|
|
|
|
// GetProgramList 获取节目列表
|
|
// @Tags 节目管理
|
|
// @Summary 获取节目列表
|
|
// @Produce application/json
|
|
// @Param data body request.GetProgramList true "分页查询"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/program/list [post]
|
|
func (a *ProgramApi) GetProgramList(c *gin.Context) {
|
|
var req request.GetProgramList
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
|
|
list, total, err := programService.GetProgramList(req)
|
|
if err != nil {
|
|
global.Logger.Error("获取节目列表失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Current,
|
|
PageSize: req.PageSize,
|
|
}, c)
|
|
}
|
|
|
|
// GetProgramDetail 获取节目详情
|
|
// @Tags 节目管理
|
|
// @Summary 获取节目详情
|
|
// @Produce application/json
|
|
// @Param id query string true "节目ID"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/program/detail [get]
|
|
func (a *ProgramApi) GetProgramDetail(c *gin.Context) {
|
|
id := c.Query("id")
|
|
if id == "" {
|
|
response.FailWithMsg("参数错误: id不能为空", c)
|
|
return
|
|
}
|
|
program, err := programService.GetProgramById(id)
|
|
if err != nil {
|
|
global.Logger.Error("获取节目详情失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(program, c)
|
|
}
|
|
|
|
// SaveProgram 保存节目
|
|
// @Tags 节目管理
|
|
// @Summary 保存节目
|
|
// @Accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.SaveProgram true "节目信息"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/program/save [post]
|
|
func (a *ProgramApi) SaveProgram(c *gin.Context) {
|
|
var req request.SaveProgram
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if err := programService.SaveProgram(req); err != nil {
|
|
global.Logger.Error("保存节目失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("保存成功", c)
|
|
}
|
|
|
|
// UpdateProgram 更新节目
|
|
// @Tags 节目管理
|
|
// @Summary 更新节目
|
|
// @Accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.UpdateProgram true "节目信息"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/program/update [post]
|
|
func (a *ProgramApi) UpdateProgram(c *gin.Context) {
|
|
var req request.UpdateProgram
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
|
|
if err := programService.UpdateProgram(req); err != nil {
|
|
global.Logger.Error("更新节目失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("更新成功", c)
|
|
}
|
|
|
|
// DeleteProgram 删除节目
|
|
// @Tags 节目管理
|
|
// @Summary 删除节目
|
|
// @Produce json
|
|
// @Param data body common.GetById true "节目ID"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/program/delete [post]
|
|
func (a *ProgramApi) DeleteProgram(c *gin.Context) {
|
|
var req common.IdsReq
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: id不能为空", c)
|
|
return
|
|
}
|
|
|
|
if err := programService.DeleteProgram(req.Ids); err != nil {
|
|
global.Logger.Error("删除节目失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("删除成功", c)
|
|
}
|