(ctx context.Context, orgID, workflowID string, opts *WorkflowUpdateOpts)
| 258 | } |
| 259 | |
| 260 | func (uc *WorkflowUseCase) Update(ctx context.Context, orgID, workflowID string, opts *WorkflowUpdateOpts) (*Workflow, error) { |
| 261 | ctx, span := otelx.Start(ctx, workflowTracer, "WorkflowUseCase.Update") |
| 262 | defer span.End() |
| 263 | |
| 264 | if opts == nil { |
| 265 | return nil, NewErrValidationStr("no updates provided") |
| 266 | } |
| 267 | |
| 268 | orgUUID, err := uuid.Parse(orgID) |
| 269 | if err != nil { |
| 270 | return nil, NewErrInvalidUUID(err) |
| 271 | } |
| 272 | |
| 273 | workflowUUID, err := uuid.Parse(workflowID) |
| 274 | if err != nil { |
| 275 | return nil, NewErrInvalidUUID(err) |
| 276 | } |
| 277 | |
| 278 | // make sure that the workflow is for the provided org |
| 279 | var preUpdateWorkflow *Workflow |
| 280 | if preUpdateWorkflow, err = uc.wfRepo.GetOrgScoped(ctx, orgUUID, workflowUUID); err != nil { |
| 281 | return nil, err |
| 282 | } else if preUpdateWorkflow == nil { |
| 283 | return nil, NewErrNotFound("workflow in organization") |
| 284 | } |
| 285 | |
| 286 | // Double check that the contract exists |
| 287 | var wfContract *WorkflowContract |
| 288 | if opts.ContractID != nil { |
| 289 | if wfContract, err = uc.contractUC.FindByIDInOrg(ctx, orgID, *opts.ContractID); err != nil { |
| 290 | return nil, err |
| 291 | } else if wfContract == nil { |
| 292 | return nil, NewErrNotFound("contract") |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | wf, err := uc.wfRepo.Update(ctx, workflowUUID, opts) |
| 297 | if err != nil { |
| 298 | if IsErrAlreadyExists(err) { |
| 299 | return nil, NewErrValidationStr("name already taken") |
| 300 | } |
| 301 | |
| 302 | return nil, fmt.Errorf("failed to update workflow: %w", err) |
| 303 | } else if wf == nil { |
| 304 | return nil, NewErrNotFound("workflow") |
| 305 | } |
| 306 | |
| 307 | // Dispatch events to the audit log regarding the workflow |
| 308 | uc.handleWorkflowUpdateEvents(ctx, wf, preUpdateWorkflow, opts, wfContract, orgUUID) |
| 309 | |
| 310 | otelx.RecordError(span, err) |
| 311 | return wf, err |
| 312 | } |
| 313 | |
| 314 | // handleWorkflowUpdateEvents dispatches events to the audit log regarding the workflow |
| 315 | func (uc *WorkflowUseCase) handleWorkflowUpdateEvents(ctx context.Context, wf *Workflow, preUpdateWorkflow *Workflow, opts *WorkflowUpdateOpts, newWfContract *WorkflowContract, orgUUID uuid.UUID) { |
nothing calls this directly
no test coverage detected