init: web_hgcg_server 初始化提交
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package playletser
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"videoweb/pub/models/homeconfigmod"
|
||||
"videoweb/pub/models/playletmod"
|
||||
)
|
||||
|
||||
func TestHomeConfigThemeRecommendSortIncludesBoundUpPlaylets(t *testing.T) {
|
||||
filter, _ := homeConfigThemePlayletQuery(homeconfigmod.SortTypeRecommend, 10181)
|
||||
if filter[playletmod.FN.Playlet.Status] != playletmod.StatusUp {
|
||||
t.Fatalf("status filter = %v, want up", filter[playletmod.FN.Playlet.Status])
|
||||
}
|
||||
if filter[playletmod.FN.Playlet.ThemeIds] != int64(10181) {
|
||||
t.Fatalf("theme filter = %v, want 10181", filter[playletmod.FN.Playlet.ThemeIds])
|
||||
}
|
||||
if _, exists := filter[playletmod.FN.Playlet.IsRecommend]; exists {
|
||||
t.Fatal("theme query must include bound up playlets without a playlet recommendation flag")
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
package playletser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"videoweb/app/service/playletcache"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/models/playletmod"
|
||||
"videoweb/pub/models/playlettagmod"
|
||||
"videoweb/pub/models/playletthememod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// resolvePlayletID 解析短剧ID:slug 非空时先按 slug 查 ID,否则使用传入 ID。
|
||||
func resolvePlayletID(ctx context.Context, id int64, slug string, required bool) (int64, *srvdef.SrvErr) {
|
||||
slug = strings.TrimSpace(slug)
|
||||
if slug != "" {
|
||||
item, err := playletmod.FindOnePlaylet(ctx, bson.M{
|
||||
playletmod.FN.Playlet.Slug: slug,
|
||||
}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: playletmod.FN.Playlet.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
|
||||
}
|
||||
|
||||
// resolveThemeID 解析题材ID:slug 非空时先按 slug 查 ID,否则使用传入 ID(0 表示不按题材筛选)。
|
||||
func resolveThemeID(ctx context.Context, id int64, slug string) (int64, *srvdef.SrvErr) {
|
||||
slug = strings.TrimSpace(slug)
|
||||
if slug == "" {
|
||||
return id, nil
|
||||
}
|
||||
if item := playletcache.GetThemeBySlug(slug); item != nil {
|
||||
return item.Id, nil
|
||||
}
|
||||
theme, err := playletthememod.FindOnePlayletTheme(ctx, bson.M{
|
||||
playletthememod.FN.PlayletTheme.Slug: slug,
|
||||
}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: playletthememod.FN.PlayletTheme.Id, Value: 1},
|
||||
}))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return theme.Id, nil
|
||||
}
|
||||
|
||||
// resolveTagID 解析标签ID:slug 非空时先按 slug 查 ID,否则使用传入 ID。
|
||||
func resolveTagID(ctx context.Context, id int64, slug string) (int64, *srvdef.SrvErr) {
|
||||
slug = strings.TrimSpace(slug)
|
||||
if slug != "" {
|
||||
if item := playletcache.GetTagBySlug(slug); item != nil {
|
||||
return item.Id, nil
|
||||
}
|
||||
tag, err := playlettagmod.FindOnePlayletTag(ctx, bson.M{
|
||||
playlettagmod.FN.PlayletTag.Slug: slug,
|
||||
}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: playlettagmod.FN.PlayletTag.Id, Value: 1},
|
||||
}))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tag.Id, nil
|
||||
}
|
||||
if id <= 0 {
|
||||
return 0, srvdef.New(srvdef.ErrParamError, "标签ID不能为空", "标签ID不能为空")
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user