Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go client patch #636

Merged
merged 7 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}