diff --git a/client/section.go b/client/section.go index 2068789..7a1a449 100644 --- a/client/section.go +++ b/client/section.go @@ -21,17 +21,15 @@ type sectionAddTaskRequest struct { Data *sectionAddTaskData `json:"data"` } -func (wc *WorkspaceClient) GetSections(project *Project) ([]*Section, error) { +func (wc *WorkspaceClient) GetSections(project *Project) (ret []*Section, err error) { path := fmt.Sprintf("projects/%s/sections", project.GID) values := &url.Values{} - ret := []*Section{} - for { resp := §ionsResponse{} - err := wc.client.get(path, values, resp) + err = wc.client.get(path, values, resp) if err != nil { - return nil, err + return } ret = append(ret, resp.Data...) @@ -43,7 +41,7 @@ func (wc *WorkspaceClient) GetSections(project *Project) ([]*Section, error) { values.Set("offset", resp.NextPage.Offset) } - return ret, nil + return } func (wc *WorkspaceClient) GetSectionsByName(project *Project) (map[string]*Section, error) { @@ -92,15 +90,27 @@ func (wc *WorkspaceClient) AddTaskToSection(task *Task, section *Section) error return nil } -func (wc *WorkspaceClient) GetTasksFromSection(section *Section) ([]*Task, error) { - // TODO: Handle pagination +func (wc *WorkspaceClient) GetTasksFromSection(section *Section) (ret []*Task, err error) { path := fmt.Sprintf("sections/%s/tasks", section.GID) - resp := &tasksResponse{} - err := wc.client.get(path, nil, resp) - if err != nil { - return nil, err + values := &url.Values{} + + for { + resp := &tasksResponse{} + err = wc.client.get(path, values, resp) + if err != nil { + return + } + + ret = append(ret, resp.Data...) + + if resp.NextPage == nil { + break + } + + values.Set("offset", resp.NextPage.Offset) } - return resp.Data, nil + + return } func (s *Section) String() string { diff --git a/client/task.go b/client/task.go index f4dd5ca..808ae0b 100644 --- a/client/task.go +++ b/client/task.go @@ -21,7 +21,8 @@ type taskResponse struct { } type tasksResponse struct { - Data []*Task `json:"data"` + Data []*Task `json:"data"` + NextPage *nextPage `json:"next_page"` } type taskUpdate struct { diff --git a/client/workspace.go b/client/workspace.go index 55bd0f3..e9e3b6c 100644 --- a/client/workspace.go +++ b/client/workspace.go @@ -25,15 +25,14 @@ func (c *Client) InWorkspace(name string) (*WorkspaceClient, error) { }, nil } -func (c *Client) GetWorkspaces() ([]*Workspace, error) { +func (c *Client) GetWorkspaces() (ret []*Workspace, err error) { values := &url.Values{} - ret := []*Workspace{} for { resp := &workspacesResponse{} - err := c.get("workspaces", values, resp) + err = c.get("workspaces", values, resp) if err != nil { - return nil, err + return } ret = append(ret, resp.Data...) @@ -45,7 +44,7 @@ func (c *Client) GetWorkspaces() ([]*Workspace, error) { values.Set("offset", resp.NextPage.Offset) } - return ret, nil + return } func (c *Client) GetWorkspaceByName(name string) (*Workspace, error) {