feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package videoser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hkdj-web-server/pub/common/srvdef"
|
||||
"hkdj-web-server/pub/models/videoinformationmod"
|
||||
"hkdj-web-server/pub/models/videotopicmod"
|
||||
"strings"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func resolveVideoID(ctx context.Context, id int64, slug string, required bool) (int64, *srvdef.SrvErr) {
|
||||
slug = strings.TrimSpace(slug)
|
||||
if slug != "" {
|
||||
item, err := videoinformationmod.FindOneVideoInformationWithOptions(ctx, bson.M{
|
||||
videoinformationmod.FN.VideoInformation.Slug: slug,
|
||||
}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: videoinformationmod.FN.VideoInformation.Id, Value: 1},
|
||||
}))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return item.Id, nil
|
||||
}
|
||||
if required && id <= 0 {
|
||||
return 0, srvdef.New(srvdef.ErrParamError, "视频ID不能为空", "视频ID不能为空")
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func resolveVideoTopicID(ctx context.Context, id int64, slug string) (int64, *srvdef.SrvErr) {
|
||||
slug = strings.TrimSpace(slug)
|
||||
if slug == "" {
|
||||
return id, nil
|
||||
}
|
||||
item, err := videotopicmod.FindOneVideoTopicModel(ctx, bson.M{
|
||||
videotopicmod.FN.VideoTopicModel.Slug: slug,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return item.Id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user