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 application/json // @Param data body request.AddHistory true "收听信息" // @Success 200 {object} response.Response // @Router /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) } // DeleteHistory 删除收听历史 // @Tags 用户互动 // @Summary 删除收听历史 // @Produce application/json // @Param id query string true "节目ID" // @Success 200 {object} response.Response // @Router /history/delete [post] func (a *InteractionApi) DeleteHistory(c *gin.Context) { var req request.RemoveHistory err := c.ShouldBindJSON(&req) if err != nil { response.FailWithMsg("参数错误: "+err.Error(), c) return } userId := auth.GetUserId(c) err = interactionService.DeleteHistory(userId, req.ProgramId) if err != nil { global.Logger.Error("删除收听历史失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("删除成功", c) } // DeleteAllHistory 删除所有收听历史 // @Tags 用户互动 // @Summary 删除所有收听历史 // @Produce application/json // @Success 200 {object} response.Response // @Router /history/deleteAllHistory [get] func (a *InteractionApi) DeleteAllHistory(c *gin.Context) { userId := auth.GetUserId(c) err := interactionService.DeleteAllHistory(userId) if err != nil { global.Logger.Error("删除所有收听历史失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("删除成功", c) } // GetHistoryList 获取收听历史列表 // @Tags 用户互动 // @Summary 获取收听历史列表 // @Produce application/json // @Param data body request.GetHistoryList true "分页查询" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.ToggleLike true "节目ID" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.GetFavoriteList true "分页查询" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.AddFavorite true "节目ID" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.RemoveFavorite true "节目ID" // @Success 200 {object} response.Response // @Router /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) } // RemoveAllFavorite 清空所有收藏 // @Tags 用户互动 // @Summary 清空所有收藏 // @Produce application/json // @Param data body request.RemoveFavorite true "节目ID" // @Success 200 {object} response.Response // @Router /favorite/removeAll [get] func (a *InteractionApi) RemoveAllFavorite(c *gin.Context) { userId := auth.GetUserId(c) err := interactionService.RemoveAllFavorite(userId) if err != nil { global.Logger.Error("清空所有收藏失败!", zap.Error(err)) response.FailWithMsg(err.Error(), c) return } response.OkWithMsg("清空所有收藏成功", c) } // GetCommentList 获取评论列表 // @Tags 用户互动 // @Summary 获取评论列表 // @Produce application/json // @Param data body request.GetCommentList true "分页查询" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.AddComment true "评论信息" // @Success 200 {object} response.Response // @Router /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 application/json // @Param data body request.DeleteComment true "评论ID" // @Success 200 {object} response.Response // @Router /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) }