@@ -11,15 +11,30 @@ import (
11
11
"github.com/google/uuid"
12
12
)
13
13
14
+ type ScenarioWorkflowParams struct {
15
+ ScenarioId dto.UriUuid `uri:"scenarioId"`
16
+ }
17
+
18
+ type WorkflowRuleParams struct {
19
+ RuleId dto.UriUuid `uri:"ruleId"`
20
+ Id dto.UriUuid `uri:"id"`
21
+ }
22
+
14
23
func handleListWorkflowsForScenario (uc usecases.Usecases ) func (c * gin.Context ) {
15
24
return func (c * gin.Context ) {
16
25
ctx := c .Request .Context ()
17
- scenarioId := c .Param ("scenarioId" )
26
+
27
+ var uri ScenarioWorkflowParams
28
+
29
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
30
+ c .Status (http .StatusBadRequest )
31
+ return
32
+ }
18
33
19
34
uc := usecasesWithCreds (ctx , uc )
20
35
workflowUsecase := uc .NewWorkflowUsecase ()
21
36
22
- rules , err := workflowUsecase .ListWorkflowsForScenario (ctx , scenarioId )
37
+ rules , err := workflowUsecase .ListWorkflowsForScenario (ctx , uri . ScenarioId . Uuid () )
23
38
if presentError (ctx , c , err ) {
24
39
return
25
40
}
@@ -59,10 +74,16 @@ func handleCreateWorkflowRule(uc usecases.Usecases) func(c *gin.Context) {
59
74
func handleUpdateWorkflowRule (uc usecases.Usecases ) func (c * gin.Context ) {
60
75
return func (c * gin.Context ) {
61
76
ctx := c .Request .Context ()
62
- ruleId := c .Param ("ruleId" )
63
77
64
- var payload dto.UpdateWorkflowRuleDto
78
+ var (
79
+ uri WorkflowRuleParams
80
+ payload dto.UpdateWorkflowRuleDto
81
+ )
65
82
83
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
84
+ c .Status (http .StatusBadRequest )
85
+ return
86
+ }
66
87
if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
67
88
c .Status (http .StatusBadRequest )
68
89
return
@@ -72,7 +93,7 @@ func handleUpdateWorkflowRule(uc usecases.Usecases) func(c *gin.Context) {
72
93
workflowUsecase := uc .NewWorkflowUsecase ()
73
94
74
95
params := models.WorkflowRule {
75
- Id : ruleId ,
96
+ Id : uri . RuleId . Uuid () ,
76
97
Name : payload .Name ,
77
98
}
78
99
@@ -88,12 +109,18 @@ func handleUpdateWorkflowRule(uc usecases.Usecases) func(c *gin.Context) {
88
109
func handleDeleteWorkflowRule (uc usecases.Usecases ) func (c * gin.Context ) {
89
110
return func (c * gin.Context ) {
90
111
ctx := c .Request .Context ()
91
- ruleId := c .Param ("ruleId" )
112
+
113
+ var uri WorkflowRuleParams
114
+
115
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
116
+ c .Status (http .StatusBadRequest )
117
+ return
118
+ }
92
119
93
120
uc := usecasesWithCreds (ctx , uc )
94
121
workflowUsecase := uc .NewWorkflowUsecase ()
95
122
96
- if err := workflowUsecase .DeleteWorkflowRule (ctx , ruleId ); presentError (ctx , c , err ) {
123
+ if err := workflowUsecase .DeleteWorkflowRule (ctx , uri . RuleId . Uuid () ); presentError (ctx , c , err ) {
97
124
return
98
125
}
99
126
@@ -104,20 +131,26 @@ func handleDeleteWorkflowRule(uc usecases.Usecases) func(c *gin.Context) {
104
131
func handleCreateWorkflowCondition (uc usecases.Usecases ) func (c * gin.Context ) {
105
132
return func (c * gin.Context ) {
106
133
ctx := c .Request .Context ()
107
- ruleId := c .Param ("ruleId" )
108
134
109
- var payload dto.PostWorkflowConditionDto
135
+ var (
136
+ uri WorkflowRuleParams
137
+ payload dto.PostWorkflowConditionDto
138
+ )
110
139
111
140
if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
112
141
c .Status (http .StatusBadRequest )
113
142
return
114
143
}
144
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
145
+ c .Status (http .StatusBadRequest )
146
+ return
147
+ }
115
148
116
149
uc := usecasesWithCreds (ctx , uc )
117
150
workflowUsecase := uc .NewWorkflowUsecase ()
118
151
119
152
params := models.WorkflowCondition {
120
- RuleId : ruleId ,
153
+ RuleId : uri . RuleId . Uuid () ,
121
154
Function : payload .Function ,
122
155
Params : payload .Params ,
123
156
}
@@ -134,11 +167,16 @@ func handleCreateWorkflowCondition(uc usecases.Usecases) func(c *gin.Context) {
134
167
func handleUpdateWorkflowCondition (uc usecases.Usecases ) func (c * gin.Context ) {
135
168
return func (c * gin.Context ) {
136
169
ctx := c .Request .Context ()
137
- ruleId := c .Param ("ruleId" )
138
- conditionId := c .Param ("conditionId" )
139
170
140
- var payload dto.PostWorkflowConditionDto
171
+ var (
172
+ uri WorkflowRuleParams
173
+ payload dto.PostWorkflowConditionDto
174
+ )
141
175
176
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
177
+ c .Status (http .StatusBadRequest )
178
+ return
179
+ }
142
180
if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
143
181
c .Status (http .StatusBadRequest )
144
182
return
@@ -148,8 +186,8 @@ func handleUpdateWorkflowCondition(uc usecases.Usecases) func(c *gin.Context) {
148
186
workflowUsecase := uc .NewWorkflowUsecase ()
149
187
150
188
params := models.WorkflowCondition {
151
- Id : conditionId ,
152
- RuleId : ruleId ,
189
+ Id : uri . Id . Uuid () ,
190
+ RuleId : uri . RuleId . Uuid () ,
153
191
Function : payload .Function ,
154
192
Params : payload .Params ,
155
193
}
@@ -166,13 +204,18 @@ func handleUpdateWorkflowCondition(uc usecases.Usecases) func(c *gin.Context) {
166
204
func handleDeleteWorkflowCondition (uc usecases.Usecases ) func (c * gin.Context ) {
167
205
return func (c * gin.Context ) {
168
206
ctx := c .Request .Context ()
169
- ruleId := c .Param ("ruleId" )
170
- conditionId := c .Param ("conditionId" )
207
+
208
+ var uri WorkflowRuleParams
209
+
210
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
211
+ c .Status (http .StatusBadRequest )
212
+ return
213
+ }
171
214
172
215
uc := usecasesWithCreds (ctx , uc )
173
216
workflowUsecase := uc .NewWorkflowUsecase ()
174
217
175
- if err := workflowUsecase .DeleteWorkflowCondition (ctx , ruleId , conditionId ); presentError (ctx , c , err ) {
218
+ if err := workflowUsecase .DeleteWorkflowCondition (ctx , uri . RuleId . Uuid (), uri . Id . Uuid () ); presentError (ctx , c , err ) {
176
219
return
177
220
}
178
221
@@ -183,23 +226,25 @@ func handleDeleteWorkflowCondition(uc usecases.Usecases) func(c *gin.Context) {
183
226
func handleCreateWorkflowAction (uc usecases.Usecases ) func (c * gin.Context ) {
184
227
return func (c * gin.Context ) {
185
228
ctx := c .Request .Context ()
186
- ruleId := c .Param ("ruleId" )
187
229
188
- var payload dto.PostWorkflowActionDto
230
+ var (
231
+ uri WorkflowRuleParams
232
+ payload dto.PostWorkflowActionDto
233
+ )
189
234
190
- if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
235
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
236
+ c .Status (http .StatusBadRequest )
191
237
return
192
238
}
193
- if err := dto .ValidateWorkflowAction (payload ); presentError (ctx , c , err ) {
194
- c .Status (http .StatusBadRequest )
239
+ if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
195
240
return
196
241
}
197
242
198
243
uc := usecasesWithCreds (ctx , uc )
199
244
workflowUsecase := uc .NewWorkflowUsecase ()
200
245
201
246
params := models.WorkflowAction {
202
- RuleId : ruleId ,
247
+ RuleId : uri . RuleId . Uuid () ,
203
248
Action : payload .Action ,
204
249
Params : payload .Params ,
205
250
}
@@ -216,25 +261,26 @@ func handleCreateWorkflowAction(uc usecases.Usecases) func(c *gin.Context) {
216
261
func handleUpdateWorkflowAction (uc usecases.Usecases ) func (c * gin.Context ) {
217
262
return func (c * gin.Context ) {
218
263
ctx := c .Request .Context ()
219
- ruleId := c .Param ("ruleId" )
220
- actionId := c .Param ("actionId" )
221
264
222
- var payload dto.PostWorkflowActionDto
265
+ var (
266
+ uri WorkflowRuleParams
267
+ payload dto.PostWorkflowActionDto
268
+ )
223
269
224
- if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
270
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
271
+ c .Status (http .StatusBadRequest )
225
272
return
226
273
}
227
- if err := dto .ValidateWorkflowAction (payload ); presentError (ctx , c , err ) {
228
- c .Status (http .StatusBadRequest )
274
+ if err := c .ShouldBindJSON (& payload ); presentError (ctx , c , err ) {
229
275
return
230
276
}
231
277
232
278
uc := usecasesWithCreds (ctx , uc )
233
279
workflowUsecase := uc .NewWorkflowUsecase ()
234
280
235
281
params := models.WorkflowAction {
236
- Id : actionId ,
237
- RuleId : ruleId ,
282
+ Id : uri . Id . Uuid () ,
283
+ RuleId : uri . RuleId . Uuid () ,
238
284
Action : payload .Action ,
239
285
Params : payload .Params ,
240
286
}
@@ -247,16 +293,22 @@ func handleUpdateWorkflowAction(uc usecases.Usecases) func(c *gin.Context) {
247
293
c .JSON (http .StatusCreated , dto .AdaptWorkflowAction (action ))
248
294
}
249
295
}
296
+
250
297
func handleDeleteWorkflowAction (uc usecases.Usecases ) func (c * gin.Context ) {
251
298
return func (c * gin.Context ) {
252
299
ctx := c .Request .Context ()
253
- ruleId := c .Param ("ruleId" )
254
- actionId := c .Param ("actionId" )
300
+
301
+ var uri WorkflowRuleParams
302
+
303
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
304
+ c .Status (http .StatusBadRequest )
305
+ return
306
+ }
255
307
256
308
uc := usecasesWithCreds (ctx , uc )
257
309
workflowUsecase := uc .NewWorkflowUsecase ()
258
310
259
- if err := workflowUsecase .DeleteWorkflowAction (ctx , ruleId , actionId ); presentError (ctx , c , err ) {
311
+ if err := workflowUsecase .DeleteWorkflowAction (ctx , uri . RuleId . Uuid (), uri . Id . Uuid () ); presentError (ctx , c , err ) {
260
312
return
261
313
}
262
314
@@ -267,18 +319,24 @@ func handleDeleteWorkflowAction(uc usecases.Usecases) func(c *gin.Context) {
267
319
func handleReorderWorkflowRules (uc usecases.Usecases ) func (c * gin.Context ) {
268
320
return func (c * gin.Context ) {
269
321
ctx := c .Request .Context ()
270
- scenarioId := c .Param ("scenarioId" )
271
322
272
- var ids []uuid.UUID
323
+ var (
324
+ uri ScenarioWorkflowParams
325
+ ids []uuid.UUID
326
+ )
273
327
328
+ if err := c .ShouldBindUri (& uri ); presentError (ctx , c , err ) {
329
+ c .Status (http .StatusBadRequest )
330
+ return
331
+ }
274
332
if err := c .ShouldBindJSON (& ids ); presentError (ctx , c , err ) {
275
333
return
276
334
}
277
335
278
336
uc := usecasesWithCreds (ctx , uc )
279
337
workflowUsecase := uc .NewWorkflowUsecase ()
280
338
281
- if err := workflowUsecase .ReorderWorkflowRules (ctx , scenarioId , ids ); presentError (ctx , c , err ) {
339
+ if err := workflowUsecase .ReorderWorkflowRules (ctx , uri . ScenarioId . Uuid () , ids ); presentError (ctx , c , err ) {
282
340
return
283
341
}
284
342
0 commit comments