Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
New interface: GetUserDepartments
Browse files Browse the repository at this point in the history
  • Loading branch information
luojielin committed Jul 16, 2021
1 parent bbf5d8f commit eff33d5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
32 changes: 32 additions & 0 deletions lib/constant/gql.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,35 @@ const RoleWithUsersDocument = `
}
}
`

const GetUserDepartmentsDocument = `
query getUserDepartments($id: String!, $orgId: String) {
user(id: $id) {
departments(orgId: $orgId) {
totalCount
list {
department {
id
orgId
name
nameI18n
description
descriptionI18n
order
code
root
depth
path
codePath
namePath
createdAt
updatedAt
children
}
isMainDepartment
joinedAt
}
}
}
}
`
4 changes: 2 additions & 2 deletions lib/management/organization_management_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestClient_ExportAll(t *testing.T) {
log.Println("==========导出所有组织机构数据==========")
resp, _ := client.ExportAll()
log.Printf("%+v\n", resp)
/*log.Println("==========获取节点成员==========")
log.Println("==========获取节点成员==========")
var req = &model.ListMemberRequest{
NodeId: "60cd9d3a4b96cfff16e7e5f4",
Page: 1,
Expand All @@ -28,7 +28,7 @@ func TestClient_ExportAll(t *testing.T) {
log.Printf("%+v\n", resp1)
log.Println("==========通过 ID 获取用户信息==========")
resp2, _ := client.Detail("60a6f9ad5bcccc51834950c5")
log.Printf("%+v\n", resp2)*/
log.Printf("%+v\n", resp2)
}
func TestClient_GetOrganizationList(t *testing.T) {
client := NewClient(userPoolId, appSecret)
Expand Down
18 changes: 18 additions & 0 deletions lib/management/user_management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/Authing/authing-go-sdk/lib/constant"
"github.com/Authing/authing-go-sdk/lib/model"
jsoniter "github.com/json-iterator/go"
"log"
)

func (c *Client) Detail(userId string) (*model.User, error) {
Expand Down Expand Up @@ -32,3 +33,20 @@ func (c *Client) GetUserList(request model.QueryListRequest) (*model.PaginatedUs
}
return &result.Data.Users, nil
}

func (c *Client) GetUserDepartments(request model.GetUserDepartmentsRequest) (*model.PaginatedDepartments, error) {
data, _ := json.Marshal(&request)
variables := make(map[string]interface{})
json.Unmarshal(data, &variables)
b, err := c.SendHttpRequest(c.Host+constant.CoreAuthingGraphqlPath, constant.HttpMethodPost, constant.GetUserDepartmentsDocument, variables)
if err != nil {
return nil, err
}
log.Println(string(b))
result := model.GetUserDepartmentsResponse{}
err = json.Unmarshal(b, &result)
if err != nil {
return nil, err
}
return result.Data.User.Departments, nil
}
11 changes: 11 additions & 0 deletions lib/management/user_management_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ func TestClient_GetUserList(t *testing.T) {
resp, _ := client.GetUserList(req)
log.Printf("%+v\n", resp)
}

func TestClient_GetUserDepartments(t *testing.T) {
client := NewClient(userPoolId, appSecret)
log.Println("==========获取用户部门列表==========")
req := model.GetUserDepartmentsRequest{
Id: "60e400c1701ea5b98dae628d",
OrgId: nil,
}
resp, _ := client.GetUserDepartments(req)
log.Printf("%+v\n", resp)
}
16 changes: 16 additions & 0 deletions lib/model/vo_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,19 @@ type OrgNode struct {
Members []User `json:"members"`
Children []OrgNode `json:"children"`
}

type GetUserDepartmentsRequest struct {
Id string `json:"id"`
OrgId *string `json:"orgId"`
}

type UserDepartments struct {
Departments *PaginatedDepartments `json:"departments"`
}

type UserDepartmentsData struct {
User UserDepartments `json:"user"`
}
type GetUserDepartmentsResponse struct {
Data UserDepartmentsData `json:"data"`
}

0 comments on commit eff33d5

Please sign in to comment.