Skip to content

Commit 24d0cb6

Browse files
authored
feat(api): implement GetUsers method for WorkspaceService (#149)
* feat(api): implement GetUsers method for WorkspaceService - Add GetUsers method to WorkspaceService for retrieving project members- Create GetUsersRequest struct for method parameters - Define User struct to represent user information - Update features.md to mark GetUsers as implemented - Add unit tests for GetUsers method - Include sample response data for GetUsers in testdata Signed-off-by: Flc <[email protected]> * refactor(api_workspace): add Tapd API reference for GetUsers function - Add API reference comment for GetUsers function in WorkspaceService - Improve code documentation and readability Signed-off-by: Flc <[email protected]> --------- Signed-off-by: Flc <[email protected]>
1 parent eb7ee5e commit 24d0cb6

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed

api_workspace.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,51 @@ type WorkspaceService struct {
1111

1212
// 获取子项目信息
1313
// 获取项目信息
14-
// 获取指定项目成员
14+
15+
// GetUsers 获取指定项目成员
16+
//
17+
// https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/api_reference/workspace/users.html
18+
func (s *WorkspaceService) GetUsers(
19+
ctx context.Context, request *GetUsersRequest, opts ...RequestOption,
20+
) ([]*User, *Response, error) {
21+
req, err := s.client.NewRequest(ctx, http.MethodGet, "workspaces/users", request, opts)
22+
if err != nil {
23+
return nil, nil, err
24+
}
25+
26+
var items []struct {
27+
UserWorkspace *User `json:"UserWorkspace"`
28+
}
29+
resp, err := s.client.Do(req, &items)
30+
if err != nil {
31+
return nil, resp, err
32+
}
33+
34+
users := make([]*User, 0, len(items))
35+
for _, item := range items {
36+
users = append(users, item.UserWorkspace)
37+
}
38+
39+
return users, resp, nil
40+
}
41+
42+
type GetUsersRequest struct {
43+
WorkspaceID *int `url:"workspace_id,omitempty"` // [必须]项目ID
44+
User *Multi[string] `url:"user,omitempty"` // [可选]用户昵称或ID
45+
Fields *Multi[string] `url:"fields,omitempty"` // [可选]返回的字段列表,user,user_id,role_id,name,email,real_join_time 可选,以,分隔
46+
}
47+
48+
type User struct {
49+
User string `json:"user"`
50+
RoleID []string `json:"role_id"`
51+
Name string `json:"name"`
52+
JoinProjectTime *string `json:"join_project_time"`
53+
RealJoinTime string `json:"real_join_time"`
54+
Status string `json:"status"`
55+
Allocation string `json:"allocation"`
56+
LeaveProjectTime *string `json:"leave_project_time"`
57+
}
58+
1559
// 添加项目成员
1660
// 获取公司项目列表
1761
// 获取用户组ID对照关系

api_workspace_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package tapd
2+
3+
import (
4+
"net/http"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestWorkspaceService_GetUsers(t *testing.T) {
12+
_, client := createServerClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13+
assert.Equal(t, http.MethodGet, r.Method)
14+
assert.Equal(t, "/workspaces/users", r.URL.Path)
15+
16+
assert.Equal(t, "11112222", r.URL.Query().Get("workspace_id"))
17+
assert.Equal(t, "张三,李四", r.URL.Query().Get("user"))
18+
assert.Equal(t, "id,name", r.URL.Query().Get("fields"))
19+
20+
_, _ = w.Write(loadData(t, "internal/testdata/api/workspace/users.json"))
21+
}))
22+
23+
users, _, err := client.WorkspaceService.GetUsers(ctx, &GetUsersRequest{
24+
WorkspaceID: Ptr(11112222),
25+
User: NewMulti("张三", "李四"),
26+
Fields: NewMulti("id", "name"),
27+
})
28+
require.NoError(t, err)
29+
assert.Len(t, users, 2)
30+
assert.Contains(t, users, &User{
31+
User: "张三",
32+
RoleID: []string{"11111122222001000029"},
33+
Name: "张三",
34+
JoinProjectTime: nil,
35+
RealJoinTime: "2018-07-03",
36+
Status: "2",
37+
Allocation: "100",
38+
LeaveProjectTime: nil,
39+
})
40+
assert.Contains(t, users, &User{
41+
User: "李四",
42+
RoleID: []string{"11111122222001000028", "11111122222001000143"},
43+
Name: "李四",
44+
JoinProjectTime: nil,
45+
RealJoinTime: "2018-07-09",
46+
Status: "1",
47+
Allocation: "100",
48+
LeaveProjectTime: nil,
49+
})
50+
}

features.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ API 文档:https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/
217217

218218
- [ ] 获取子项目信息
219219
- [ ] 获取项目信息
220-
- [ ] 获取指定项目成员
220+
- [x] 获取指定项目成员
221221
- [ ] 添加项目成员
222222
- [ ] 获取公司项目列表
223223
- [ ] 获取用户组ID对照关系
@@ -228,6 +228,12 @@ API 文档:https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/
228228
- [ ] 获取项目文档
229229
- [x] 获取成员活动日志 —— ⚠️ 因无权限,暂未测试过,请谨慎使用
230230

231+
### 项目集
232+
233+
- [ ] 根据视图id获取项目集视图工作项列表
234+
- [ ] 项目集批量关联/取消关联、修改授权范围项目
235+
- [ ] 项目集批量关联/取消关联业务对象
236+
231237
### 工作流
232238

233239
- [ ] 获取工作流流转细则
@@ -236,6 +242,7 @@ API 文档:https://open.tapd.cn/document/api-doc/API%E6%96%87%E6%A1%A3/
236242
- [ ] 获取工作流状态中英文名对应关系
237243
- [ ] 获取工作流起始状态
238244
- [ ] 获取项目下的工作流列表
245+
- [ ] 获取并行工作节点和状态的对应关系
239246

240247
### 配置
241248

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"status": 1,
3+
"data": [
4+
{
5+
"UserWorkspace": {
6+
"user": "张三",
7+
"role_id": [
8+
"11111122222001000029"
9+
],
10+
"name": "张三",
11+
"join_project_time": null,
12+
"real_join_time": "2018-07-03",
13+
"status": "2",
14+
"allocation": "100",
15+
"leave_project_time": null
16+
}
17+
},
18+
{
19+
"UserWorkspace": {
20+
"user": "李四",
21+
"role_id": [
22+
"11111122222001000028",
23+
"11111122222001000143"
24+
],
25+
"name": "李四",
26+
"join_project_time": null,
27+
"real_join_time": "2018-07-09",
28+
"status": "1",
29+
"allocation": "100",
30+
"leave_project_time": null
31+
}
32+
}
33+
],
34+
"info": "success"
35+
}

0 commit comments

Comments
 (0)