Skip to content

Commit 23c7f8a

Browse files
authored
refactor(client): interfaceize service implementation (#151)
* refactor(measure): interface-ify MeasureService and implement with measureService - Created a MeasureService interface to define the service's behavior - Implemented MeasureService with a new measureService struct- Updated client.go to use the new MeasureService interface - Refactored LifeTimes method to use the new service implementation Signed-off-by: Flc <[email protected]> * refactor(attachment): interface-ify AttachmentService and implement new methods - Add new methods to AttachmentService interface: - GetAttachmentDownloadURL - GetImageDownloadURL - GetDocumentDownloadURL - Implement the new methods in attachmentService struct - Update client.go to use the new AttachmentService interface Signed-off-by: Flc <[email protected]> * refactor(comment): interface-ify CommentService and implement with commentService - Define CommentService interface for comment-related operations - Implement CommentService with commentService struct - Update client.go to use new CommentService interface Signed-off-by: Flc <[email protected]> * refactor(api): simplify comment request structures - Reduced the number of fields in GetCommentsRequest and GetCommentsCountRequest - Improved code readability by using inline comments - Removed unnecessary blank lines and excessive spacing Signed-off-by: Flc <[email protected]> * refactor(label): interface-ify LabelService and implement proper struct - Define LabelService interface with all label-related methods - Implement LabelService interface in labelService struct - Update client.go to use LabelService interface instead of struct- Add context parameter to all methods for better request management Signed-off-by: Flc <[email protected]> * refactor(setting): interface-ize SettingService and implement with settingService - Define SettingService interface with GetWorkspaceSetting method - Implement SettingService with settingService struct - Update client to use new SettingService interface - Refactor GetWorkspaceSetting method to use new service implementation Signed-off-by: Flc <[email protected]> * refactor(workflow): interface-ify WorkflowService and implement GetAllLastSteps- Define WorkflowService interface with GetAllLastSteps method - Create new workflowService struct and implement WorkflowService interface - Update client.go to use new WorkflowService interface Signed-off-by: Flc <[email protected]> * refactor(report): interface-ize ReportService and implement with reportService - Define ReportService interface to interact with report-related APIs - Implement ReportService with reportService struct - Update client.go to use new ReportService interface - Refactor GetReports method to use new service implementation Signed-off-by: Flc <[email protected]> * refactor(workspace): restructure workspace service and improve type safety - Restructured WorkspaceService interface to separate it from the concrete implementation - Renamed concrete implementation to workspaceService - Updated related imports and function signatures - Improved type safety by using interface instead of pointer to struct Signed-off-by: Flc <[email protected]> * fix: types/v3-directive not published Signed-off-by: Flc <[email protected]> * refactor(client): improve BugService initialization and type - Change BugService type from *BugService to BugService- Update BugService initialization to use NewBugService function Signed-off-by: Flc <[email protected]> * refactor(client): improve service initialization and naming consistency - Update StoryService initialization to use NewStoryService function - Remove unnecessary pointer allocations for StoryService and TaskService - Improve consistency in service naming and initialization across the client Signed-off-by: Flc <[email protected]> * refactor(task): enhance TaskService implementation and improve type definitions Signed-off-by: Flc <[email protected]> --------- Signed-off-by: Flc <[email protected]>
1 parent f9b6c7d commit 23c7f8a

File tree

13 files changed

+3478
-3400
lines changed

13 files changed

+3478
-3400
lines changed

api_attachment.go

Lines changed: 95 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,107 @@ import (
55
"net/http"
66
)
77

8-
// Attachment 附件
9-
type Attachment struct {
10-
ID string `json:"id,omitempty"` // 附件ID
11-
Type string `json:"type,omitempty"` // 类型
12-
EntryID string `json:"entry_id,omitempty"` // 依赖对象ID
13-
Filename string `json:"filename,omitempty"` // 附件名称
14-
Description string `json:"description,omitempty"` // 描述
15-
ContentType string `json:"content_type,omitempty"` // 内容类型
16-
Created string `json:"created,omitempty"` // 创建时间
17-
WorkspaceID string `json:"workspace_id,omitempty"` // 项目ID
18-
Owner string `json:"owner,omitempty"` // 上传人
19-
DownloadURL string `json:"download_url,omitempty"` // 下载链接(仅在获取单个附件时返回)
20-
}
8+
type (
9+
// Attachment 附件
10+
Attachment struct {
11+
ID string `json:"id,omitempty"` // 附件ID
12+
Type string `json:"type,omitempty"` // 类型
13+
EntryID string `json:"entry_id,omitempty"` // 依赖对象ID
14+
Filename string `json:"filename,omitempty"` // 附件名称
15+
Description string `json:"description,omitempty"` // 描述
16+
ContentType string `json:"content_type,omitempty"` // 内容类型
17+
Created string `json:"created,omitempty"` // 创建时间
18+
WorkspaceID string `json:"workspace_id,omitempty"` // 项目ID
19+
Owner string `json:"owner,omitempty"` // 上传人
20+
DownloadURL string `json:"download_url,omitempty"` // 下载链接(仅在获取单个附件时返回)
21+
}
22+
23+
GetAttachmentsRequest struct {
24+
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
25+
ID *int `url:"id,omitempty"` // [可选]ID
26+
Type *string `url:"type,omitempty"` // [可选]类型
27+
EntryID *int `url:"entry_id,omitempty"` // [可选]依赖对象ID
28+
Filename *string `url:"filename,omitempty"` // [可选]附件名称
29+
Owner *string `url:"owner,omitempty"` // [可选]上传人
30+
DownloadURL string `json:"download_url,omitempty"` // 下载链接(仅在获取单个附件时返回)
31+
}
32+
33+
GetAttachmentDownloadURLRequest struct {
34+
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
35+
ID *int `url:"id,omitempty"` // [必须]附件ID
36+
}
37+
38+
GetImageDownloadURLRequest struct {
39+
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
40+
ImagePath *string `url:"image_path,omitempty"` // [必须]图片路径, 支持完整url地址, 图片所属项目必须和传入的项目id一致
41+
}
42+
43+
ImageAttachment struct {
44+
Type string `json:"type,omitempty"` // 文件类型
45+
Value string `json:"value,omitempty"` // 图片路径
46+
WorkspaceID int `json:"workspace_id,omitempty"` // 项目id
47+
Filename string `json:"filename,omitempty"` // 图片文件名
48+
DownloadURL string `json:"download_url,omitempty"` // 单个图片下载地址
49+
}
50+
51+
GetDocumentDownloadURLRequest struct {
52+
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
53+
ID *int `url:"id,omitempty"` // [必须]文档ID
54+
}
55+
56+
DocumentAttachment struct {
57+
ID string `json:"id,omitempty"` // 文档ID
58+
WorkspaceID string `json:"workspace_id,omitempty"` // 项目ID
59+
Name string `json:"name,omitempty"` // 标题
60+
Type string `json:"type,omitempty"` // 文档类型
61+
FolderID string `json:"folder_id,omitempty"` // 文件夹ID
62+
Creator string `json:"creator,omitempty"` // 创建人
63+
Modifier string `json:"modifier,omitempty"` // 最后修改人
64+
Status string `json:"status,omitempty"` // 状态
65+
Created string `json:"created,omitempty"` // 创建时间
66+
Modified string `json:"modified,omitempty"` // 最后修改时间
67+
DownloadURL string `json:"download_url,omitempty"` // 下载链接
68+
}
69+
)
2170

2271
// AttachmentService is the service to communicate with Attachment API.
2372
//
2473
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/
25-
type AttachmentService struct {
74+
type AttachmentService interface {
75+
// GetAttachments 获取附件
76+
//
77+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_attachments.html
78+
GetAttachments(ctx context.Context, request *GetAttachmentsRequest, opts ...RequestOption) ([]*Attachment, *Response, error)
79+
80+
// GetAttachmentDownloadURL 获取单个附件下载链接
81+
//
82+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_one_attachment.html
83+
GetAttachmentDownloadURL(ctx context.Context, request *GetAttachmentDownloadURLRequest, opts ...RequestOption) (*Attachment, *Response, error)
84+
85+
// GetImageDownloadURL 获取单个图片下载链接
86+
//
87+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_image.html
88+
GetImageDownloadURL(ctx context.Context, request *GetImageDownloadURLRequest, opts ...RequestOption) (*ImageAttachment, *Response, error)
89+
90+
// GetDocumentDownloadURL 获取单个文档下载链接
91+
//
92+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/documents_down.html
93+
GetDocumentDownloadURL(ctx context.Context, request *GetDocumentDownloadURLRequest, opts ...RequestOption) (*DocumentAttachment, *Response, error)
94+
}
95+
96+
type attachmentService struct {
2697
client *Client
2798
}
2899

29-
type GetAttachmentsRequest struct {
30-
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
31-
ID *int `url:"id,omitempty"` // [可选]ID
32-
Type *string `url:"type,omitempty"` // [可选]类型
33-
EntryID *int `url:"entry_id,omitempty"` // [可选]依赖对象ID
34-
Filename *string `url:"filename,omitempty"` // [可选]附件名称
35-
Owner *string `url:"owner,omitempty"` // [可选]上传人
36-
DownloadURL string `json:"download_url,omitempty"` // 下载链接(仅在获取单个附件时返回)
100+
var _ AttachmentService = (*attachmentService)(nil)
101+
102+
func NewAttachmentService(client *Client) AttachmentService {
103+
return &attachmentService{
104+
client: client,
105+
}
37106
}
38107

39-
// GetAttachments 获取附件
40-
//
41-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_attachments.html
42-
func (s *AttachmentService) GetAttachments(
108+
func (s *attachmentService) GetAttachments(
43109
ctx context.Context, request *GetAttachmentsRequest, opts ...RequestOption,
44110
) ([]*Attachment, *Response, error) {
45111
req, err := s.client.NewRequest(ctx, http.MethodGet, "attachments", request, opts)
@@ -63,15 +129,7 @@ func (s *AttachmentService) GetAttachments(
63129
return attachments, resp, nil
64130
}
65131

66-
type GetAttachmentDownloadURLRequest struct {
67-
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
68-
ID *int `url:"id,omitempty"` // [必须]附件ID
69-
}
70-
71-
// GetAttachmentDownloadURL 获取单个附件下载链接
72-
//
73-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_one_attachment.html
74-
func (s *AttachmentService) GetAttachmentDownloadURL(
132+
func (s *attachmentService) GetAttachmentDownloadURL(
75133
ctx context.Context, request *GetAttachmentDownloadURLRequest, opts ...RequestOption,
76134
) (*Attachment, *Response, error) {
77135
req, err := s.client.NewRequest(ctx, http.MethodGet, "attachments/down", request, opts)
@@ -90,23 +148,7 @@ func (s *AttachmentService) GetAttachmentDownloadURL(
90148
return response.Attachment, resp, nil
91149
}
92150

93-
type GetImageDownloadURLRequest struct {
94-
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
95-
ImagePath *string `url:"image_path,omitempty"` // [必须]图片路径, 支持完整url地址, 图片所属项目必须和传入的项目id一致
96-
}
97-
98-
type ImageAttachment struct {
99-
Type string `json:"type,omitempty"` // 文件类型
100-
Value string `json:"value,omitempty"` // 图片路径
101-
WorkspaceID int `json:"workspace_id,omitempty"` // 项目id
102-
Filename string `json:"filename,omitempty"` // 图片文件名
103-
DownloadURL string `json:"download_url,omitempty"` // 单个图片下载地址
104-
}
105-
106-
// GetImageDownloadURL 获取单个图片下载链接
107-
//
108-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/get_image.html
109-
func (s *AttachmentService) GetImageDownloadURL(
151+
func (s *attachmentService) GetImageDownloadURL(
110152
ctx context.Context, request *GetImageDownloadURLRequest, opts ...RequestOption,
111153
) (*ImageAttachment, *Response, error) {
112154
req, err := s.client.NewRequest(ctx, http.MethodGet, "files/get_image", request, opts)
@@ -125,29 +167,7 @@ func (s *AttachmentService) GetImageDownloadURL(
125167
return response.Attachment, resp, nil
126168
}
127169

128-
type GetDocumentDownloadURLRequest struct {
129-
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
130-
ID *int `url:"id,omitempty"` // [必须]文档ID
131-
}
132-
133-
type DocumentAttachment struct {
134-
ID string `json:"id,omitempty"` // 文档ID
135-
WorkspaceID string `json:"workspace_id,omitempty"` // 项目ID
136-
Name string `json:"name,omitempty"` // 标题
137-
Type string `json:"type,omitempty"` // 文档类型
138-
FolderID string `json:"folder_id,omitempty"` // 文件夹ID
139-
Creator string `json:"creator,omitempty"` // 创建人
140-
Modifier string `json:"modifier,omitempty"` // 最后修改人
141-
Status string `json:"status,omitempty"` // 状态
142-
Created string `json:"created,omitempty"` // 创建时间
143-
Modified string `json:"modified,omitempty"` // 最后修改时间
144-
DownloadURL string `json:"download_url,omitempty"` // 下载链接
145-
}
146-
147-
// GetDocumentDownloadURL 获取单个文档下载链接
148-
//
149-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/attachment/documents_down.html
150-
func (s *AttachmentService) GetDocumentDownloadURL(
170+
func (s *attachmentService) GetDocumentDownloadURL(
151171
ctx context.Context, request *GetDocumentDownloadURLRequest, opts ...RequestOption,
152172
) (*DocumentAttachment, *Response, error) {
153173
req, err := s.client.NewRequest(ctx, http.MethodGet, "documents/down", request, opts)

0 commit comments

Comments
 (0)