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

Commit

Permalink
修复操作自定义字段相关接口的类型兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luojielin committed Mar 29, 2022
1 parent 9efdfe8 commit 6cdfa88
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gql/schemas.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ input SearchUserRoleOpt {
input SetUdfValueBatchInput {
targetId: String!
key: String!
value: String!
value: Object!
}

type SocialConnection {
Expand Down
11 changes: 10 additions & 1 deletion lib/management/role_management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ func (c *Client) SetRoleUdfValue(id string, udv *model.KeyValuePair) (*[]model.U

variables := make(map[string]interface{})

v, _ := json.Marshal(udv.Value)
udv.Value = string(v)
variables["targetType"] = constant.ROLE
variables["targetId"] = id
variables["udvList"] = []model.KeyValuePair{*udv}
Expand Down Expand Up @@ -440,8 +442,15 @@ func (c *Client) SetRoleUdfValue(id string, udv *model.KeyValuePair) (*[]model.U
func (c *Client) BatchSetRoleUdfValue(request *[]model.SetUdfValueBatchInput) (*model.CommonMessageAndCode, error) {

variables := make(map[string]interface{})
input := make([]model.SetUdfValueBatchInput, 0)
for _, req := range *request {
v, _ := json.Marshal(&req.Value)
req.Value = string(v)
input = append(input, req)
}

variables["targetType"] = constant.ROLE
variables["input"] = request
variables["input"] = input
b, err := c.SendHttpRequest(c.Host+constant.CoreAuthingGraphqlPath, http.MethodPost, constant.BatchSetUdfValueDocument, variables)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions lib/management/role_management_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ func TestClient_SetRoleUdfValue(t *testing.T) {
client := NewClient(userPoolId, appSecret)
log.Println("==========设置角色自定义字段==========")
kv := &model.KeyValuePair{
Key: "lhucskosfr",
Value: "123",
Key: "school",
Value: "西财",
}
resp, err := client.SetRoleUdfValue("616d112b7e387494d1ed0676", kv)
resp, err := client.SetRoleUdfValue("624298162086c052b6dc8e5f", kv)
if err != nil {
fmt.Println(err)
}
Expand Down
12 changes: 9 additions & 3 deletions lib/management/user_management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ func (c *Client) SetUserUdfValue(id string, udv *model.KeyValuePair) (*[]model.U
variables["targetType"] = constant.USER
variables["targetId"] = id
variables["key"] = udv.Key
variables["value"] = udv.Value
v, _ := json.Marshal(udv.Value)
variables["value"] = string(v)

b, err := c.SendHttpRequest(c.Host+constant.CoreAuthingGraphqlPath, http.MethodPost, constant.SetUdvDocument, variables)
if err != nil {
Expand All @@ -630,10 +631,15 @@ func (c *Client) SetUserUdfValue(id string, udv *model.KeyValuePair) (*[]model.U
// BatchSetUserUdfValue
// 批量设置自定义数据
func (c *Client) BatchSetUserUdfValue(request *[]model.SetUdfValueBatchInput) (*model.CommonMessageAndCode, error) {

variables := make(map[string]interface{})
input := make([]model.SetUdfValueBatchInput, 0)
for _, req := range *request {
v, _ := json.Marshal(&req.Value)
req.Value = string(v)
input = append(input, req)
}
variables["targetType"] = constant.USER
variables["input"] = request
variables["input"] = input
b, err := c.SendHttpRequest(c.Host+constant.CoreAuthingGraphqlPath, http.MethodPost, constant.BatchSetUdfValueDocument, variables)
if err != nil {
return nil, err
Expand Down
29 changes: 25 additions & 4 deletions lib/management/user_management_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func TestClient_ListUserAuthorizedResources(t *testing.T) {
func TestClient_BatchGetUserUdfValue(t *testing.T) {
client := NewClient(userPoolId, appSecret)
log.Println("==========批量查询用户自定义字段==========")
resp, err := client.BatchGetUserUdfValue([]string{"616d41b7410a33da0cb70e65"})
resp, err := client.BatchGetUserUdfValue([]string{"621dcbede60e7b7eda97d82a"})
log.Println(resp)
log.Println(err)
}
Expand All @@ -329,10 +329,31 @@ func TestClient_SetUserUdfValue(t *testing.T) {
client := NewClient(userPoolId, appSecret)
log.Println("==========批量查询用户自定义字段==========")
udv := model.KeyValuePair{
Key: "school",
Value: "1x1",
Key: "runCount",
Value: 23,
}
resp, err := client.SetUserUdfValue("616d41b7410a33da0cb70e65", &udv)
resp, err := client.SetUserUdfValue("621dcbede60e7b7eda97d82a", &udv)
log.Println(resp)
log.Println(err)
}

func TestClient_BatchSetUserUdfValue(t *testing.T) {
client := NewClient(userPoolId, appSecret)
log.Println("==========批量设置用户自定义字段==========")
udvs := make([]model.SetUdfValueBatchInput, 0)
udv := model.SetUdfValueBatchInput{
TargetId: "621dcbede60e7b7eda97d82a",
Key: "school",
Value: "西财",
}
udv1 := model.SetUdfValueBatchInput{
TargetId: "621dcbede60e7b7eda97d82a",
Key: "student",
Value: true,
}
udvs = append(udvs, udv)
udvs = append(udvs, udv1)
resp, err := client.BatchSetUserUdfValue(&udvs)
log.Println(resp)
log.Println(err)
}
Expand Down
10 changes: 5 additions & 5 deletions lib/model/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6cdfa88

Please sign in to comment.