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

fix(SPV-1283): use proper upsertcontact command field for a path param #41

Merged
merged 4 commits into from
Dec 10, 2024
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
7 changes: 4 additions & 3 deletions commands/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package commands

// UpsertContact holds the necessary arguments for adding or updating a user's contact information.
type UpsertContact struct {
FullName string `json:"fullName"` // The full name of the user.
Metadata map[string]any `json:"metadata"` // Metadata associated with the contact.
Paymail string `json:"requesterPaymail"` // Paymail address of the user, which is used for secure and simplified payment transfers.
ContactPaymail string `json:"-"` // Paymail address of the new/updating contact.
FullName string `json:"fullName"` // The full name of the user.
Metadata map[string]any `json:"metadata"` // Metadata associated with the contact.
RequesterPaymail string `json:"requesterPaymail"` // RequesterPaymail address of the user, which is used for secure and simplified payment transfers.
}

// UpdateContact represents the arguments defined for updating a user's contact information.
Expand Down
11 changes: 7 additions & 4 deletions examples/contact_upsert/contact_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ func main() {
log.Fatal(err)
}

paymail := "john.doe@example.com"
contactPaymail := "john.doe@example.com"
contact, err := usersAPI.UpsertContact(context.Background(), commands.UpsertContact{
FullName: "John Doe",
ContactPaymail: contactPaymail,
FullName: "John Doe",
Metadata: map[string]any{
"key": "value",
},
Paymail: paymail,
// Optional field representing the paymail address of the user who is creating the contact.
// It is required in case if user has multiple paymail addresses associated with single xPub.
//RequesterPaymail: "",
})
if err != nil {
log.Fatal(err)
}

exampleutil.Print(fmt.Sprintf("[HTTP PUT] Upsert contact - api/v1/contacts/%s", paymail), contact)
exampleutil.Print(fmt.Sprintf("[HTTP PUT] Upsert contact - api/v1/contacts/%s", contactPaymail), contact)
}
2 changes: 1 addition & 1 deletion internal/api/v1/user/contacts/contacts_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (a *API) UpsertContact(ctx context.Context, cmd commands.UpsertContact) (*r
SetBody(cmd).
SetContext(ctx).
SetResult(&result).
Put(a.url.JoinPath(cmd.Paymail).String())
Put(a.url.JoinPath(cmd.ContactPaymail).String())
if err != nil {
return nil, fmt.Errorf("HTTP response failure: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/api/v1/user/contacts/contacts_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func TestContactsAPI_UpsertContact(t *testing.T) {

// when:
got, err := wallet.UpsertContact(context.Background(), commands.UpsertContact{
FullName: "John Doe",
Metadata: map[string]any{"example_key": "example_val"},
Paymail: paymail,
ContactPaymail: paymail,
FullName: "John Doe",
Metadata: map[string]any{"example_key": "example_val"},
})

// then:
Expand Down
Loading