From 080d32cef0a7a195f365b8f697b5998cc2b7fffd Mon Sep 17 00:00:00 2001 From: DDefiebre <65296654+DDefiebre@users.noreply.github.com> Date: Tue, 28 Feb 2023 12:06:12 +0100 Subject: [PATCH] Go client patch (#636) --- client/client.go | 8 ++++++++ client/client_test.go | 15 +++++++++++++++ client/model.go | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/client/client.go b/client/client.go index 6e652e9a1..67419ceff 100644 --- a/client/client.go +++ b/client/client.go @@ -63,6 +63,10 @@ func (c *GorseClient) InsertUser(ctx context.Context, user User) (RowAffected, e return request[RowAffected](ctx, c, "POST", c.entryPoint+"/api/user", user) } +func (c *GorseClient) UpdateUser(ctx context.Context, userId string, user UserPatch) (RowAffected, error) { + return request[RowAffected](ctx, c, "PATCH", fmt.Sprintf("%s/api/user/%s", c.entryPoint, userId), user) +} + func (c *GorseClient) GetUser(ctx context.Context, userId string) (User, error) { return request[User, any](ctx, c, "GET", c.entryPoint+fmt.Sprintf("/api/user/%s", userId), nil) } @@ -75,6 +79,10 @@ func (c *GorseClient) InsertItem(ctx context.Context, item Item) (RowAffected, e return request[RowAffected](ctx, c, "POST", c.entryPoint+"/api/item", item) } +func (c *GorseClient) UpdateItem(ctx context.Context, itemId string, item ItemPatch) (RowAffected, error) { + return request[RowAffected](ctx, c, "PATCH", fmt.Sprintf("%s/api/item/%s", c.entryPoint, itemId), item) +} + func (c *GorseClient) GetItem(ctx context.Context, itemId string) (Item, error) { return request[Item, any](ctx, c, "GET", c.entryPoint+fmt.Sprintf("/api/item/%s", itemId), nil) } diff --git a/client/client_test.go b/client/client_test.go index 3f71f1ed1..1fb38a405 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -284,10 +284,18 @@ func (suite *GorseClientTestSuite) TestUsers() { Subscribe: []string{"d", "e"}, Comment: "comment", } + userPatch := UserPatch{ + Comment: &user.Comment, + } + rowAffected, err := suite.client.InsertUser(ctx, user) suite.NoError(err) suite.Equal(1, rowAffected.RowAffected) + rowAffected, err = suite.client.UpdateUser(ctx, user.UserId, userPatch) + suite.NoError(err) + suite.Equal(1, rowAffected.RowAffected) + userResp, err := suite.client.GetUser(ctx, "100") suite.NoError(err) suite.Equal(user, userResp) @@ -311,10 +319,17 @@ func (suite *GorseClientTestSuite) TestItems() { Timestamp: timestamp, Comment: "comment", } + itemPatch := ItemPatch{ + Comment: &item.Comment, + } rowAffected, err := suite.client.InsertItem(ctx, item) suite.NoError(err) suite.Equal(1, rowAffected.RowAffected) + rowAffected, err = suite.client.UpdateItem(ctx, item.ItemId, itemPatch) + suite.NoError(err) + suite.Equal(1, rowAffected.RowAffected) + itemResp, err := suite.client.GetItem(ctx, "100") suite.NoError(err) suite.Equal(item, itemResp) diff --git a/client/model.go b/client/model.go index 5004cf716..707544c6f 100644 --- a/client/model.go +++ b/client/model.go @@ -14,6 +14,8 @@ package client +import "time" + type Feedback struct { FeedbackType string `json:"FeedbackType"` UserId string `json:"UserId"` @@ -43,6 +45,12 @@ type User struct { Comment string `json:"Comment"` } +type UserPatch struct { + Labels []string + Subscribe []string + Comment *string +} + type Item struct { ItemId string `json:"ItemId"` IsHidden bool `json:"IsHidden"` @@ -51,3 +59,11 @@ type Item struct { Timestamp string `json:"Timestamp"` Comment string `json:"Comment"` } + +type ItemPatch struct { + IsHidden *bool + Categories []string + Timestamp *time.Time + Labels []string + Comment *string +}