From 87678ecf435874e7771b0e47911ffb2aa2c4d33e Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sun, 3 Sep 2023 12:30:50 -0400 Subject: chore reminders Sends a discord webhook with reminders as to who has what chore! --- grocy/user.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'grocy') 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) -- cgit v1.2.3