fix room pin list type filter
This commit is contained in:
parent
ac6672f398
commit
b97e5f0011
@ -56,7 +56,7 @@ func (s *Service) AdminListRoomPins(ctx context.Context, req *roomv1.AdminListRo
|
||||
Keyword: strings.TrimSpace(req.GetKeyword()),
|
||||
Status: strings.TrimSpace(req.GetStatus()),
|
||||
RegionID: req.GetVisibleRegionId(),
|
||||
PinType: normalizeRoomPinType(req.GetPinType()),
|
||||
PinType: normalizeRoomPinListType(req.GetPinType()),
|
||||
NowMS: nowMS,
|
||||
})
|
||||
if err != nil {
|
||||
@ -67,7 +67,7 @@ func (s *Service) AdminListRoomPins(ctx context.Context, req *roomv1.AdminListRo
|
||||
slog.Int("page_size", int(req.GetPageSize())),
|
||||
slog.String("status", strings.TrimSpace(req.GetStatus())),
|
||||
slog.Int64("visible_region_id", req.GetVisibleRegionId()),
|
||||
slog.String("pin_type", normalizeRoomPinType(req.GetPinType())),
|
||||
slog.String("pin_type", normalizeRoomPinListType(req.GetPinType())),
|
||||
slog.Bool("has_keyword", strings.TrimSpace(req.GetKeyword()) != ""),
|
||||
)
|
||||
return nil, err
|
||||
@ -177,6 +177,20 @@ func normalizeRoomPinType(pinType string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeRoomPinListType(pinType string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(pinType)) {
|
||||
case roomPinTypeRegion:
|
||||
return roomPinTypeRegion
|
||||
case roomPinTypeGlobal:
|
||||
return roomPinTypeGlobal
|
||||
case roomPinTypeCountry:
|
||||
return roomPinTypeCountry
|
||||
default:
|
||||
// 列表空类型代表“不按置顶类型筛选”;不能复用创建默认 region,否则国家置顶会从后台总列表消失。
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeAdminRoomPinInterval(pinnedAtMS int64, expiresAtMS int64, durationDays int64, nowMS int64) (int64, int64, error) {
|
||||
if pinnedAtMS <= 0 {
|
||||
pinnedAtMS = nowMS
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeRoomPinListTypeDoesNotDefaultBlankToRegion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pinType string
|
||||
want string
|
||||
}{
|
||||
{name: "blank means all pin types", pinType: "", want: ""},
|
||||
{name: "space means all pin types", pinType: " ", want: ""},
|
||||
{name: "unknown means all pin types", pinType: "unknown", want: ""},
|
||||
{name: "region filter is preserved", pinType: "region", want: roomPinTypeRegion},
|
||||
{name: "global filter is preserved", pinType: "global", want: roomPinTypeGlobal},
|
||||
{name: "country filter is preserved", pinType: "country", want: roomPinTypeCountry},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := normalizeRoomPinListType(tt.pinType); got != tt.want {
|
||||
t.Fatalf("list pin type mismatch: got %q want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRoomPinTypeKeepsCreateCompatibility(t *testing.T) {
|
||||
if got := normalizeRoomPinType(""); got != roomPinTypeRegion {
|
||||
t.Fatalf("blank create pin type must keep legacy region default, got %q", got)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user