init: radio init commit
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
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 CategoryApi struct{}
|
||||
|
||||
// GetCategoryPage 获取分类列表
|
||||
// @Tags 分类管理
|
||||
// @Summary 获取分类列表
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetCategoryList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/category/page [post]
|
||||
func (a *CategoryApi) GetCategoryPage(c *gin.Context) {
|
||||
var req request.GetCategoryList
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := categoryService.GetCategoryList(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)
|
||||
}
|
||||
|
||||
// GetCategoryList 获取分类列表
|
||||
// @Tags 分类管理
|
||||
// @Summary 获取分类列表
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/category/list [get]
|
||||
func (a *CategoryApi) GetCategoryList(c *gin.Context) {
|
||||
list, err := categoryService.GetAllCategory()
|
||||
if err != nil {
|
||||
global.Logger.Error("获取分类列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.ListResult{
|
||||
List: list,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// GetCategoryDetail 获取分类详情
|
||||
// @Tags 分类管理
|
||||
// @Summary 获取分类详情
|
||||
// @Produce application/json
|
||||
// @Param id query string true "分类ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/category/detail [get]
|
||||
func (a *CategoryApi) GetCategoryDetail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
response.FailWithMsg("参数错误: id不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
category, err := categoryService.GetCategoryById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取分类详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(category, c)
|
||||
}
|
||||
|
||||
// SaveCategory 保存分类
|
||||
// @Tags 分类管理
|
||||
// @Summary 保存分类
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SaveCategory true "分类信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/category/save [post]
|
||||
func (a *CategoryApi) SaveCategory(c *gin.Context) {
|
||||
var req request.SaveCategory
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := categoryService.SaveCategory(req); err != nil {
|
||||
global.Logger.Error("保存分类失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("保存成功", c)
|
||||
}
|
||||
|
||||
// UpdateCategory 更新分类
|
||||
// @Tags 分类管理
|
||||
// @Summary 更新分类
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.UpdateCategory true "Success 200 {分类信息"
|
||||
// @object} response.Response
|
||||
// @Router /radio/category/update [post]
|
||||
func (a *CategoryApi) UpdateCategory(c *gin.Context) {
|
||||
var req request.UpdateCategory
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := categoryService.UpdateCategory(req); err != nil {
|
||||
global.Logger.Error("更新分类失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("更新成功", c)
|
||||
}
|
||||
|
||||
// DeleteCategory 删除分类
|
||||
// @Tags 分类管理
|
||||
// @Summary 删除分类
|
||||
// @Produce application/json
|
||||
// @Param data body common.GetById true "分类ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/category/delete [post]
|
||||
func (a *CategoryApi) DeleteCategory(c *gin.Context) {
|
||||
var req common.IdReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil || req.Id == "" {
|
||||
response.FailWithMsg("参数错误: id不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := categoryService.DeleteCategory(req.Id); err != nil {
|
||||
global.Logger.Error("删除分类失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("删除成功", c)
|
||||
}
|
||||
Reference in New Issue
Block a user