110 lines
3.4 KiB
Go
110 lines
3.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"service/api/consts"
|
|
video_moderation_proto "service/api/proto/video_moderation/proto"
|
|
"service/app/mix/dao"
|
|
"service/bizcommon/util"
|
|
"service/dbstruct"
|
|
"service/library/logger"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
type VideoModeration struct {
|
|
store *dao.Store
|
|
}
|
|
|
|
func NewVideoModeration(store *dao.Store) (a *VideoModeration) {
|
|
a = &VideoModeration{
|
|
store: store,
|
|
}
|
|
return
|
|
}
|
|
|
|
func (p *VideoModeration) OpCreate(ctx *gin.Context, req *video_moderation_proto.OpCreateReq) error {
|
|
req.VideoModeration.Id = goproto.String(primitive.NewObjectID().Hex())
|
|
req.VideoModeration.Ct = goproto.Int64(time.Now().Unix())
|
|
req.VideoModeration.Ut = goproto.Int64(time.Now().Unix())
|
|
req.VideoModeration.DelFlag = goproto.Int64(consts.Exist)
|
|
err := p.store.CreateVideoModeration(ctx, req.VideoModeration)
|
|
if err != nil {
|
|
logger.Error("CreateVideoModeration fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpUpdate(ctx *gin.Context, req *video_moderation_proto.OpUpdateReq) error {
|
|
err := p.store.UpdateVideoModeration(ctx, req.VideoModeration)
|
|
if err != nil {
|
|
logger.Error("UpdateVideoModeration fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpDelete(ctx *gin.Context, id string) error {
|
|
err := p.store.DeleteVideoModeration(ctx, id)
|
|
if err != nil {
|
|
logger.Error("DeleteVideoModeration fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpList(ctx *gin.Context, req *video_moderation_proto.OpListReq) (*dbstruct.VideoModeration, error) {
|
|
video_moderation, err := p.store.GetVideoModerationList(ctx, util.DerefString(req.Id))
|
|
if err != nil {
|
|
logger.Error("GetVideoModerationList fail, err: %v", err)
|
|
return nil, err
|
|
}
|
|
return video_moderation, nil
|
|
}
|
|
|
|
func (p *VideoModeration) GetListByIds(ctx *gin.Context, ids []string) ([]*dbstruct.VideoModeration, error) {
|
|
list, err := p.store.GetVideoModerationListByIds(ctx, ids)
|
|
if err != nil {
|
|
logger.Error("GetVideoModerationListByIds fail, ids: %v, err: %v", ids, err)
|
|
return make([]*dbstruct.VideoModeration, 0), err
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpCreateFragmentGroup(ctx *gin.Context, req *video_moderation_proto.OpCreateBatchReq) error {
|
|
for i := range req.VideoModerations {
|
|
video_moderation := req.VideoModerations[i]
|
|
video_moderation.Id = goproto.String(primitive.NewObjectID().Hex())
|
|
video_moderation.Ct = goproto.Int64(time.Now().Unix())
|
|
video_moderation.Ut = goproto.Int64(time.Now().Unix())
|
|
video_moderation.DelFlag = goproto.Int64(consts.Exist)
|
|
}
|
|
err := p.store.CreateVideoModerationBatch(ctx, req.VideoModerations)
|
|
if err != nil {
|
|
logger.Error("CreateVideoModerationBatch fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpUpdateByIds(ctx *gin.Context, req *video_moderation_proto.OpUpdateByIdsReq) error {
|
|
err := p.store.UpdateVideoModerationByIds(ctx, req.VideoModeration, req.Ids)
|
|
if err != nil {
|
|
logger.Error("UpdateVideoModeration fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *VideoModeration) OpUpdateByBatchId(ctx *gin.Context, batchId string, video_moderation *dbstruct.VideoModeration) error {
|
|
err := p.store.UpdateVideoModerationByBatchId(ctx, batchId, video_moderation)
|
|
if err != nil {
|
|
logger.Error("UpdateVideoModerationByBatchId fail, err: %v", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|