76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"videoweb/app/service/playletser"
|
|
"videoweb/pub/common/useragent"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// ChapterWatchReport BFF:代理 POST /api/app/playlet/chapter/watch/report。
|
|
// 文档:http://172.104.181.99:25319/swagger/index.html#/app短剧相关接口/post_api_app_playlet_chapter_watch_report
|
|
func ChapterWatchReport(c *gin.Context) {
|
|
if useragent.TokenFromRequest(c.Request) == "" {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 401,
|
|
"msg": "unauthorized",
|
|
"tip": "请先登录",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
|
|
var body struct {
|
|
ChapterID int64 `json:"chapterId"`
|
|
PlayletID int64 `json:"playletId"`
|
|
}
|
|
if err := c.ShouldBindJSON(&body); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{
|
|
"code": 400,
|
|
"msg": "invalid body",
|
|
"tip": "参数错误",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
if body.ChapterID <= 0 {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 400,
|
|
"msg": "chapterId required",
|
|
"tip": "缺少剧集 ID",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
|
|
env, err := playletser.ChapterWatchReport(c, playletser.PlayletChapterWatchReportReq{
|
|
ChapterID: body.ChapterID,
|
|
PlayletID: body.PlayletID,
|
|
})
|
|
if err != nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 500,
|
|
"msg": err.Error(),
|
|
"tip": "上报失败,请稍后重试",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
if env == nil {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": 500,
|
|
"msg": "empty response",
|
|
"tip": "上报失败,请稍后重试",
|
|
"data": nil,
|
|
})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"code": env.Code,
|
|
"msg": env.Msg,
|
|
"tip": env.Tip,
|
|
"data": env.Data,
|
|
})
|
|
}
|