fix(rule): add type and default fields to rule group model and update related logic

This commit is contained in:
Chang lue Tsen 2025-07-16 12:46:47 -04:00 committed by Leif Draven
parent 94d316ec52
commit 979e39b9e5
4 changed files with 8 additions and 2 deletions

View File

@ -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"`
}

View File

@ -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(),
}

View File

@ -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))
}

View File

@ -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"`
}