init: radio init commit
This commit is contained in:
@@ -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