From ec6f7ca5a9ea9f960b8f3a960e056d9ffbf0422d Mon Sep 17 00:00:00 2001 From: JJ Date: Fri, 19 Jul 2024 14:07:09 -0700 Subject: fix add rule notification --- application_router.go | 4 ++-- rules_manager.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/application_router.go b/application_router.go index 08988ea..b9db5b0 100644 --- a/application_router.go +++ b/application_router.go @@ -91,10 +91,10 @@ func CreateApplicationRouter(applicationContext *ApplicationContext, return } - if id, err := applicationContext.RulesManager.AddRule(c, rule); err != nil { + if rule, err := applicationContext.RulesManager.AddRule(c, rule); err != nil { unprocessableEntity(c, err) } else { - response := UnorderedDocument{"id": id} + response := UnorderedDocument{"id": rule.ID, "name": rule.Name} success(c, response) notificationController.Notify("rules.new", response) } diff --git a/rules_manager.go b/rules_manager.go index 2e32573..1ddde5e 100644 --- a/rules_manager.go +++ b/rules_manager.go @@ -80,7 +80,7 @@ type RulesDatabase struct { } type RulesManager interface { - AddRule(context context.Context, rule Rule) (RowID, error) + AddRule(context context.Context, rule Rule) (Rule, error) GetRule(id RowID) (Rule, bool) UpdateRule(context context.Context, id RowID, rule Rule) (bool, error) DeleteRule(context context.Context, id RowID) error @@ -150,7 +150,7 @@ func LoadRulesManager(storage Storage, flagRegex string) (RulesManager, error) { return &rulesManager, nil } -func (rm *rulesManagerImpl) AddRule(context context.Context, rule Rule) (RowID, error) { +func (rm *rulesManagerImpl) AddRule(context context.Context, rule Rule) (Rule, error) { rm.mutex.Lock() rule.ID = CustomRowID(uint64(len(rm.rules)), time.Now()) @@ -158,7 +158,7 @@ func (rm *rulesManagerImpl) AddRule(context context.Context, rule Rule) (RowID, if err := rm.validateAndAddRuleLocal(&rule); err != nil { rm.mutex.Unlock() - return EmptyRowID(), err + return Rule{}, err } if err := rm.generateDatabase(rule.ID); err != nil { @@ -171,7 +171,7 @@ func (rm *rulesManagerImpl) AddRule(context context.Context, rule Rule) (RowID, log.WithError(err).WithField("rule", rule).Panic("failed to insert rule on database") } - return rule.ID, nil + return rule, nil } func (rm *rulesManagerImpl) GetRule(id RowID) (Rule, bool) { -- cgit v1.2.3-70-g09d2