-
Notifications
You must be signed in to change notification settings - Fork 1
/
sections.go
88 lines (70 loc) · 2.88 KB
/
sections.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package asana
import (
"context"
"fmt"
"time"
)
type SectionBase struct {
// Read-only. The name of the object.
Name string `json:"name,omitempty"`
}
// A Section is a subdivision of a project that groups tasks together. It can either be
// a header above a list of tasks in a list view or a column in a board view of a project.
//
// Sections are largely a shared idiom in Asana’s API for both list and board views of
// a project regardless of the project’s layout.
//
// The ‘memberships’ property when getting a task will return the information for the
// section or the column under ‘section’ in the response.
type Section struct {
// Read-only. Globally unique ID of the object
ID string `json:"gid,omitempty"`
SectionBase
// Read-only. The time at which this object was created.
CreatedAt *time.Time `json:"created_at,omitempty"`
// Read-only. The project which contains the section.
Project *Project `json:"project,omitempty"`
}
// Fetch loads the full details for this Section
func (s *Section) Fetch(ctx context.Context, client *Client) error {
client.trace("Loading section details for %q", s.Name)
_, err := client.get(ctx, fmt.Sprintf("/sections/%s", s.ID), nil, s)
return err
}
func (s *Section) Delete(ctx context.Context, client *Client) error {
client.trace("Delete section %s %q", s.ID, s.Name)
err := client.delete(ctx, fmt.Sprintf("/sections/%s", s.ID))
return err
}
// Sections returns a list of sections in this project
func (p *Project) Sections(ctx context.Context, client *Client, opts ...*Options) ([]*Section, *NextPage, error) {
client.trace("Listing sections in %q", p.Name)
var result []*Section
// Make the request
nextPage, err := client.get(ctx, fmt.Sprintf("/projects/%s/sections", p.ID), nil, &result, opts...)
return result, nextPage, err
}
// CreateSection creates a new section in the given project
func (p *Project) CreateSection(ctx context.Context, client *Client, section *SectionBase) (*Section, error) {
client.info("Creating section %q", section.Name)
result := &Section{}
err := client.post(ctx, fmt.Sprintf("/projects/%s/sections", p.ID), section, result)
return result, err
}
type SectionInsertRequest struct {
Project string `json:"project_gid"`
Section string `json:"section"`
BeforeSection string `json:"before_section,omitempty"`
AfterSection string `json:"after_section,omitempty"`
}
// InsertSection moves sections relative to each other in a board view.
// One of before_section or after_section is required.
//
// Sections cannot be moved between projects.
//
// At this point in time, moving sections is not supported in list views, only board views.
func (p *Project) InsertSection(ctx context.Context, client *Client, request *SectionInsertRequest) error {
client.info("Moving section %s", request.Section)
err := client.post(ctx, fmt.Sprintf("projects/%s/sections/insert", p.ID), request, nil)
return err
}