package modulevideoctrl import ( "91porn-server/app/service/modulevideoser" "encoding/json" "91porn-server/common" "91porn-server/common/constant" "91porn-server/common/stderr" "91porn-server/models/commod" "91porn-server/models/l/operatorlgmod" "91porn-server/models/v/modulevidmod" "91porn-server/web/service/moduleser" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) // AddVideo doc // @Summary 新增视频 // @Description 在专题下新增视频 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionID body string true "专题id" // @Param videoID body string true "视频id" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/add [post] func AddVideo(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := modulevidmod.SectionVideo{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } code := modulevideoser.AddVideo(&p) if code != stderr.Success { common.ServeJSON(ctx, code, code.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // AddVideoBatch doc // @Summary 批量新增视频 // @Description 在专题下批量新增视频 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionID body string true "专题id" // @Param videoIDs body string true "视频id列表,以','分隔" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/add/batch [post] func AddVideoBatch(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := moduleser.AddVideoBatchReq{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err := moduleser.AddVideoBatch(p); err != nil { common.ServeJSON(ctx, stderr.ErrDbInsertManyError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // UpdateVideo doc // @Summary 修改视频 // @Description 设置视频在专题下的排序码 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string false "id primary key" // @Param sectionID body string false "section id" // @Param videoID body string false "video id" // @Param sortCode body integer false "视频排序" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/edit [post] func UpdateVideo(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := modulevidmod.EditSelector{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } code := modulevideoser.UpdateVideo(&p) if code != stderr.Success { common.ServeJSON(ctx, code, code.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // DeleteVideo doc // @Summary 删除视频 // @Description 删除视频 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "id" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/delete [post] func DeleteVideo(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { ID primitive.ObjectID `json:"id"` } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = modulevidmod.DeleteOne(p.ID); err != nil { common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // BatchDeleteVideo doc // @Summary 批量删除视频 // @Description 批量删除专题下视频 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionID body string true "专题ID" // @Param request body modulevidmod.BatchDeleteVideoRequest true "request" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/delete/batch [post] func BatchDeleteVideo(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p modulevidmod.BatchDeleteVideoRequest if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if p.SectionID.IsZero() || len(p.VideoIDs) == 0 { common.ServeJSON(ctx, stderr.ErrParamError, "invalid params") return } if err = modulevidmod.BatchDeleteVideo(ctx, p.SectionID, p.VideoIDs); err != nil { common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // List doc // @Summary 获取视频列表 // @Description 获取视频列表 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionid query string true "专题id" // @Param videoid query string true "视频id" // @Param pageNumber query integer true "当前页码" // @Param pageSize query integer true "一页数据量" // @Success 200 {object} moduleser.ModuleVideoList // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/video/list [post] func List(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var q struct { modulevidmod.QuerySelector commod.Page } if err = ctx.ShouldBind(&q); err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } resp, err := moduleser.GetModuleList(q.QuerySelector, q.Page) if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } log, _ := json.Marshal(q) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, resp) }