Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package srv_videotopic
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/models/videotopicmod"
|
|
"videoweb/pub/mongos"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
// GetVideoTopics 按照参数搜索视频分类
|
|
func GetVideoTopics(ctx context.Context, param *VideoTopicReq) (*VideoTopicResp, *srvdef.SrvErr) {
|
|
filter := bson.M{}
|
|
if param.VideoCategoryId != nil {
|
|
filter[videotopicmod.FN.VideoTopicModel.VideoCategoryId] = *param.VideoCategoryId
|
|
}
|
|
opt := &options.FindOptions{}
|
|
resp := &VideoTopicResp{}
|
|
|
|
opt.SetSort(bson.M{videotopicmod.FN.VideoTopicModel.Rank: -1})
|
|
opt.SetSkip((param.PageNum - 1) * param.PageSize).SetLimit(param.PageSize)
|
|
|
|
total, serr := videotopicmod.CountVideoTopicModels(ctx, filter)
|
|
if serr != nil {
|
|
return resp, serr
|
|
}
|
|
resp.Total = total
|
|
if total == 0 {
|
|
return resp, nil
|
|
}
|
|
ads, serr := videotopicmod.FindManyVideoTopicModels(ctx, filter, opt)
|
|
if serr != nil {
|
|
return resp, serr
|
|
}
|
|
resp.List = ads
|
|
|
|
return resp, nil
|
|
}
|
|
|
|
// AddVideoTopic 添加一个视频分类
|
|
func AddVideoTopic(ctx context.Context,
|
|
ac *videotopicmod.VideoTopicModel) *srvdef.SrvErr {
|
|
|
|
ac.Id = mongos.Lid.VideoTopic.Get()
|
|
now := time.Now()
|
|
ac.CreatedAt = now
|
|
ac.UpdatedAt = now
|
|
|
|
serr := videotopicmod.InsertOneVideoTopicModel(ctx, ac)
|
|
if serr != nil {
|
|
return serr
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// DelVideoTopic 删除指定视频分类
|
|
func DelVideoTopic(ctx context.Context, id int64) *srvdef.SrvErr {
|
|
adFilter := bson.M{videotopicmod.FN.VideoTopicModel.Id: id}
|
|
//删除
|
|
count, serr := videotopicmod.DelOneVideoTopicModel(ctx, adFilter)
|
|
if serr != nil {
|
|
return serr
|
|
}
|
|
if count == 0 {
|
|
return srvdef.New(srvdef.ErrNoData, "", "")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateVideoTopic 更新指定视频分类
|
|
func UpdateVideoTopic(ctx context.Context, id int64, param VideoTopicUpdate) *srvdef.SrvErr {
|
|
now := time.Now()
|
|
param.UpdatedAt = now
|
|
|
|
adFilter := bson.M{videotopicmod.FN.VideoTopicModel.Id: id}
|
|
param.IndexNow = nil
|
|
if param.IsReIndexNow != nil && *param.IsReIndexNow {
|
|
indexNow := int64(0)
|
|
param.IndexNow = &indexNow
|
|
}
|
|
updateDoc := bson.M{"$set": param}
|
|
serr := videotopicmod.UpdateOneVideoTopicModel(ctx, adFilter, updateDoc)
|
|
if serr != nil {
|
|
return serr
|
|
}
|
|
return nil
|
|
}
|