Merge pull request #3035 from ghostg00/fix/admin-group-clear-description

fix(group): 管理员清空分组描述时正确持久化
This commit is contained in:
Wesley Liddick 2026-06-05 13:53:20 +08:00 committed by GitHub
commit fbd25acae0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 5 deletions

View File

@ -123,7 +123,7 @@ type CreateGroupRequest struct {
// UpdateGroupRequest represents update group request
type UpdateGroupRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Description *string `json:"description"`
Platform string `json:"platform" binding:"omitempty,oneof=anthropic openai gemini antigravity"`
RateMultiplier *float64 `json:"rate_multiplier"`
IsExclusive *bool `json:"is_exclusive"`

View File

@ -230,7 +230,7 @@ type CreateGroupInput struct {
type UpdateGroupInput struct {
Name string
Description string
Description *string
Platform string
RateMultiplier *float64 // 使用指针以支持设置为0
IsExclusive *bool
@ -1924,8 +1924,8 @@ func (s *adminServiceImpl) UpdateGroup(ctx context.Context, id int64, input *Upd
if input.Name != "" {
group.Name = input.Name
}
if input.Description != "" {
group.Description = input.Description
if input.Description != nil {
group.Description = *input.Description
}
if input.Platform != "" {
group.Platform = input.Platform

View File

@ -280,8 +280,9 @@ func TestAdminService_UpdateGroup_PreservesImageGenerationControlsWhenOmitted(t
repo := &groupRepoStubForAdmin{getByID: existingGroup}
svc := &adminServiceImpl{groupRepo: repo}
updatedDesc := "updated"
group, err := svc.UpdateGroup(context.Background(), 1, &UpdateGroupInput{
Description: "updated",
Description: &updatedDesc,
})
require.NoError(t, err)
require.NotNil(t, group)
@ -291,6 +292,45 @@ func TestAdminService_UpdateGroup_PreservesImageGenerationControlsWhenOmitted(t
require.InDelta(t, 0.5, repo.updated.ImageRateMultiplier, 1e-12)
}
func TestAdminService_UpdateGroup_ClearsDescriptionWhenEmptyString(t *testing.T) {
existingGroup := &Group{
ID: 1,
Name: "existing-group",
Description: "Auto-created default group",
Platform: PlatformOpenAI,
Status: StatusActive,
}
repo := &groupRepoStubForAdmin{getByID: existingGroup}
svc := &adminServiceImpl{groupRepo: repo}
empty := ""
_, err := svc.UpdateGroup(context.Background(), 1, &UpdateGroupInput{
Description: &empty,
})
require.NoError(t, err)
require.NotNil(t, repo.updated)
require.Equal(t, "", repo.updated.Description, "empty string should clear description")
}
func TestAdminService_UpdateGroup_PreservesDescriptionWhenNil(t *testing.T) {
existingGroup := &Group{
ID: 1,
Name: "existing-group",
Description: "keep me",
Platform: PlatformOpenAI,
Status: StatusActive,
}
repo := &groupRepoStubForAdmin{getByID: existingGroup}
svc := &adminServiceImpl{groupRepo: repo}
_, err := svc.UpdateGroup(context.Background(), 1, &UpdateGroupInput{
Description: nil,
})
require.NoError(t, err)
require.NotNil(t, repo.updated)
require.Equal(t, "keep me", repo.updated.Description, "nil should preserve existing description")
}
func TestAdminService_UpdateGroup_RejectsNegativeImageRateMultiplier(t *testing.T) {
existingGroup := &Group{
ID: 1,