From 7e4fab34af6d537c437f22d9c5abbe1186d702a3 Mon Sep 17 00:00:00 2001 From: hy001 Date: Wed, 22 Apr 2026 20:12:59 +0800 Subject: [PATCH] feat: update baishun admin game types --- internal/service/baishun/admin.go | 17 ++++++++++++++--- internal/service/baishun/admin_test.go | 24 ++++++++++++++++++++++++ internal/service/baishun/types.go | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 internal/service/baishun/admin_test.go diff --git a/internal/service/baishun/admin.go b/internal/service/baishun/admin.go index 96d808e..649c6ce 100644 --- a/internal/service/baishun/admin.go +++ b/internal/service/baishun/admin.go @@ -202,6 +202,7 @@ func (s *BaishunService) SaveAdminGame(ctx context.Context, req SaveAdminBaishun tx.Rollback() return nil, err } + showcase := resolveAdminShowcase(req.Showcase, cfg.Showcase, cfg.ID == 0) cfgValues := map[string]any{ "sys_origin": sysOrigin, @@ -212,7 +213,7 @@ func (s *BaishunService) SaveAdminGame(ctx context.Context, req SaveAdminBaishun "game_code": gameCode, "cover": cover, "amounts": strings.TrimSpace(req.Amounts), - "is_showcase": req.Showcase, + "is_showcase": showcase, "sort": req.Sort, "height": req.Height, "width": req.Width, @@ -238,7 +239,7 @@ func (s *BaishunService) SaveAdminGame(ctx context.Context, req SaveAdminBaishun GameCode: gameCode, Cover: cover, Amounts: strings.TrimSpace(req.Amounts), - Showcase: req.Showcase, + Showcase: showcase, Sort: req.Sort, Height: req.Height, Width: req.Width, @@ -585,7 +586,7 @@ func (s *BaishunService) importCatalogGamesTx(tx *gorm.DB, sysOrigin string, fil Category: "OTHER", GameCode: vendorGameID, Cover: defaultIfBlank(catalog.Cover, catalog.PreviewURL), - Showcase: false, + Showcase: true, Sort: int64(catalog.VendorGameID), FullScreen: true, ClientOrigin: "COMMON", @@ -687,6 +688,16 @@ func normalizePageLimit(limit int) int { return limit } +func resolveAdminShowcase(showcase *bool, current bool, isCreate bool) bool { + if showcase != nil { + return *showcase + } + if isCreate { + return true + } + return current +} + func defaultAdminGSP(catalogGSP string, fallback int) string { if strings.TrimSpace(catalogGSP) != "" { return strings.TrimSpace(catalogGSP) diff --git a/internal/service/baishun/admin_test.go b/internal/service/baishun/admin_test.go new file mode 100644 index 0000000..1718896 --- /dev/null +++ b/internal/service/baishun/admin_test.go @@ -0,0 +1,24 @@ +package baishun + +import "testing" + +func TestResolveAdminShowcase(t *testing.T) { + t.Run("create defaults to enabled", func(t *testing.T) { + if got := resolveAdminShowcase(nil, false, true); !got { + t.Fatalf("resolveAdminShowcase(nil, false, true) = %v, want true", got) + } + }) + + t.Run("update keeps current when omitted", func(t *testing.T) { + if got := resolveAdminShowcase(nil, false, false); got { + t.Fatalf("resolveAdminShowcase(nil, false, false) = %v, want false", got) + } + }) + + t.Run("explicit false remains false", func(t *testing.T) { + showcase := false + if got := resolveAdminShowcase(&showcase, true, true); got { + t.Fatalf("resolveAdminShowcase(false, true, true) = %v, want false", got) + } + }) +} diff --git a/internal/service/baishun/types.go b/internal/service/baishun/types.go index 53e320e..2ffed1b 100644 --- a/internal/service/baishun/types.go +++ b/internal/service/baishun/types.go @@ -239,7 +239,7 @@ type SaveAdminBaishunGameRequest struct { GameCode string `json:"gameCode"` Cover string `json:"cover"` Amounts string `json:"amounts"` - Showcase bool `json:"showcase"` + Showcase *bool `json:"showcase"` Sort int64 `json:"sort"` Height float64 `json:"height"` Width float64 `json:"width"`