123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package community
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/models/request"
- responseModel "hongze/hongze_yb/models/response"
- "hongze/hongze_yb/services/bullet_chat"
- "hongze/hongze_yb/services/community"
- "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- )
- func VideoList(c *gin.Context) {
- var req request.VideoListReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.PageIndex == 0 {
- req.PageIndex = 1
- }
- if req.PageSize == 0 {
- req.PageSize = utils.PageSize20
- }
- userInfo := user.GetInfoByClaims(c)
- list, err := community.GetVideoList(int(userInfo.UserID), req.PageIndex, req.PageSize, req.VideoId, req.VarietyTagId, req.Keywords)
- if err != nil {
- response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
- return
- }
- idsArr := make([]int, 0)
- for i := range list {
- idsArr = append(idsArr, list[i].CommunityVideoID)
- }
-
- err = community.HandleLikeOrTeaseByCommunityVideoItemList(userInfo.UserID, list)
- if err != nil {
- response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
- return
- }
-
- err = community.HandleCommentByCommunityVideoItemList(list)
- if err != nil {
- response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
- return
- }
-
- idBulletsMap, e := bullet_chat.GetListMapBySourceAndIds(bullet_chat.SourceBulletChatVideo, idsArr)
- if e != nil {
- response.FailMsg("获取失败", "获取视频社区弹幕列表Map失败, Err: "+e.Error(), c)
- return
- }
- for i := range list {
- ls := make([]*responseModel.BulletChatItem, 0)
- bs := idBulletsMap[list[i].CommunityVideoID]
- if bs != nil && len(bs) > 0 {
- for k := range bs {
- ls = append(ls, &responseModel.BulletChatItem{
- Id: bs[k].ID,
- Content: bs[k].Content,
- UserId: bs[k].UserID,
- Color: bs[k].Color,
- Seconds: fmt.Sprint(bs[k].Seconds),
- })
- }
- }
- list[i].BulletChatList = ls
- }
- response.OkData("获取成功", list, c)
- }
- func VideoPlayLog(c *gin.Context) {
- var req request.VideoPlayLogReq
- if err := c.ShouldBind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.VideoId == 0 {
- response.Fail("参数有误", c)
- return
- }
- if req.SourceAgent == 0 {
- response.Fail("参数有误", c)
- return
- }
- userinfo := user.GetInfoByClaims(c)
- newId, errMsg, err := community.SaveVideoPlayLog(userinfo, req.VideoId, req.SourceAgent, 1)
- if err != nil {
- response.FailMsg(errMsg, "VideoPlayLog ErrMsg:"+err.Error(), c)
- return
- }
- response.OkData("操作成功", newId, c)
- }
|