init: web_hgdjc_server
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package videoser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
"videoweb/pub/models/videotopicmod"
|
||||
|
||||
"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