Skip to content

Commit

Permalink
Go client patch (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
DDefiebre committed Feb 28, 2023
1 parent bcc601b commit 080d32c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
15 changes: 15 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package client

import "time"

type Feedback struct {
FeedbackType string `json:"FeedbackType"`
UserId string `json:"UserId"`
Expand Down Expand Up @@ -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"`
Expand All @@ -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
}

0 comments on commit 080d32c

Please sign in to comment.