From 979e39b9e5b2cd3b3c0ebdfc3e4b47b388d4f497 Mon Sep 17 00:00:00 2001 From: Chang lue Tsen Date: Wed, 16 Jul 2025 12:46:47 -0400 Subject: [PATCH] fix(rule): add type and default fields to rule group model and update related logic --- apis/types.api | 2 ++ internal/logic/admin/server/getRuleGroupListLogic.go | 2 ++ internal/model/server/model.go | 4 ++-- internal/types/types.go | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apis/types.api b/apis/types.api index 60dbf5e..780a858 100644 --- a/apis/types.api +++ b/apis/types.api @@ -515,9 +515,11 @@ type ( Id int64 `json:"id"` Icon string `json:"icon"` Name string `json:"name" validate:"required"` + Type string `json:"type"` Tags []string `json:"tags"` Rules string `json:"rules"` Enable bool `json:"enable"` + Default bool `json:"default"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` } diff --git a/internal/logic/admin/server/getRuleGroupListLogic.go b/internal/logic/admin/server/getRuleGroupListLogic.go index 4f3f96f..c3e1a3f 100644 --- a/internal/logic/admin/server/getRuleGroupListLogic.go +++ b/internal/logic/admin/server/getRuleGroupListLogic.go @@ -38,9 +38,11 @@ func (l *GetRuleGroupListLogic) GetRuleGroupList() (resp *types.GetRuleGroupResp Id: v.Id, Icon: v.Icon, Name: v.Name, + Type: v.Type, Tags: strings.Split(v.Tags, ","), Rules: v.Rules, Enable: v.Enable, + Default: v.Default, CreatedAt: v.CreatedAt.UnixMilli(), UpdatedAt: v.UpdatedAt.UnixMilli(), } diff --git a/internal/model/server/model.go b/internal/model/server/model.go index 4b51c9c..daace5f 100644 --- a/internal/model/server/model.go +++ b/internal/model/server/model.go @@ -283,10 +283,10 @@ func (m *customServerModel) FindServersByTag(ctx context.Context, tag string) ([ func (m *customServerModel) SetDefaultRuleGroup(ctx context.Context, id int64) error { return m.ExecCtx(ctx, func(conn *gorm.DB) error { // Reset all groups to not default - if err := conn.Model(&RuleGroup{}).Update("default", false).Error; err != nil { + if err := conn.Model(&RuleGroup{}).Where("`id` != ?", id).Update("default", false).Error; err != nil { return err } // Set the specified group as default - return conn.Model(&RuleGroup{}).Where("id = ?", id).Update("default", true).Error + return conn.Model(&RuleGroup{}).Where("`id` = ?", id).Update("default", true).Error }, cacheServerRuleGroupAllKeys, fmt.Sprintf("cache:serverRuleGroup:%v", id)) } diff --git a/internal/types/types.go b/internal/types/types.go index 195b825..a7e0ba9 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1560,9 +1560,11 @@ type ServerRuleGroup struct { Id int64 `json:"id"` Icon string `json:"icon"` Name string `json:"name" validate:"required"` + Type string `json:"type"` Tags []string `json:"tags"` Rules string `json:"rules"` Enable bool `json:"enable"` + Default bool `json:"default"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` }