-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_report.go
87 lines (75 loc) · 3.19 KB
/
api_report.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
package tapd
import (
"context"
"net/http"
)
// ReportStatus 报告状态(sent:已发送, draft:草稿, abandon:已删除)
type ReportStatus string
const (
ReportStatusSent ReportStatus = "sent"
ReportStatusDraft ReportStatus = "draft"
ReportStatusAbandon ReportStatus = "abandon"
)
// ReportType 报告类型(normal:项目进度报告, totest:项目转测试, test:测试报告)
type ReportType string
const (
ReportTypeNormal ReportType = "normal"
ReportTypeToTest ReportType = "totest"
ReportTypeTest ReportType = "test"
)
// Report 项目报告
type Report struct {
ID string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
WorkspaceID string `json:"workspace_id,omitempty"`
ReportType ReportType `json:"report_type,omitempty"`
Receiver string `json:"receiver,omitempty"`
Cc string `json:"cc,omitempty"`
ReceiverOrganizationIDs string `json:"receiver_organization_ids,omitempty"`
CcOrganizationIDs string `json:"cc_organization_ids,omitempty"`
Sender string `json:"sender,omitempty"`
SendTime string `json:"send_time,omitempty"`
Author string `json:"author,omitempty"`
Created string `json:"created,omitempty"`
Status ReportStatus `json:"status,omitempty"`
Modified string `json:"modified,omitempty"`
LastModify string `json:"last_modify,omitempty"`
}
// ReportService is a service to interact with report related API
type ReportService struct {
client *Client
}
// GetReportsRequest represents a request to get reports
type GetReportsRequest struct {
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目 ID
ID *int `url:"id,omitempty"` // ID
Title *string `url:"title,omitempty"` // 标题
Author *string `url:"author,omitempty"` // 创建人
Created *string `url:"created,omitempty"` // 创建时间
Limit *int `url:"limit,omitempty"` // 设置返回数量限制,默认为30
Page *int `url:"page,omitempty"` // 返回当前数量限制下第N页的数据,默认为1(第一页)
Fields *Multi[string] `url:"fields,omitempty"` // 设置获取的字段,多个字段间以','逗号隔开
}
// GetReports 获取项目报告
//
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/report/get_workspace_reports.html
func (s *ReportService) GetReports(
ctx context.Context, request *GetReportsRequest, opts ...RequestOption,
) ([]*Report, *Response, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, "workspace_reports", request, opts)
if err != nil {
return nil, nil, err
}
var items []struct {
WorkspaceReport *Report `json:"WorkspaceReport"`
}
resp, err := s.client.Do(req, &items)
if err != nil {
return nil, resp, err
}
reports := make([]*Report, 0, len(items))
for _, item := range items {
reports = append(reports, item.WorkspaceReport)
}
return reports, resp, nil
}