Skip to content

Commit 201136b

Browse files
authored
refactor(api/comment): change ID fields from int to int64 (#69)
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
1 parent d93a310 commit 201136b

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

api_comment.go

+64-64
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,6 @@ type CommentService struct {
4545
client *Client
4646
}
4747

48-
type CreateCommentRequest struct {
49-
Title *string `json:"title,omitempty"` // 标题
50-
Description *string `json:"description,omitempty"` // 内容
51-
Author *string `json:"author,omitempty"` // 评论人
52-
EntryType *CommentEntryType `json:"entry_type,omitempty"` // 评论类型
53-
EntryID *int `json:"entry_id,omitempty"` // 评论所依附的业务对象实体id
54-
ReplyID *int `json:"reply_id,omitempty"` // 评论回复的ID
55-
RootID *int `json:"root_id,omitempty"` // 根评论ID
56-
WorkspaceID *int `json:"workspace_id,omitempty"` // 项目ID
57-
}
58-
5948
// CreateComment 添加评论接口
6049
//
6150
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/comment/add_comment.html
@@ -78,9 +67,47 @@ func (s *CommentService) CreateComment(
7867
return response.Comment, resp, nil
7968
}
8069

70+
type CreateCommentRequest struct {
71+
Title *string `json:"title,omitempty"` // 标题
72+
Description *string `json:"description,omitempty"` // 内容
73+
Author *string `json:"author,omitempty"` // 评论人
74+
EntryType *CommentEntryType `json:"entry_type,omitempty"` // 评论类型
75+
EntryID *int64 `json:"entry_id,omitempty"` // 评论所依附的业务对象实体id
76+
ReplyID *int64 `json:"reply_id,omitempty"` // 评论回复的ID
77+
RootID *int64 `json:"root_id,omitempty"` // 根评论ID
78+
WorkspaceID *int `json:"workspace_id,omitempty"` // 项目ID
79+
}
80+
81+
// GetComments 获取评论
82+
//
83+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/comment/get_comments.html
84+
func (s *CommentService) GetComments(
85+
ctx context.Context, request *GetCommentsRequest, opts ...RequestOption,
86+
) ([]*Comment, *Response, error) {
87+
req, err := s.client.NewRequest(ctx, http.MethodGet, "comments", request, opts)
88+
if err != nil {
89+
return nil, nil, err
90+
}
91+
92+
var items []struct {
93+
Comment *Comment `json:"Comment"`
94+
}
95+
resp, err := s.client.Do(req, &items)
96+
if err != nil {
97+
return nil, resp, err
98+
}
99+
100+
comments := make([]*Comment, 0, len(items))
101+
for _, item := range items {
102+
comments = append(comments, item.Comment)
103+
}
104+
105+
return comments, resp, nil
106+
}
107+
81108
type GetCommentsRequest struct {
82109
// 评论ID 支持多ID查询
83-
ID *Multi[int] `url:"id,omitempty"`
110+
ID *Multi[int64] `url:"id,omitempty"`
84111

85112
// 标题
86113
Title *string `url:"title,omitempty"`
@@ -95,7 +122,7 @@ type GetCommentsRequest struct {
95122
EntryType *CommentEntryType `url:"entry_type,omitempty"`
96123

97124
// 评论所依附的业务对象实体id
98-
EntryID *int `url:"entry_id,omitempty"`
125+
EntryID *int64 `url:"entry_id,omitempty"`
99126

100127
// 创建时间 支持时间查询
101128
Created *string `url:"created,omitempty"`
@@ -107,10 +134,10 @@ type GetCommentsRequest struct {
107134
WorkspaceID *int `url:"workspace_id,omitempty"`
108135

109136
// 根评论ID
110-
RootID *int `url:"root_id,omitempty"`
137+
RootID *int64 `url:"root_id,omitempty"`
111138

112139
// 评论回复的ID
113-
ReplyID *int `url:"reply_id,omitempty"`
140+
ReplyID *int64 `url:"reply_id,omitempty"`
114141

115142
// 设置返回数量限制,默认为30
116143
Limit *int `url:"limit,omitempty"`
@@ -125,36 +152,29 @@ type GetCommentsRequest struct {
125152
Fields *Multi[string] `url:"fields,omitempty"`
126153
}
127154

128-
// GetComments 获取评论
155+
// GetCommentsCount 获取评论数量
129156
//
130-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/comment/get_comments.html
131-
func (s *CommentService) GetComments(
132-
ctx context.Context, request *GetCommentsRequest, opts ...RequestOption,
133-
) ([]*Comment, *Response, error) {
134-
req, err := s.client.NewRequest(ctx, http.MethodGet, "comments", request, opts)
157+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/comment/get_comments_count.html
158+
func (s *CommentService) GetCommentsCount(
159+
ctx context.Context, request *GetCommentsCountRequest, opts ...RequestOption,
160+
) (int, *Response, error) {
161+
req, err := s.client.NewRequest(ctx, http.MethodGet, "comments/count", request, opts)
135162
if err != nil {
136-
return nil, nil, err
163+
return 0, nil, err
137164
}
138165

139-
var items []struct {
140-
Comment *Comment `json:"Comment"`
141-
}
142-
resp, err := s.client.Do(req, &items)
166+
var response CountResponse
167+
resp, err := s.client.Do(req, &response)
143168
if err != nil {
144-
return nil, resp, err
145-
}
146-
147-
comments := make([]*Comment, 0, len(items))
148-
for _, item := range items {
149-
comments = append(comments, item.Comment)
169+
return 0, resp, err
150170
}
151171

152-
return comments, resp, nil
172+
return response.Count, resp, nil
153173
}
154174

155175
type GetCommentsCountRequest struct {
156176
// 评论ID 支持多ID查询
157-
ID *Multi[int] `url:"id,omitempty"`
177+
ID *Multi[int64] `url:"id,omitempty"`
158178

159179
// 标题
160180
Title *string `url:"title,omitempty"`
@@ -169,7 +189,7 @@ type GetCommentsCountRequest struct {
169189
EntryType *CommentEntryType `url:"entry_type,omitempty"`
170190

171191
// 评论所依附的业务对象实体id
172-
EntryID *int `url:"entry_id,omitempty"`
192+
EntryID *int64 `url:"entry_id,omitempty"`
173193

174194
// 创建时间 支持时间查询
175195
Created *string `url:"created,omitempty"`
@@ -181,37 +201,10 @@ type GetCommentsCountRequest struct {
181201
WorkspaceID *int `url:"workspace_id,omitempty"`
182202

183203
// 根评论ID
184-
RootID *int `url:"root_id,omitempty"`
204+
RootID *int64 `url:"root_id,omitempty"`
185205

186206
// 评论回复的ID
187-
ReplyID *int `url:"reply_id,omitempty"`
188-
}
189-
190-
// GetCommentsCount 获取评论数量
191-
//
192-
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/comment/get_comments_count.html
193-
func (s *CommentService) GetCommentsCount(
194-
ctx context.Context, request *GetCommentsCountRequest, opts ...RequestOption,
195-
) (int, *Response, error) {
196-
req, err := s.client.NewRequest(ctx, http.MethodGet, "comments/count", request, opts)
197-
if err != nil {
198-
return 0, nil, err
199-
}
200-
201-
var response CountResponse
202-
resp, err := s.client.Do(req, &response)
203-
if err != nil {
204-
return 0, resp, err
205-
}
206-
207-
return response.Count, resp, nil
208-
}
209-
210-
type UpdateCommentRequest struct {
211-
WorkspaceID *int `json:"workspace_id,omitempty"` // [必须]项目ID
212-
ID *int `json:"id,omitempty"` // [必须]评论ID
213-
Description *string `json:"description,omitempty"` // [必须]内容
214-
ChangeCreator *string `json:"change_creator,omitempty"` // 变更人
207+
ReplyID *int64 `url:"reply_id,omitempty"`
215208
}
216209

217210
// UpdateComment 更新评论接口
@@ -235,3 +228,10 @@ func (s *CommentService) UpdateComment(
235228

236229
return response.Comment, resp, nil
237230
}
231+
232+
type UpdateCommentRequest struct {
233+
WorkspaceID *int `json:"workspace_id,omitempty"` // [必须]项目ID
234+
ID *int64 `json:"id,omitempty"` // [必须]评论ID
235+
Description *string `json:"description,omitempty"` // [必须]内容
236+
ChangeCreator *string `json:"change_creator,omitempty"` // 变更人
237+
}

api_comment_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func TestCommentService_CreateComment(t *testing.T) {
5050
Description: Ptr("description"),
5151
Author: Ptr("author"),
5252
EntryType: Ptr(CommentEntryTypeStories),
53-
EntryID: Ptr(123),
54-
ReplyID: Ptr(0),
55-
RootID: Ptr(111),
53+
EntryID: Ptr[int64](123),
54+
ReplyID: Ptr[int64](0),
55+
RootID: Ptr[int64](111),
5656
WorkspaceID: Ptr(111),
5757
})
5858
assert.NoError(t, err)
@@ -94,17 +94,17 @@ func TestCommentService_GetComments(t *testing.T) {
9494
}))
9595

9696
comments, _, err := client.CommentService.GetComments(ctx, &GetCommentsRequest{
97-
ID: NewMulti(111, 222),
97+
ID: NewMulti[int64](111, 222),
9898
Title: Ptr("title"),
9999
Description: Ptr("description"),
100100
Author: Ptr("author"),
101101
EntryType: Ptr(CommentEntryTypeStories),
102-
EntryID: Ptr(123),
102+
EntryID: Ptr[int64](123),
103103
Created: Ptr("created"),
104104
Modified: Ptr("modified"),
105105
WorkspaceID: Ptr(111),
106-
RootID: Ptr(222),
107-
ReplyID: Ptr(333),
106+
RootID: Ptr[int64](222),
107+
ReplyID: Ptr[int64](333),
108108
Limit: Ptr(10),
109109
Page: Ptr(1),
110110
Order: NewOrder("id", OrderByDesc),
@@ -146,17 +146,17 @@ func TestCommentService_GetCommentsCount(t *testing.T) {
146146
}))
147147

148148
count, _, err := client.CommentService.GetCommentsCount(ctx, &GetCommentsCountRequest{
149-
ID: NewMulti(111, 222),
149+
ID: NewMulti[int64](111, 222),
150150
Title: Ptr("test title"),
151151
Description: Ptr("test description"),
152152
Author: Ptr("test author"),
153153
EntryType: Ptr(CommentEntryTypeStories),
154-
EntryID: Ptr(123),
154+
EntryID: Ptr[int64](123),
155155
Created: Ptr("2024-08-28"),
156156
Modified: Ptr("2024-08-28"),
157157
WorkspaceID: Ptr(111),
158-
RootID: Ptr(222),
159-
ReplyID: Ptr(333),
158+
RootID: Ptr[int64](222),
159+
ReplyID: Ptr[int64](333),
160160
})
161161
assert.NoError(t, err)
162162
assert.NotNil(t, count)
@@ -185,7 +185,7 @@ func TestCommentService_UpdateComment(t *testing.T) {
185185

186186
comment, _, err := client.CommentService.UpdateComment(ctx, &UpdateCommentRequest{
187187
WorkspaceID: Ptr(111),
188-
ID: Ptr(111),
188+
ID: Ptr[int64](111),
189189
Description: Ptr("test description 2"),
190190
ChangeCreator: Ptr("test creator"),
191191
})

0 commit comments

Comments
 (0)