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)
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package radio
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
common "sundynix-go/model/commom/request"
|
||||
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/radio/request"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ChannelApi struct{}
|
||||
|
||||
// GetChannelList 获取频道列表
|
||||
// @Tags 频道管理
|
||||
// @Summary 获取频道列表
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetChannelList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/channel/list [post]
|
||||
func (a *ChannelApi) GetChannelList(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.GetChannelList
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := channelService.GetChannelList(userId, 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)
|
||||
}
|
||||
|
||||
// GetChannelDetail 获取频道详情
|
||||
// @Tags 频道管理
|
||||
// @Summary 获取频道详情
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param id query string true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/channel/detail [get]
|
||||
func (a *ChannelApi) GetChannelDetail(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
response.FailWithMsg("参数错误: id不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := channelService.GetChannelById(userId, id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取频道详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(channel, c)
|
||||
}
|
||||
|
||||
// SaveChannel 保存频道
|
||||
// @Tags 频道管理
|
||||
// @Summary 保存频道
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.SaveChannel true "频道信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/channel/save [post]
|
||||
func (a *ChannelApi) SaveChannel(c *gin.Context) {
|
||||
var req request.SaveChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := channelService.SaveChannel(req); err != nil {
|
||||
global.Logger.Error("保存频道失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("保存成功", c)
|
||||
}
|
||||
|
||||
// UpdateChannel 更新频道
|
||||
// @Tags 频道管理
|
||||
// @Summary 更新频道
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.UpdateChannel true "频道信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/channel/update [post]
|
||||
func (a *ChannelApi) UpdateChannel(c *gin.Context) {
|
||||
var req request.UpdateChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := channelService.UpdateChannel(req); err != nil {
|
||||
global.Logger.Error("更新频道失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("更新成功", c)
|
||||
}
|
||||
|
||||
// DeleteChannel 删除频道
|
||||
// @Tags 频道管理
|
||||
// @Summary 删除频道
|
||||
// @Produce json
|
||||
// @Param data body common.GetById true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/channel/delete [post]
|
||||
func (a *ChannelApi) DeleteChannel(c *gin.Context) {
|
||||
var req common.IdReq
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil || req.Id == "" {
|
||||
response.FailWithMsg("参数错误: id不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := channelService.DeleteChannel(req.Id); err != nil {
|
||||
global.Logger.Error("删除频道失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("删除成功", c)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package radio
|
||||
|
||||
import "sundynix-go/service"
|
||||
|
||||
type ApiGroup struct {
|
||||
CategoryApi
|
||||
ChannelApi
|
||||
ProgramApi
|
||||
SubscriptionApi
|
||||
InteractionApi
|
||||
}
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
var (
|
||||
categoryService = service.GroupApp.RadioServiceGroup.CategoryService
|
||||
channelService = service.GroupApp.RadioServiceGroup.ChannelService
|
||||
programService = service.GroupApp.RadioServiceGroup.ProgramService
|
||||
subscriptionService = service.GroupApp.RadioServiceGroup.SubscriptionService
|
||||
interactionService = service.GroupApp.RadioServiceGroup.InteractionService
|
||||
)
|
||||
@@ -0,0 +1,253 @@
|
||||
package radio
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/radio/request"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type InteractionApi struct{}
|
||||
|
||||
// AddHistory 添加收听历史
|
||||
// @Tags 用户互动
|
||||
// @Summary 添加收听历史
|
||||
// @Produce json
|
||||
// @Param data body request.AddHistory true "收听信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/history/add [post]
|
||||
func (a *InteractionApi) AddHistory(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.AddHistory
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := interactionService.AddHistory(userId, req); err != nil {
|
||||
global.Logger.Error("添加收听历史失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("添加成功", c)
|
||||
}
|
||||
|
||||
// GetHistoryList 获取收听历史列表
|
||||
// @Tags 用户互动
|
||||
// @Summary 获取收听历史列表
|
||||
// @Produce json
|
||||
// @Param data body request.GetHistoryList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/history/list [post]
|
||||
func (a *InteractionApi) GetHistoryList(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.GetHistoryList
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := interactionService.GetHistoryList(userId, 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,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// ToggleLike 切换点赞状态
|
||||
// @Tags 用户互动
|
||||
// @Summary 切换点赞状态
|
||||
// @Produce json
|
||||
// @Param data body request.ToggleLike true "节目ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/like/toggle [post]
|
||||
func (a *InteractionApi) ToggleLike(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.ToggleLike
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
isLiked, err := interactionService.ToggleLike(userId, req.ProgramId)
|
||||
if err != nil {
|
||||
global.Logger.Error("操作失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(isLiked, c)
|
||||
}
|
||||
|
||||
// GetFavoriteList 获取收藏列表
|
||||
// @Tags 用户互动
|
||||
// @Summary 获取收藏列表
|
||||
// @Produce json
|
||||
// @Param data body request.GetFavoriteList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/favorite/list [post]
|
||||
func (a *InteractionApi) GetFavoriteList(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.GetFavoriteList
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := interactionService.GetFavoriteList(userId, 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,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// AddFavorite 添加收藏
|
||||
// @Tags 用户互动
|
||||
// @Summary 添加收藏
|
||||
// @Produce json
|
||||
// @Param data body request.AddFavorite true "节目ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/favorite/add [post]
|
||||
func (a *InteractionApi) AddFavorite(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.AddFavorite
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := interactionService.AddFavorite(userId, req.ProgramId); err != nil {
|
||||
global.Logger.Error("添加收藏失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("收藏成功", c)
|
||||
}
|
||||
|
||||
// RemoveFavorite 取消收藏
|
||||
// @Tags 用户互动
|
||||
// @Summary 取消收藏
|
||||
// @Produce json
|
||||
// @Param data body request.RemoveFavorite true "节目ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/favorite/remove [post]
|
||||
func (a *InteractionApi) RemoveFavorite(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.RemoveFavorite
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := interactionService.RemoveFavorite(userId, req.ProgramId); err != nil {
|
||||
global.Logger.Error("取消收藏失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("取消收藏成功", c)
|
||||
}
|
||||
|
||||
// GetCommentList 获取评论列表
|
||||
// @Tags 用户互动
|
||||
// @Summary 获取评论列表
|
||||
// @Produce json
|
||||
// @Param data body request.GetCommentList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/comment/list [post]
|
||||
func (a *InteractionApi) GetCommentList(c *gin.Context) {
|
||||
var req request.GetCommentList
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := interactionService.GetCommentList(req.ProgramId, 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,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// AddComment 添加评论
|
||||
// @Tags 用户互动
|
||||
// @Summary 添加评论
|
||||
// @Produce json
|
||||
// @Param data body request.AddComment true "评论信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/comment/add [post]
|
||||
func (a *InteractionApi) AddComment(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.AddComment
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := interactionService.AddComment(userId, req); err != nil {
|
||||
global.Logger.Error("添加评论失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("评论成功", c)
|
||||
}
|
||||
|
||||
// DeleteComment 删除评论
|
||||
// @Tags 用户互动
|
||||
// @Summary 删除评论
|
||||
// @Produce json
|
||||
// @Param data body request.DeleteComment true "评论ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/comment/delete [post]
|
||||
func (a *InteractionApi) DeleteComment(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.DeleteComment
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := interactionService.DeleteComment(userId, req.CommentId); err != nil {
|
||||
global.Logger.Error("删除评论失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("删除成功", c)
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
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)
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package radio
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
common "sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/radio/request"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type SubscriptionApi struct{}
|
||||
|
||||
// GetSubscriptionList 获取订阅列表
|
||||
// @Tags 订阅管理
|
||||
// @Summary 获取我的订阅列表
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetSubscriptionList true "分页查询"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/list [post]
|
||||
func (a *SubscriptionApi) GetSubscriptionList(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req common.PageInfo
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := subscriptionService.GetUserSubscription(userId, 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,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// CanSubscribe 检查是否可以订阅
|
||||
// @Tags 订阅管理
|
||||
// @Summary 检查是否可以订阅
|
||||
// @Produce application/json
|
||||
// @Param data body request.SubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/can-subscribe [post]
|
||||
func (a *SubscriptionApi) CanSubscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.SubscribeChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
can, _, err := subscriptionService.CanSubscribe(userId, req.ChannelId)
|
||||
if err != nil {
|
||||
global.Logger.Error("检查订阅权限失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(can, c)
|
||||
}
|
||||
|
||||
// Subscribe 订阅频道
|
||||
// @Tags 订阅管理
|
||||
// @Summary 订阅频道
|
||||
// @Produce application/json
|
||||
// @Param data body request.SubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/subscribe [post]
|
||||
func (a *SubscriptionApi) Subscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.SubscribeChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
can, reason, err := subscriptionService.CanSubscribe(userId, req.ChannelId)
|
||||
if err != nil {
|
||||
global.Logger.Error("订阅失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if !can {
|
||||
response.FailWithMsg(reason, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 订阅类型 1:免费
|
||||
if err := subscriptionService.Subscribe(userId, req.ChannelId, 1); err != nil {
|
||||
global.Logger.Error("订阅失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("订阅成功", c)
|
||||
}
|
||||
|
||||
// Unsubscribe 退订频道
|
||||
// @Tags 订阅管理
|
||||
// @Summary 退订频道
|
||||
// @Produce application/json
|
||||
// @Param data body request.UnsubscribeChannel true "频道ID"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /radio/subscription/unsubscribe [post]
|
||||
func (a *SubscriptionApi) Unsubscribe(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
var req request.UnsubscribeChannel
|
||||
err := c.ShouldBindJSON(&req)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := subscriptionService.Unsubscribe(userId, req.ChannelId); err != nil {
|
||||
global.Logger.Error("退订失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMsg("退订成功", c)
|
||||
}
|
||||
Reference in New Issue
Block a user