[Section] Pagination support
This commit is contained in:
@@ -26,6 +26,12 @@ type emptyResponse struct {
|
|||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type nextPage struct {
|
||||||
|
Offset string `json:"offset"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
URI string `json:"uri"`
|
||||||
|
}
|
||||||
|
|
||||||
func NewClient(token string) *Client {
|
func NewClient(token string) *Client {
|
||||||
c := &Client{
|
c := &Client{
|
||||||
client: &http.Client{},
|
client: &http.Client{},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "net/url"
|
||||||
|
|
||||||
type Section struct {
|
type Section struct {
|
||||||
GID string `json:"gid"`
|
GID string `json:"gid"`
|
||||||
@@ -9,6 +10,7 @@ type Section struct {
|
|||||||
|
|
||||||
type sectionsResponse struct {
|
type sectionsResponse struct {
|
||||||
Data []*Section `json:"data"`
|
Data []*Section `json:"data"`
|
||||||
|
NextPage *nextPage `json:"next_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type sectionAddTaskData struct {
|
type sectionAddTaskData struct {
|
||||||
@@ -20,14 +22,28 @@ type sectionAddTaskRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkspaceClient) GetSections(project *Project) ([]*Section, error) {
|
func (wc *WorkspaceClient) GetSections(project *Project) ([]*Section, error) {
|
||||||
// TODO: Handle pagination
|
|
||||||
path := fmt.Sprintf("projects/%s/sections", project.GID)
|
path := fmt.Sprintf("projects/%s/sections", project.GID)
|
||||||
|
values := &url.Values{}
|
||||||
|
|
||||||
|
ret := []*Section{}
|
||||||
|
|
||||||
|
for {
|
||||||
resp := §ionsResponse{}
|
resp := §ionsResponse{}
|
||||||
err := wc.client.get(path, nil, resp)
|
err := wc.client.get(path, values, resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return resp.Data, nil
|
|
||||||
|
ret = append(ret, resp.Data...)
|
||||||
|
|
||||||
|
if resp.NextPage == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
values.Set("offset", resp.NextPage.Offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wc *WorkspaceClient) GetSectionsByName(project *Project) (map[string]*Section, error) {
|
func (wc *WorkspaceClient) GetSectionsByName(project *Project) (map[string]*Section, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user