-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprojects.go
157 lines (138 loc) · 4.92 KB
/
projects.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package taigo
import (
"errors"
"fmt"
"net/http"
"strconv"
"github.com/google/go-querystring/query"
)
// ProjectService is a handle to actions related to Projects
//
// https://taigaio.github.io/taiga-doc/dist/api.html#projects
type ProjectService struct {
client *Client
// defaultProjectID int
Endpoint string
// Mapped services for simple access
areMappedServicesConfigured bool
Auth *AuthService
Epic *EpicService
Issue *IssueService
Milestone *MilestoneService
Resolver *ResolverService
Stats *StatsService
Task *TaskService
UserStory *UserStoryService
User *UserService
Webhook *WebhookService
Wiki *WikiService
}
// ConfigureMappedServices maps all services to the *ProjectService with a selected project preconfigured
func (s *ProjectService) ConfigureMappedServices(ProjectID int) {
s.Auth = &AuthService{s.client, ProjectID, "auth"}
s.Epic = &EpicService{s.client, ProjectID, "epics"}
s.Issue = &IssueService{s.client, ProjectID, "issues"}
s.Milestone = &MilestoneService{s.client, ProjectID, "milestones"}
s.Resolver = &ResolverService{s.client, ProjectID, "resolver"}
s.Stats = &StatsService{s.client, ProjectID, "stats"}
s.Task = &TaskService{s.client, ProjectID, "tasks"}
s.UserStory = &UserStoryService{s.client, ProjectID, "userstories"}
s.User = &UserService{s.client, ProjectID, "users"}
s.Webhook = &WebhookService{s.client, ProjectID, "webhooks", "webhooklogs"}
s.Wiki = &WikiService{s.client, ProjectID, "wiki"}
s.areMappedServicesConfigured = true
}
// AreMappedServicesConfigured returns true if project-related mapped services have been configured
func (s *ProjectService) AreMappedServicesConfigured() bool {
return s.areMappedServicesConfigured
}
// List -> https://taigaio.github.io/taiga-doc/dist/api.html#projects-list
//
// The results can be filtered by passing in a ProjectListQueryFilter struct
func (s *ProjectService) List(queryParameters *ProjectsQueryParameters) (*ProjectsList, error) {
/*
The results can be filtered using the following parameters:
* Member
* Members
* IsLookingForPeople
* IsFeatured
* IsBacklogActivated
* IsKanbanActivated
The results can be ordered using the order_by parameter with the values:
* memberships__user_order
* total_fans
* total_fans_last_week
* total_fans_last_month
* total_fans_last_year
* total_activity
* total_activity_last_week
* total_activity_last_month
* total_activity_last_year
*/
url := s.client.MakeURL(s.Endpoint)
if queryParameters != nil {
paramValues, _ := query.Values(queryParameters)
url = fmt.Sprintf("%s?%s", url, paramValues.Encode())
}
var projects ProjectsList
_, err := s.client.Request.Get(url, &projects)
if err != nil {
return nil, err
}
return &projects, nil
}
// Create -> https://taigaio.github.io/taiga-doc/dist/api.html#projects-create
// Required fields: name, description
func (s *ProjectService) Create(project *Project) (*Project, error) {
url := s.client.MakeURL(s.Endpoint)
var p ProjectDetail
// Check for required fields
// name, description
if isEmpty(project.Name) || isEmpty(project.Description) {
return nil, errors.New("a mandatory field is missing. See API documentataion")
}
_, err := s.client.Request.Post(url, &project, &p)
if err != nil {
return nil, err
}
return p.AsProject()
}
// Get -> https://taigaio.github.io/taiga-doc/dist/api.html#projects-get
func (s *ProjectService) Get(projectID int) (*Project, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(projectID))
var p ProjectDetail
_, err := s.client.Request.Get(url, &p)
if err != nil {
return nil, err
}
return p.AsProject()
}
// GetBySlug -> https://taigaio.github.io/taiga-doc/dist/api.html#projects-get-by-slug
func (s *ProjectService) GetBySlug(slug string) (*Project, error) {
url := s.client.MakeURL(s.Endpoint, "by_slug?slug="+slug)
var p ProjectDetail
_, err := s.client.Request.Get(url, &p)
if err != nil {
return nil, err
}
return p.AsProject()
}
// Edit edits an Project via a PATCH request => https://taigaio.github.io/taiga-doc/dist/api.html#projects-edit
// Available Meta: ProjectDetail
func (s *ProjectService) Edit(project *Project) (*Project, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(project.ID))
var p ProjectDetail
if project.ID == 0 {
return nil, errors.New("passed Project does not have an ID yet. Does it exist?")
}
_, err := s.client.Request.Patch(url, &project, &p)
if err != nil {
return nil, err
}
return p.AsProject()
}
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#projects-delete
func (s *ProjectService) Delete(projectID int) (*http.Response, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(projectID))
return s.client.Request.Delete(url)
}