@@ -17,30 +17,30 @@ import (
17
17
// SQL Queries as Strings.
18
18
const (
19
19
addRuleQuery = `
20
- INSERT INTO rules (id, name, domain_id, input_channel, input_topic, logic_type, logic_value,
21
- output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status)
22
- VALUES (:id, :name, :domain_id, :input_channel, :input_topic, :logic_type, :logic_value,
20
+ INSERT INTO rules (id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
21
+ output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status)
22
+ VALUES (:id, :name, :domain_id, :metadata, : input_channel, :input_topic, :logic_type, :logic_value,
23
23
:output_channel, :output_topic, :recurring_time, :recurring_type, :recurring_period, :created_at, :updated_at, :updated_by, :status)
24
- RETURNING id, name, domain_id, input_channel, input_topic, logic_type, logic_value,
25
- output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status;
24
+ RETURNING id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
25
+ output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status;
26
26
`
27
27
28
28
viewRuleQuery = `
29
- SELECT id, name, domain_id, input_channel, input_topic, logic_type, logic_value, output_channel,
30
- output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status
29
+ SELECT id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value, output_channel,
30
+ output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status
31
31
FROM rules
32
32
WHERE id = $1;
33
33
`
34
34
35
35
updateRuleQuery = `
36
36
UPDATE rules
37
- SET name = :name, input_channel = :input_channel, input_topic = :input_topic, logic_type = :logic_type,
37
+ SET name = :name, metadata = :metadata, input_channel = :input_channel, input_topic = :input_topic, logic_type = :logic_type,
38
38
logic_value = :logic_value, output_channel = :output_channel, output_topic = :output_topic,
39
39
recurring_time = :recurring_time, recurring_type = :recurring_type,
40
40
recurring_period = :recurring_period, updated_at = :updated_at, updated_by = :updated_by, status = :status
41
41
WHERE id = :id
42
- RETURNING id, name, domain_id, input_channel, input_topic, logic_type, logic_value,
43
- output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status;
42
+ RETURNING id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
43
+ output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status;
44
44
`
45
45
46
46
removeRuleQuery = `
@@ -52,13 +52,13 @@ const (
52
52
UPDATE rules
53
53
SET status = $2
54
54
WHERE id = $1
55
- RETURNING id, name, domain_id, input_channel, input_topic, logic_type, logic_value,
56
- output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status;
55
+ RETURNING id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
56
+ output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status;
57
57
`
58
58
59
59
listRulesQuery = `
60
60
SELECT id, name, domain_id, input_channel, input_topic, logic_type, logic_value, output_channel,
61
- output_topic, recurring_time, recurring_type, recurring_period, created_at, updated_at, updated_by, status
61
+ output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status
62
62
FROM rules r %s %s;
63
63
`
64
64
@@ -74,7 +74,10 @@ func NewRepository(db postgres.Database) re.Repository {
74
74
}
75
75
76
76
func (repo * PostgresRepository ) AddRule (ctx context.Context , r re.Rule ) (re.Rule , error ) {
77
- dbr := ruleToDb (r )
77
+ dbr , err := ruleToDb (r )
78
+ if err != nil {
79
+ return re.Rule {}, err
80
+ }
78
81
row , err := repo .DB .NamedQueryContext (ctx , addRuleQuery , dbr )
79
82
if err != nil {
80
83
return re.Rule {}, err
@@ -88,7 +91,10 @@ func (repo *PostgresRepository) AddRule(ctx context.Context, r re.Rule) (re.Rule
88
91
}
89
92
}
90
93
91
- rule := dbToRule (dbRule )
94
+ rule , err := dbToRule (dbRule )
95
+ if err != nil {
96
+ return re.Rule {}, err
97
+ }
92
98
93
99
return rule , nil
94
100
}
@@ -102,7 +108,10 @@ func (repo *PostgresRepository) ViewRule(ctx context.Context, id string) (re.Rul
102
108
if err := row .StructScan (& dbr ); err != nil {
103
109
return re.Rule {}, err
104
110
}
105
- ret := dbToRule (dbr )
111
+ ret , err := dbToRule (dbr )
112
+ if err != nil {
113
+ return re.Rule {}, err
114
+ }
106
115
107
116
return ret , nil
108
117
}
@@ -118,13 +127,19 @@ func (repo *PostgresRepository) UpdateRuleStatus(ctx context.Context, id string,
118
127
return re.Rule {}, err
119
128
}
120
129
121
- rule := dbToRule (dbr )
130
+ rule , err := dbToRule (dbr )
131
+ if err != nil {
132
+ return re.Rule {}, err
133
+ }
122
134
123
135
return rule , nil
124
136
}
125
137
126
138
func (repo * PostgresRepository ) UpdateRule (ctx context.Context , r re.Rule ) (re.Rule , error ) {
127
- dbr := ruleToDb (r )
139
+ dbr , err := ruleToDb (r )
140
+ if err != nil {
141
+ return re.Rule {}, err
142
+ }
128
143
row , err := repo .DB .NamedQueryContext (ctx , updateRuleQuery , dbr )
129
144
if err != nil {
130
145
return re.Rule {}, err
@@ -137,7 +152,10 @@ func (repo *PostgresRepository) UpdateRule(ctx context.Context, r re.Rule) (re.R
137
152
return re.Rule {}, err
138
153
}
139
154
}
140
- rule := dbToRule (dbRule )
155
+ rule , err := dbToRule (dbRule )
156
+ if err != nil {
157
+ return re.Rule {}, err
158
+ }
141
159
142
160
return rule , nil
143
161
}
@@ -177,7 +195,11 @@ func (repo *PostgresRepository) ListRules(ctx context.Context, pm re.PageMeta) (
177
195
if err := rows .StructScan (& r ); err != nil {
178
196
return re.Page {}, errors .Wrap (repoerr .ErrViewEntity , err )
179
197
}
180
- rules = append (rules , dbToRule (r ))
198
+ ret , err := dbToRule (r )
199
+ if err != nil {
200
+ return re.Page {}, err
201
+ }
202
+ rules = append (rules , ret )
181
203
}
182
204
183
205
cq := fmt .Sprintf (totalQuery , pq )
0 commit comments