aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application_router.go4
-rw-r--r--rules_manager.go8
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) {