Files
2026-10-26 16:28:14 +08:00

485 lines
17 KiB
Go

package playletapi
import (
"videoweb/app/api/proto"
"videoweb/app/service/playletser"
"videoweb/app/service/slugser"
"videoweb/app/service/videoser"
"videoweb/pub/common"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
// HomePlaylet app端短剧首页
// @Tags app短剧相关接口
// @Summary app端短剧首页 -- by 王鸣
// @Description 返回短剧Banner、首页配置模块、公告、广告和SEO信息
// @Produce json
// @Success 200 {object} proto.HomePlayletResponse "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/home [get]
func HomePlaylet(ctx *gin.Context) {
resp, err := playletser.Home(ctx)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// HomeConfigList 按首页配置分页查询内容
// @Tags app短剧相关接口
// @Summary app端首页配置内容列表 -- by 王鸣
// @Description 按首页配置ID或slug分页查询内容,同时传入时优先使用slug
// @Produce json
// @Param params query proto.PlayletHomeConfigListReq true "首页配置内容分页请求"
// @Success 200 {object} proto.PlayletHomeConfigListResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/home-config/list [get]
func HomeConfigList(ctx *gin.Context) {
var req proto.PlayletHomeConfigListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.HomeConfigList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// TopicDetail 查询短剧题材或视频分类专题详情
// @Tags app短剧相关接口
// @Summary app端专题详情 -- by 王鸣
// @Produce json
// @Param params query proto.PlayletTopicDetailReq true "专题详情请求"
// @Success 200 {object} proto.PlayletTopicDetailResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/topic/detail [get]
func TopicDetail(ctx *gin.Context) {
var req proto.PlayletTopicDetailReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.TopicDetail(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ThemeList 查询全部已启用短剧题材
// @Tags app短剧相关接口
// @Summary app端短剧题材列表
// @Produce json
// @Success 200 {object} proto.PlayletThemeListResp "成功"
// @Router /api/app/playlet/theme/list [get]
func ThemeList(ctx *gin.Context) {
resp, err := playletser.PlayletThemeList(ctx)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// List 分页查询已上架短剧并穿插广告
// @Tags app短剧相关接口
// @Summary app端短剧列表 -- by 王鸣
// @Description 按题材和排序筛选已上架短剧,最近更新按更新时间降序,每4部短剧穿插1条广告
// @Produce json
// @Param params query proto.PlayletListReq true "短剧列表请求"
// @Success 200 {object} proto.PlayletListResp{list=[]proto.PlayletRecommendListItem} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/list [get]
func List(ctx *gin.Context) {
var req proto.PlayletListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.PlayletList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ContentList 分页查询上架短剧或视频并穿插广告
// @Tags app短剧相关接口
// @Summary app端短剧或视频全站排行榜列表 -- by 王鸣
// @Description 按观看量查询上架内容,dataType 为 1 时每 4 条短剧穿插 1 条广告,为 2 时每 5 条视频穿插 1 条广告,并返回广告配置
// @Produce json
// @Param params query proto.PlayletContentListReq true "短剧或视频列表请求"
// @Success 200 {object} proto.PlayletContentListResp{list=[]proto.PlayletContentListItem} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/content/list [get]
func ContentList(ctx *gin.Context) {
var req proto.PlayletContentListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ContentList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// RecommendList app端推荐短剧列表
// @Tags app短剧相关接口
// @Summary app端推荐短剧列表 -- by 王鸣
// @Description 分页查询短剧列表,带穿插列表广告,每间隔8条短剧数据插入一个广告
// @Accept json
// @Produce json
// @Param params query proto.PlayletRecommendListReq true "推荐短剧列表请求"
// @Success 200 {object} proto.PlayletRecommendListResp{list=[]proto.PlayletRecommendListItem} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/recommend/list [get]
func RecommendList(ctx *gin.Context) {
var req proto.PlayletRecommendListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.PlayletRecommendList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// GuessList 分页查询猜你喜欢短剧
// @Tags app短剧相关接口
// @Summary 猜你喜欢短剧列表 -- by 王鸣
// @Description id可选,传入时排除当前短剧,按观看量降序查询上架短剧
// @Produce json
// @Param params query proto.PlayletGuessListReq true "猜你喜欢短剧请求"
// @Success 200 {object} proto.PlayletGuessListResp{list=[]proto.PlayletRecommendListItem} "成功"
// @Router /api/app/playlet/guess/list [get]
func GuessList(ctx *gin.Context) {
var req proto.PlayletGuessListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.PlayletGuessList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// TagList app端根据标签ID查询短剧列表
// @Tags app短剧相关接口
// @Summary app端根据标签ID查询短剧列表 -- by 王鸣
// @Description 根据统一标签ID分页查询已上架短剧
// @Accept json
// @Produce json
// @Param id path int true "标签ID"
// @Param pageNum query int false "页码,默认1"
// @Param pageSize query int false "每页数量,默认20,最大100"
// @Success 200 {object} proto.PlayletRecommendListResp{list=[]proto.PlayletRecommendListItem} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/tag/{id} [get]
func TagList(ctx *gin.Context) {
var req proto.ContentTagPageReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
pathID, pathSlug := slugser.ParseIDOrSlug(ctx.Param("id"))
if req.Id <= 0 {
req.Id = pathID
}
if req.Slug == "" {
req.Slug = pathSlug
}
resp, err := playletser.PlayletTagList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryPlayletInfo 短剧详情
// @Tags app短剧相关接口
// @Summary 短剧详情 -- by 王鸣
// @Description 查询短剧详情、剧集列表、点赞状态和收藏状态
// @Accept json
// @Produce json
// @Param params query proto.QueryPlayletInfoReq true "短剧详情查询请求"
// @Success 200 {object} proto.QueryPlayletInfoResp{playletInfo=proto.PlayletDetailInfo,chapterList=[]proto.PlayletChapterInfo} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/info [get]
func QueryPlayletInfo(ctx *gin.Context) {
var req proto.QueryPlayletInfoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.QueryPlayletInfo(ctx, common.GetUserId(ctx), videoser.H5M3U8RequestIP(ctx), ctx.Request.UserAgent(), &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryPlayletChapterInfo 短剧剧集详情
// @Tags app短剧相关接口
// @Summary app端短剧剧集详情 -- by 王鸣
// @Description 根据剧集ID查询短剧剧集详情、所属短剧、剧集列表、热门短剧列表和点赞状态
// @Accept json
// @Produce json
// @Param params query proto.QueryPlayletChapterInfoReq true "短剧剧集详情查询请求"
// @Success 200 {object} proto.QueryPlayletChapterInfoResp{chapterInfo=proto.PlayletChapterInfo,playletInfo=proto.PlayletData,chapterList=[]proto.PlayletChapterInfo,hotPlayletList=[]proto.PlayletData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/chapter/info [get]
func QueryPlayletChapterInfo(ctx *gin.Context) {
var req proto.QueryPlayletChapterInfoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.QueryPlayletChapterInfo(ctx, common.GetUserId(ctx), videoser.H5M3U8RequestIP(ctx), ctx.Request.UserAgent(), &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// LikePlaylet 点赞或取消点赞短剧
// @Tags app短剧相关接口
// @Summary 点赞或取消点赞短剧 -- by 王鸣
// @Description 当前登录用户点赞或取消点赞指定短剧,isLike=true表示点赞,isLike=false表示取消点赞
// @Accept json
// @Produce json
// @Param param body proto.LikePlayletReq true "点赞或取消点赞请求"
// @Success 200 {object} proto.LikePlayletResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/like [post]
func LikePlaylet(ctx *gin.Context) {
var req proto.LikePlayletReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
userId := common.GetUserId(ctx)
if userId <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
ua, _ := common.GetUA(ctx)
if ua.UserAgent == "" {
ua.UserAgent = ctx.Request.UserAgent()
}
resp, err := playletser.LikePlaylet(ctx, userId, ctx.ClientIP(), ua, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryLikePlayletList 当前用户点赞短剧分页列表
// @Tags app短剧相关接口
// @Summary 当前用户点赞短剧分页列表
// @Description 按点赞时间倒序返回当前用户点赞的上架短剧
// @Produce json
// @Param params query proto.QueryLikePlayletListReq true "点赞短剧分页请求"
// @Success 200 {object} proto.QueryLikePlayletListResp{list=[]proto.PlayletData} "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/like/list [get]
func QueryLikePlayletList(ctx *gin.Context) {
var req proto.QueryLikePlayletListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
resp, err := playletser.QueryLikePlayletList(ctx, userID, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// FavoritePlaylet 收藏或取消收藏短剧
// @Tags app短剧相关接口
// @Summary 收藏或取消收藏短剧
// @Description isFavorite=true 收藏 false 取消收藏
// @Accept json
// @Produce json
// @Param param body proto.FavoritePlayletReq true "短剧收藏请求"
// @Success 200 {object} proto.FavoritePlayletResp "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/favorite [post]
func FavoritePlaylet(ctx *gin.Context) {
var req proto.FavoritePlayletReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
ua, _ := common.GetUA(ctx)
if ua.UserAgent == "" {
ua.UserAgent = ctx.Request.UserAgent()
}
resp, err := playletser.FavoritePlaylet(ctx, userID, ctx.ClientIP(), ua, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryFavoritePlayletList 当前用户收藏短剧分页列表
// @Tags app短剧相关接口
// @Summary 当前用户收藏短剧分页列表
// @Produce json
// @Param params query proto.QueryFavoritePlayletListReq true "收藏短剧分页请求"
// @Success 200 {object} proto.QueryFavoritePlayletListResp{list=[]proto.PlayletData} "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/favorite/list [get]
func QueryFavoritePlayletList(ctx *gin.Context) {
var req proto.QueryFavoritePlayletListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
resp, err := playletser.QueryFavoritePlayletList(ctx, userID, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ReportPlayletHistory 播放成功后记录当前用户的短剧剧集
// @Tags app短剧相关接口
// @Summary 上报短剧观看历史
// @Accept json
// @Produce json
// @Param param body proto.PlayletHistoryReportReq true "当前播放短剧和剧集"
// @Success 200 {object} proto.PlayletHistoryReportResp "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/history [post]
func ReportPlayletHistory(ctx *gin.Context) {
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
var req proto.PlayletHistoryReportReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.ReportPlayletHistory(ctx, userID, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryPlayletHistoryList 当前用户短剧观看历史分页列表
// @Tags app短剧相关接口
// @Summary 短剧观看历史列表
// @Produce json
// @Param params query proto.PlayletHistoryListReq true "分页请求"
// @Success 200 {object} proto.PlayletHistoryListResp{list=[]proto.PlayletHistoryItem} "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/history/list [get]
func QueryPlayletHistoryList(ctx *gin.Context) {
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
var req proto.PlayletHistoryListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.QueryPlayletHistoryList(ctx, userID, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ClearPlayletHistory 清空当前用户短剧观看历史
// @Tags app短剧相关接口
// @Summary 清空短剧观看历史
// @Produce json
// @Success 200 {object} proto.PlayletHistoryClearResp "成功"
// @Security ApiKeyAuth
// @Router /api/app/playlet/history [delete]
func ClearPlayletHistory(ctx *gin.Context) {
userID := common.GetUserId(ctx)
if userID <= 0 {
common.ServerJSON(ctx, srvdef.InvalidToken, "")
return
}
resp, err := playletser.ClearPlayletHistory(ctx, userID)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// QueryPlayletRankList 短剧排行榜分页列表
// @Tags app短剧相关接口
// @Summary 短剧排行榜分页列表 -- by 王鸣
// @Description 分页查询短剧排行榜,rankPeriod=0点赞榜(累计点赞)、1周榜/2月榜/3年榜(周期观看量),独立缓存10分钟,每榜最多50条,pageSize不是50时强制为50
// @Accept json
// @Produce json
// @Param params query proto.PlayletRankReq true "短剧排行榜分页请求"
// @Success 200 {object} proto.PlayletRankResp{list=[]proto.PlayletRankData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/rank/list [get]
func QueryPlayletRankList(ctx *gin.Context) {
var req proto.PlayletRankReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, "")
return
}
resp, err := playletser.QueryPlayletRank(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err, err.GetMsg())
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}