Skip to content

Commit

Permalink
manage account users
Browse files Browse the repository at this point in the history
  • Loading branch information
dheeruk12 committed Nov 1, 2022
1 parent fcdcffc commit dc3f1d7
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion client/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,77 @@ package client

import (
"encoding/json"
"fmt"
)

type UserService service

type UserObj struct {
Email string `json:"email"`
Username string `json:"username"`
Username string `json:"username,omitempty"`
First_Name string `json:"first_name"`
Last_Name string `json:"last_name"`
Role int `json:"role,omitempty"`
}

type GetUsers struct {
Unique_Id string `json:"unique_id"`
User UserObj `json:"user"`
}
type CreateUser struct {
Team string `json:"team"`
UniqueId string `json:"unique_id,omitempty"`
User UserObj `json:"user_detail"`
}
type GetUser struct {
Team string `json:"team,omitempty"`
UniqueId string `json:"unique_id,omitempty"`
User UserObj `json:"user"`
Role int `json:"role"`
}

func (c *UserService) CreateUser(user *CreateUser) (*GetUser, error) {
path := "/api/account/api_invite/"
body, err := c.client.newRequestDo("POST", path, user)
if err != nil {
return nil, err
}
var s GetUser
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *UserService) UpdateUser(username string,user *UserObj) (*GetUser, error) {

path := fmt.Sprintf("/api/account/users/%s/", username)
body, err := c.client.newRequestDo("PATCH", path, user)
if err != nil {
return nil, err
}
var s GetUser
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c * UserService) GetUser(username string) (*GetUser, error) {
path := fmt.Sprintf("/api/account/users/%s/", username)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s GetUser
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *UserService) GetUsers(email string) ([]GetUsers, error) {
path := "/api/account/users/"
Expand Down

0 comments on commit dc3f1d7

Please sign in to comment.