Files
web_hgtv_server/app/api/playletapi/playlet.go
T
rootandClaude Opus 5.5 7974a42301 Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 11:07:42 +08:00

548 lines
20 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package playletapi
import (
"videoweb/app/api/proto"
"videoweb/app/service/playletser"
"videoweb/pub/common"
"videoweb/pub/common/ipaddr"
"videoweb/pub/common/srvdef"
"github.com/gin-gonic/gin"
)
// HomePlaylet app端首页短剧接口
// @Tags app短剧相关接口
// @Summary app端首页短剧接口 --by 王鸣
// @Description 无请求参数,返回首页banner、最近更新和启用短剧分类数据;homeCategoryData按分类rank倒序返回全部启用分类,每个分类最多16条短剧
// @Accept json
// @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.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// RecommendList app端分页查询分类短剧
// @Tags app短剧相关接口
// @Summary app端分页查询分类短剧(更多) --by 王鸣
// @Description 根据短剧分类ID或分类slug分页查询已上架短剧;slug非空时优先按slug解析分类ID;pageSize默认10、最大100
// @Accept json
// @Produce json
// @Param params query proto.PlayletRecommendListReq true "分类短剧分页请求"
// @Success 200 {object} proto.PlayletRecommendListResp{list=[]proto.CommonData} "成功"
// @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, nil)
return
}
resp, err := playletser.RecommendList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// List app端分页查询短剧
// @Tags app短剧相关接口
// @Summary 短剧 --by 王鸣
// @Description 分页查询已上架短剧;可按题材ID或题材slug筛选,slug非空时优先按slug解析题材ID
// @Accept json
// @Produce json
// @Param params query proto.PlayletVideoReq true "分页查询短剧请求"
// @Success 200 {object} proto.PlayletVideoResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/list [get]
func List(ctx *gin.Context) {
var req proto.PlayletVideoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.List(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// Rank app端分页查询短剧排行榜
// @Tags app短剧相关接口
// @Summary 短剧排行榜 --by 王鸣
// @Description 分页查询已上架短剧排行榜;sortOrder=1按热度值倒序,2按上架时间倒序,3按收藏数倒序
// @Accept json
// @Produce json
// @Param params query proto.PlayletRankReq true "分页查询短剧排行榜请求"
// @Success 200 {object} proto.PlayletRankResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/rank [get]
func Rank(ctx *gin.Context) {
var req proto.PlayletRankReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.Rank(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// OperateList app端按运营类型分页查询短剧
// @Tags app短剧相关接口
// @Summary app端按运营类型分页查询短剧
// @Description 按运营类型查询已上架短剧;operateType=1短剧 2漫剧;filterType=1最近更新(按上架时间) 2当前热播(按收藏数) 3独家原创(原创且按推荐排序)
// @Accept json
// @Produce json
// @Param params query proto.PlayletOperateListReq true "按运营类型分页查询短剧请求"
// @Success 200 {object} proto.PlayletOperateListResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/operate/list [get]
func OperateList(ctx *gin.Context) {
var req proto.PlayletOperateListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.OperateList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// TodayUpdate app端分页查询今日更新短剧
// @Tags app短剧相关接口
// @Summary app端分页查询今日更新短剧 --by 王鸣
// @Description 分页查询已上架短剧
// @Accept json
// @Produce json
// @Param params query proto.PlayletTodayUpdateReq true "分页查询今日更新短剧请求"
// @Success 200 {object} proto.PlayletTodayUpdateResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/today-update [get]
func TodayUpdate(ctx *gin.Context) {
var req proto.PlayletTodayUpdateReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.TodayUpdate(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// TagVideoList app端根据标签ID分页查询短剧
// @Tags app短剧相关接口
// @Summary app端根据标签ID分页查询短剧 --by 王鸣
// @Description 根据标签ID或标签slug分页查询已上架短剧;slug非空时优先按slug解析标签ID
// @Accept json
// @Produce json
// @Param params query proto.PlayletTagVideoReq true "根据标签ID分页查询短剧请求"
// @Success 200 {object} proto.PlayletTagVideoResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/tag/list [get]
func TagVideoList(ctx *gin.Context) {
var req proto.PlayletTagVideoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.TagVideoList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// Search app端ES分页搜索短剧
// @Tags app短剧相关接口
// @Summary app端ES分页搜索短剧 --by 王鸣
// @Description 使用ES分页搜索已上架短剧,支持剧名、题材名、简介和标签名检索
// @Accept json
// @Produce json
// @Param params query proto.PlayletSearchReq true "短剧ES分页搜索请求"
// @Success 200 {object} proto.PlayletSearchResp{list=[]proto.CommonData} "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/search [get]
func Search(ctx *gin.Context) {
var req proto.PlayletSearchReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.Search(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// HotLike app端热搜词和猜你喜欢
// @Tags app短剧相关接口
// @Summary app端热搜词和猜你喜欢
// @Description 返回缓存的前10个热搜词,以及按收藏量最多的15部猜你喜欢短剧
// @Accept json
// @Produce json
// @Success 200 {object} proto.PlayletHotLikeResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/hot-like [get]
func HotLike(ctx *gin.Context) {
common.ServerJSON(ctx, srvdef.Success, playletser.HotLike(ctx))
}
// SetLike app端短剧点赞/取消点赞
// @Tags app短剧相关接口
// @Summary app端短剧点赞/取消点赞 --by 王鸣
// @Description 设置当前用户短剧点赞状态,点赞数只在状态真实变化时增减
// @Accept json
// @Produce json
// @Param param body proto.PlayletLikeSetReq true "短剧点赞设置请求"
// @Success 200 {object} proto.PlayletLikeSetResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/like/set [post]
func SetLike(ctx *gin.Context) {
var req proto.PlayletLikeSetReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.SetLike(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SetCollect app端短剧收藏/取消收藏
// @Tags app短剧相关接口
// @Summary app端短剧收藏/取消收藏 --by 王鸣
// @Description 设置当前用户短剧收藏状态,收藏数只在状态真实变化时增减
// @Accept json
// @Produce json
// @Param param body proto.PlayletCollectSetReq true "短剧收藏设置请求"
// @Success 200 {object} proto.PlayletCollectSetResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/collect/set [post]
func SetCollect(ctx *gin.Context) {
var req proto.PlayletCollectSetReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.SetCollect(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ForwardHeat app端短剧转发增加热度
// @Tags app短剧相关接口
// @Summary app端短剧转发增加热度 --by 王鸣
// @Description 请求一次短剧热度值增加5,仅支持已上架短剧
// @Accept json
// @Produce json
// @Param param body proto.PlayletForwardHeatReq true "短剧转发加热度请求"
// @Success 200 {object} proto.PlayletForwardHeatResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/forward/heat [post]
func ForwardHeat(ctx *gin.Context) {
var req proto.PlayletForwardHeatReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ForwardHeat(ctx, common.GetUserId(ctx), ipaddr.ResolveClientIP(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// CollectList app端我的短剧收藏列表
// @Tags app短剧相关接口
// @Summary app端我的短剧收藏列表 --by 王鸣
// @Description 按当前用户收藏时间倒序分页返回短剧收藏列表,并返回已看/未看集数和最近观看位置
// @Accept json
// @Produce json
// @Param params query proto.PlayletCollectListReq true "我的短剧收藏列表请求"
// @Success 200 {object} proto.PlayletCollectListResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/collect/list [get]
func CollectList(ctx *gin.Context) {
var req proto.PlayletCollectListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.CollectList(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// HistoryList app端我的短剧观看历史列表
// @Tags app短剧相关接口
// @Summary app端我的短剧观看历史列表 --by 王鸣
// @Description 按当前用户最近观看时间倒序分页返回短剧观看历史;pageSize默认20、最大100
// @Accept json
// @Produce json
// @Param params query proto.PlayletHistoryListReq true "观看历史列表请求"
// @Success 200 {object} proto.PlayletHistoryListResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/history/list [get]
func HistoryList(ctx *gin.Context) {
var req proto.PlayletHistoryListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.HistoryList(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ClearHistory app端清空我的短剧观看历史
// @Tags app短剧相关接口
// @Summary app端清空我的短剧观看历史 --by 王鸣
// @Description 仅清空观看历史,不影响收藏列表和观看进度
// @Accept json
// @Produce json
// @Success 200 {object} proto.PlayletHistoryClearResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/history/clear [post]
func ClearHistory(ctx *gin.Context) {
resp, err := playletser.ClearHistory(ctx, common.GetUserId(ctx))
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SetChapterLike app端短剧剧集点赞/取消点赞
// @Tags app短剧相关接口
// @Summary app端短剧剧集点赞/取消点赞 --by 王鸣
// @Description 设置当前用户短剧剧集点赞状态,点赞数只在状态真实变化时增减
// @Accept json
// @Produce json
// @Param param body proto.PlayletChapterLikeSetReq true "短剧剧集点赞设置请求"
// @Success 200 {object} proto.PlayletChapterLikeSetResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/chapter/like/set [post]
func SetChapterLike(ctx *gin.Context) {
var req proto.PlayletChapterLikeSetReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.SetChapterLike(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// SetChapterCollect app端短剧剧集收藏/取消收藏
// @Tags app短剧相关接口
// @Summary app端短剧剧集收藏/取消收藏 --by 王鸣
// @Description 设置当前用户短剧剧集收藏状态,收藏数只在状态真实变化时增减
// @Accept json
// @Produce json
// @Param param body proto.PlayletChapterCollectSetReq true "短剧剧集收藏设置请求"
// @Success 200 {object} proto.PlayletChapterCollectSetResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/chapter/collect/set [post]
func SetChapterCollect(ctx *gin.Context) {
var req proto.PlayletChapterCollectSetReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.SetChapterCollect(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ChapterCollectList app端我的短剧剧集收藏列表
// @Tags app短剧相关接口
// @Summary app端我的短剧剧集收藏列表 --by 王鸣
// @Description 按当前用户收藏时间倒序分页返回短剧剧集收藏列表
// @Accept json
// @Produce json
// @Param params query proto.PlayletChapterCollectListReq true "我的短剧剧集收藏列表请求"
// @Success 200 {object} proto.PlayletChapterCollectListResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/chapter/collect/list [get]
func ChapterCollectList(ctx *gin.Context) {
var req proto.PlayletChapterCollectListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ChapterCollectList(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ReportChapterWatch app端短剧剧集观看上报
// @Tags app短剧相关接口
// @Summary app端短剧剧集观看上报 --by 王鸣
// @Description 上报当前用户短剧剧集播放进度,达到已看条件时用于我的收藏未看集数计算
// @Accept json
// @Produce json
// @Param param body proto.PlayletChapterWatchReportReq true "短剧剧集观看上报请求"
// @Success 200 {object} proto.PlayletChapterWatchReportResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/chapter/watch/report [post]
func ReportChapterWatch(ctx *gin.Context) {
var req proto.PlayletChapterWatchReportReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ReportChapterWatch(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// UnlockChapter app端使用金币逐集解锁短剧剧集
// @Tags app短剧相关接口
// @Summary app端使用金币逐集解锁短剧剧集 --by 王鸣
// @Description 仅金币付费剧集可调用;接口具备幂等性,已解锁剧集重复调用不会重复扣金币
// @Accept json
// @Produce json
// @Param param body proto.PlayletChapterUnlockReq true "短剧剧集金币解锁请求"
// @Success 200 {object} proto.PlayletChapterUnlockResp "成功"
// @Failure 400 {string} string "失败"
// @Security ApiKeyAuth
// @Router /api/app/playlet/chapter/unlock [post]
func UnlockChapter(ctx *gin.Context) {
var req proto.PlayletChapterUnlockReq
if err := ctx.ShouldBindJSON(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err1 := playletser.UnlockChapter(ctx, common.GetUserId(ctx), &req)
if err1 != nil {
common.ServerJSON(ctx, err1.Code, err1.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// Detail app端根据ID查询短剧详情
// @Tags app短剧相关接口
// @Summary app端根据ID查询短剧详情 --by 王鸣
// @Description 根据短剧ID或slug查询已上架短剧详情;slug非空时优先按slug解析短剧ID
// @Produce json
// @Param params query proto.PlayletInfoReq true "短剧详情请求"
// @Success 200 {object} proto.PlayletInfoResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/detail [get]
func Detail(ctx *gin.Context) {
var req proto.PlayletInfoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.Detail(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ChapterDetail app端根据ID查询短剧剧集详情
// @Tags app短剧相关接口
// @Summary app端根据ID查询短剧剧集详情 --by 王鸣
// @Description 根据短剧剧集ID查询播放页当前剧集详情;可传playletId或playletSlug校验剧集归属,slug非空时优先解析短剧ID
// @Produce json
// @Param params query proto.PlayletChapterInfoReq true "短剧剧集详情请求"
// @Success 200 {object} proto.PlayletChapterInfoResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/chapter/detail [get]
func ChapterDetail(ctx *gin.Context) {
var req proto.PlayletChapterInfoReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ChapterDetail(ctx, common.GetUserId(ctx), &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}
// ChapterList app端根据短剧ID查询剧集列表
// @Tags app短剧相关接口
// @Summary app端根据短剧ID查询剧集列表 --by 王鸣
// @Description 根据短剧ID或slug查询右侧选集列表;slug非空时优先按slug解析短剧ID
// @Produce json
// @Param params query proto.PlayletChapterListReq true "短剧剧集列表请求"
// @Success 200 {object} proto.PlayletChapterListResp "成功"
// @Failure 400 {string} string "失败"
// @Router /api/app/playlet/chapter/list [get]
func ChapterList(ctx *gin.Context) {
var req proto.PlayletChapterListReq
if err := ctx.ShouldBindQuery(&req); err != nil {
common.ServerJSON(ctx, srvdef.ErrParamError, nil)
return
}
resp, err := playletser.ChapterList(ctx, &req)
if err != nil {
common.ServerJSON(ctx, err.Code, err.Tips)
return
}
common.ServerJSON(ctx, srvdef.Success, resp)
}