@@ -32,7 +32,7 @@ type AppWorkflowRepository interface {
32
32
FindByIds (ids []int ) (* AppWorkflow , error )
33
33
FindByAppId (appId int ) (appWorkflow []* AppWorkflow , err error )
34
34
FindByAppIds (appIds []int ) (appWorkflow []* AppWorkflow , err error )
35
- DeleteAppWorkflow (appWorkflow * AppWorkflow , tx * pg.Tx ) error
35
+ DeleteAppWorkflowAndAllMappings (appWorkflow * AppWorkflow , tx * pg.Tx ) error
36
36
37
37
SaveAppWorkflowMapping (wf * AppWorkflowMapping , tx * pg.Tx ) (* AppWorkflowMapping , error )
38
38
FindByWorkflowId (workflowId int ) ([]* AppWorkflowMapping , error )
@@ -164,26 +164,21 @@ func (impl AppWorkflowRepositoryImpl) FindByIds(ids []int) (*AppWorkflow, error)
164
164
return appWorkflow , err
165
165
}
166
166
167
- func (impl AppWorkflowRepositoryImpl ) DeleteAppWorkflow (appWorkflow * AppWorkflow , tx * pg.Tx ) error {
168
- appWorkflowMappings , err := impl .FindWFCIMappingByWorkflowId (appWorkflow .Id )
169
- if err != nil && pg .ErrNoRows != err {
170
- impl .Logger .Errorw ("err" , err )
171
- return err
172
- }
173
- if len (appWorkflowMappings ) > 0 {
174
- for _ , item := range appWorkflowMappings {
175
- err = impl .DeleteAppWorkflowMapping (item , tx )
176
- if err != nil {
177
- impl .Logger .Errorw ("err" , err )
178
- return err
179
- }
167
+ func (impl AppWorkflowRepositoryImpl ) DeleteAppWorkflowAndAllMappings (appWorkflow * AppWorkflow , tx * pg.Tx ) error {
168
+ // Delete app workflow mapping
169
+ mapping , err := impl .FindWFAllMappingByWorkflowId (appWorkflow .Id )
170
+ for _ , item := range mapping {
171
+ err := impl .DeleteAppWorkflowMapping (item , tx )
172
+ if err != nil {
173
+ impl .Logger .Errorw ("error in deleting workflow mapping" , "err" , err )
174
+ return err
180
175
}
181
176
}
182
177
183
178
appWorkflow .Active = false
184
- err = impl . dbConnection .Update (appWorkflow )
179
+ err = tx .Update (appWorkflow )
185
180
if err != nil {
186
- impl .Logger .Errorw ("err" , err )
181
+ impl .Logger .Errorw ("error in deleting app workflow" , "appWorkflow" , appWorkflow , " err" , err )
187
182
return err
188
183
}
189
184
return nil
0 commit comments