Run executes the workflow list action
(page int, pageSize int)
| 57 | |
| 58 | // Run executes the workflow list action |
| 59 | func (action *WorkflowList) Run(page int, pageSize int) (*WorkflowListResult, error) { |
| 60 | if page < 1 { |
| 61 | return nil, fmt.Errorf("page must be greater or equal to 1") |
| 62 | } |
| 63 | if pageSize < 1 { |
| 64 | return nil, fmt.Errorf("page-size must be greater or equal to 1") |
| 65 | } |
| 66 | |
| 67 | client := pb.NewWorkflowServiceClient(action.cfg.CPConnection) |
| 68 | res := &WorkflowListResult{} |
| 69 | |
| 70 | resp, err := client.List(context.Background(), &pb.WorkflowServiceListRequest{ |
| 71 | Pagination: &pb.OffsetPaginationRequest{ |
| 72 | Page: int32(page), |
| 73 | PageSize: int32(pageSize), |
| 74 | }, |
| 75 | }) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | |
| 80 | // Convert the response to the output format |
| 81 | for _, p := range resp.Result { |
| 82 | res.Workflows = append(res.Workflows, pbWorkflowItemToAction(p)) |
| 83 | } |
| 84 | |
| 85 | // Add the pagination details |
| 86 | res.Pagination = &OffsetPagination{ |
| 87 | Page: int(resp.GetPagination().GetPage()), |
| 88 | PageSize: int(resp.GetPagination().GetPageSize()), |
| 89 | TotalPages: int(resp.GetPagination().GetTotalPages()), |
| 90 | TotalCount: int(resp.GetPagination().GetTotalCount()), |
| 91 | } |
| 92 | |
| 93 | return res, nil |
| 94 | } |
| 95 | |
| 96 | // pbWorkflowItemToAction converts API response to WorkflowItem |
| 97 | func pbWorkflowItemToAction(wf *pb.WorkflowItem) *WorkflowItem { |
nothing calls this directly
no test coverage detected