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

feat(SPV-804): adjust contact search methods #227

Merged
merged 2 commits into from
May 23, 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
8 changes: 5 additions & 3 deletions admin_contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ func TestAdminContactActions(t *testing.T) {
case r.URL.Path == "/v1/admin/contact/search" && r.Method == http.MethodPost:
c := fixtures.Contact
c.ID = "1"
contacts := []*models.Contact{c}
json.NewEncoder(w).Encode(contacts)
content := models.PagedResponse[*models.Contact]{
Content: []*models.Contact{c},
}
json.NewEncoder(w).Encode(content)
case r.URL.Path == "/v1/admin/contact/1" && r.Method == http.MethodPatch:
contact := fixtures.Contact
json.NewEncoder(w).Encode(contact)
Expand All @@ -46,7 +48,7 @@ func TestAdminContactActions(t *testing.T) {
t.Run("AdminGetContacts", func(t *testing.T) {
contacts, err := client.AdminGetContacts(context.Background(), nil, nil, nil)
require.NoError(t, err)
require.Equal(t, "1", contacts[0].ID)
require.Equal(t, "1", contacts.Content[0].ID)
})

t.Run("AdminUpdateContact", func(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestContactActionsRouting(t *testing.T) {
}
case r.URL.Path == "/v1/contact/search":
if r.Method == http.MethodPost {
json.NewEncoder(w).Encode([]*models.Contact{fixtures.Contact})
content := models.PagedResponse[*models.Contact]{
Content: []*models.Contact{fixtures.Contact},
}
json.NewEncoder(w).Encode(content)
}
case strings.HasPrefix(r.URL.Path, "/v1/contact/"):
if r.Method == http.MethodPost || r.Method == http.MethodPut {
Expand Down
8 changes: 4 additions & 4 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func (wc *WalletClient) ConfirmContact(ctx context.Context, contact *models.Cont
}

// GetContacts will get contacts by conditions
func (wc *WalletClient) GetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Contact, ResponseError) {
func (wc *WalletClient) GetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) (*models.SearchContactsResponse, ResponseError) {
jsonStr, err := json.Marshal(map[string]interface{}{
FieldConditions: conditions,
FieldMetadata: processMetadata(metadata),
Expand All @@ -674,7 +674,7 @@ func (wc *WalletClient) GetContacts(ctx context.Context, conditions map[string]i
return nil, WrapError(err)
}

var result []*models.Contact
var result *models.SearchContactsResponse
if err := wc.doHTTPRequest(
ctx, http.MethodPost, "/contact/search", jsonStr, wc.xPriv, wc.signRequest, &result,
); err != nil {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ func (wc *WalletClient) AdminGetSharedConfig(ctx context.Context) (*models.Share
}

// AdminGetContacts executes an HTTP POST request to search for contacts based on specified conditions, metadata, and query parameters.
func (wc *WalletClient) AdminGetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) ([]*models.Contact, ResponseError) {
func (wc *WalletClient) AdminGetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *QueryParams) (*models.SearchContactsResponse, ResponseError) {
jsonStr, err := json.Marshal(map[string]interface{}{
FieldConditions: conditions,
FieldMetadata: processMetadata(metadata),
Expand All @@ -1035,7 +1035,7 @@ func (wc *WalletClient) AdminGetContacts(ctx context.Context, conditions map[str
return nil, WrapError(err)
}

var contacts []*models.Contact
var contacts *models.SearchContactsResponse
err = wc.doHTTPRequest(ctx, http.MethodPost, "/admin/contact/search", jsonStr, wc.adminXPriv, true, &contacts)
return contacts, WrapError(err)
}
Expand Down
Loading