diff options
Diffstat (limited to 'grocy')
| -rw-r--r-- | grocy/user.go | 18 | 
1 files changed, 18 insertions, 0 deletions
diff --git a/grocy/user.go b/grocy/user.go index 58d3d08..493c4d5 100644 --- a/grocy/user.go +++ b/grocy/user.go @@ -2,6 +2,7 @@ package grocy  import (  	"context" +	"errors"  	"fmt"  	"net/http"  ) @@ -35,6 +36,23 @@ func (c *Client) GetUsers(ctx context.Context) ([]User, error) {  	return res, nil  } +func (c *Client) GetUser(ctx context.Context, userId int) (User, error) { +	// This is kinda hacky because grocy doesn't support getting LDAP users by +	// grocy ID :( +	res, err := c.GetUsers(ctx) +	if err != nil { +		return *new(User), err +	} + +	for _, u := range res { +		if u.Id == userId { +			return u, nil +		} +	} + +	return *new(User), errors.New("User Not Found") +} +  func (c *Client) GetUserFields(ctx context.Context, userId int) (map[string]string, error) {  	req, err := http.NewRequest("GET", fmt.Sprintf("%s/userfields/users/%d", c.BaseUrl, userId), nil)  | 
