(ctx context.Context, orgID uuid.UUID, filter *biz.WorkflowListOpts, pagination *pagination.OffsetPaginationOpts)
| 264 | } |
| 265 | |
| 266 | func (r *WorkflowRepo) List(ctx context.Context, orgID uuid.UUID, filter *biz.WorkflowListOpts, pagination *pagination.OffsetPaginationOpts) ([]*biz.Workflow, int, error) { |
| 267 | ctx, span := otelx.Start(ctx, workflowRepoTracer, "WorkflowRepo.List") |
| 268 | defer span.End() |
| 269 | |
| 270 | if pagination == nil { |
| 271 | return nil, 0, fmt.Errorf("pagination options is required") |
| 272 | } |
| 273 | |
| 274 | // Initialize the base query for WorkflowRun |
| 275 | baseQuery := orgScopedQuery(r.data.DB, orgID).QueryWorkflows() |
| 276 | |
| 277 | // Apply filters to the WorkflowRun query based on the provided options |
| 278 | baseQuery = applyWorkflowRunFilters(baseQuery, filter) |
| 279 | |
| 280 | // Initialize the Workflow query and apply organization and deletion filters |
| 281 | wfQuery := baseQuery.Where(workflow.DeletedAtIsNil()) |
| 282 | |
| 283 | // Apply additional filters to the Workflow query based on the provided options |
| 284 | wfQuery, err := applyWorkflowFilters(wfQuery, filter) |
| 285 | if err != nil { |
| 286 | return nil, 0, err |
| 287 | } |
| 288 | |
| 289 | // Get the count of all filtered rows without the limit and offset |
| 290 | count, err := wfQuery.Count(ctx) |
| 291 | if err != nil { |
| 292 | return nil, 0, err |
| 293 | } |
| 294 | |
| 295 | // Apply pagination options and execute the query |
| 296 | workflows, err := wfQuery. |
| 297 | WithLatestWorkflowRun(). |
| 298 | WithContract(). |
| 299 | WithProject(). |
| 300 | Order(ent.Desc(workflow.FieldCreatedAt)). |
| 301 | Limit(pagination.Limit()). |
| 302 | Offset(pagination.Offset()). |
| 303 | All(ctx) |
| 304 | if err != nil { |
| 305 | return nil, 0, err |
| 306 | } |
| 307 | |
| 308 | result := make([]*biz.Workflow, 0, len(workflows)) |
| 309 | for _, wf := range workflows { |
| 310 | r, err := entWFToBizWF(ctx, wf) |
| 311 | if err != nil { |
| 312 | return nil, 0, fmt.Errorf("converting entity: %w", err) |
| 313 | } |
| 314 | |
| 315 | result = append(result, r) |
| 316 | } |
| 317 | |
| 318 | return result, count, nil |
| 319 | } |
| 320 | |
| 321 | // applyWorkflowRunFilters applies filters to the WorkflowRun query based on the provided options |
| 322 | func applyWorkflowRunFilters(baseQuery *ent.WorkflowQuery, opts *biz.WorkflowListOpts) *ent.WorkflowQuery { |
nothing calls this directly
no test coverage detected