|
|
@@ -0,0 +1,74 @@ |
|
|
|
|
|
package cdsapi |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"net/url" |
|
|
|
|
|
|
|
|
|
|
|
"gitlink.org.cn/cloudream/common/consts/errorcode" |
|
|
|
|
|
cdssdk "gitlink.org.cn/cloudream/common/sdks/storage" |
|
|
|
|
|
"gitlink.org.cn/cloudream/common/utils/http2" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const UserCreatePath = "/user/create" |
|
|
|
|
|
|
|
|
|
|
|
type UserCreate struct { |
|
|
|
|
|
Name string `json:"name" binding:"required"` |
|
|
|
|
|
} |
|
|
|
|
|
type UserCreateResp struct { |
|
|
|
|
|
User cdssdk.User `json:"user"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Client) UserCreate(req *UserCreate) (*UserCreateResp, error) { |
|
|
|
|
|
url, err := url.JoinPath(c.baseURL, UserCreatePath) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resp, err := http2.PostJSON(url, http2.RequestParam{ |
|
|
|
|
|
Body: req, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
codeResp, err := ParseJSONResponse[response[UserCreateResp]](resp) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if codeResp.Code == errorcode.OK { |
|
|
|
|
|
return &codeResp.Data, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil, codeResp.ToError() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const UserDeletePath = "/user/delete" |
|
|
|
|
|
|
|
|
|
|
|
type UserDelete struct { |
|
|
|
|
|
UserID cdssdk.UserID `json:"userID" binding:"required"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type UserDeleteResp struct{} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Client) UserDelete(req *UserDelete) error { |
|
|
|
|
|
url, err := url.JoinPath(c.baseURL, UserDeletePath) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resp, err := http2.PostJSON(url, http2.RequestParam{ |
|
|
|
|
|
Body: req, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
codeResp, err := ParseJSONResponse[response[UserDeleteResp]](resp) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if codeResp.Code == errorcode.OK { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return codeResp.ToError() |
|
|
|
|
|
} |