Skip to content

Commit

Permalink
add rule_group field on rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal-Delange committed Jun 7, 2024
1 parent c9ba831 commit edae7e3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dto/rule_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RuleDto struct {
FormulaAstExpression *NodeDto `json:"formula_ast_expression"`
ScoreModifier int `json:"scoreModifier"`
CreatedAt time.Time `json:"createdAt"`
RuleGroup string `json:"rule_group"`
}

type CreateRuleInputBody struct {
Expand All @@ -33,6 +34,7 @@ type CreateRuleInputBody struct {
Description string `json:"description"`
FormulaAstExpression *NodeDto `json:"formula_ast_expression"`
ScoreModifier int `json:"scoreModifier"`
RuleGroup string `json:"rule_group"`
}

type CreateRuleInput struct {
Expand All @@ -45,6 +47,7 @@ type UpdateRuleBody struct {
Description *string `json:"description,omitempty"`
FormulaAstExpression *NodeDto `json:"formula_ast_expression"`
ScoreModifier *int `json:"scoreModifier,omitempty"`
RuleGroup *string `json:"rule_group"`
}

type UpdateRuleInput struct {
Expand Down Expand Up @@ -74,6 +77,7 @@ func AdaptRuleDto(rule models.Rule) (RuleDto, error) {
FormulaAstExpression: formulaAstExpression,
ScoreModifier: rule.ScoreModifier,
CreatedAt: rule.CreatedAt,
RuleGroup: rule.RuleGroup,
}, nil
}

Expand All @@ -86,6 +90,7 @@ func AdaptCreateRuleInput(body CreateRuleInputBody, organizationId string) (mode
Description: body.Description,
FormulaAstExpression: nil,
ScoreModifier: body.ScoreModifier,
RuleGroup: body.RuleGroup,
}

if body.FormulaAstExpression != nil {
Expand All @@ -108,6 +113,7 @@ func AdaptUpdateRule(ruleId string, body UpdateRuleBody) (models.UpdateRuleInput
Description: body.Description,
FormulaAstExpression: nil,
ScoreModifier: body.ScoreModifier,
RuleGroup: body.RuleGroup,
}

if body.FormulaAstExpression != nil {
Expand Down
3 changes: 3 additions & 0 deletions models/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Rule struct {
FormulaAstExpression *ast.Node
ScoreModifier int
CreatedAt time.Time
RuleGroup string
}

type CreateRuleInput struct {
Expand All @@ -31,6 +32,7 @@ type CreateRuleInput struct {
Description string
FormulaAstExpression *ast.Node
ScoreModifier int
RuleGroup string
}

type UpdateRuleInput struct {
Expand All @@ -40,4 +42,5 @@ type UpdateRuleInput struct {
Description *string
FormulaAstExpression *ast.Node
ScoreModifier *int
RuleGroup *string
}
6 changes: 6 additions & 0 deletions repositories/dbmodels/db_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DBRule struct {
FormulaAstExpression []byte `db:"formula_ast_expression"`
CreatedAt time.Time `db:"created_at"`
DeletedAt pgtype.Time `db:"deleted_at"`
RuleGroup string `db:"rule_group"`
}

func AdaptRule(db DBRule) (models.Rule, error) {
Expand All @@ -43,6 +44,7 @@ func AdaptRule(db DBRule) (models.Rule, error) {
FormulaAstExpression: formulaAstExpression,
ScoreModifier: db.ScoreModifier,
CreatedAt: db.CreatedAt,
RuleGroup: db.RuleGroup,
}, nil
}

Expand All @@ -55,6 +57,7 @@ type DBCreateRuleInput struct {
Description string `db:"description"`
ScoreModifier int `db:"score_modifier"`
FormulaAstExpression *[]byte `db:"formula_ast_expression"`
RuleGroup string `db:"rule_group"`
}

func AdaptDBCreateRuleInput(rule models.CreateRuleInput) (DBCreateRuleInput, error) {
Expand All @@ -72,6 +75,7 @@ func AdaptDBCreateRuleInput(rule models.CreateRuleInput) (DBCreateRuleInput, err
Description: rule.Description,
ScoreModifier: rule.ScoreModifier,
FormulaAstExpression: formulaAstExpression,
RuleGroup: rule.RuleGroup,
}, nil
}

Expand All @@ -82,6 +86,7 @@ type DBUpdateRuleInput struct {
Description *string `db:"description"`
ScoreModifier *int `db:"score_modifier"`
FormulaAstExpression *[]byte `db:"formula_ast_expression"`
RuleGroup *string `db:"rule_group"`
}

func AdaptDBUpdateRuleInput(rule models.UpdateRuleInput) (DBUpdateRuleInput, error) {
Expand All @@ -97,5 +102,6 @@ func AdaptDBUpdateRuleInput(rule models.UpdateRuleInput) (DBUpdateRuleInput, err
Description: rule.Description,
ScoreModifier: rule.ScoreModifier,
FormulaAstExpression: formulaAstExpression,
RuleGroup: rule.RuleGroup,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE scenario_iteration_rules
ADD COLUMN rule_group VARCHAR(255) NOT NULL DEFAULT '';

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE scenario_iteration_rules
DROP COLUMN rule_group;

-- +goose StatementEnd
4 changes: 3 additions & 1 deletion repositories/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ func (repo *MarbleDbRepository) CreateRules(ctx context.Context, exec Executor,
"name",
"description",
"formula_ast_expression",
"score_modifier").
"score_modifier",
"rule_group").
Suffix("RETURNING *")

for _, rule := range dbCreateRuleInputs {
Expand All @@ -111,6 +112,7 @@ func (repo *MarbleDbRepository) CreateRules(ctx context.Context, exec Executor,
rule.Description,
rule.FormulaAstExpression,
rule.ScoreModifier,
rule.RuleGroup,
)
}

Expand Down

0 comments on commit edae7e3

Please sign in to comment.