From 7ea6895978b35fd61d722ee79bba0909345e9c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lewandowski?= <35259896+pawellewandowski98@users.noreply.github.com> Date: Thu, 23 May 2024 15:27:48 +0200 Subject: [PATCH] feat(SPV-804): adjust contact search methods (#227) --- admin_contacts_test.go | 8 +++++--- contacts_test.go | 5 ++++- http.go | 8 ++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/admin_contacts_test.go b/admin_contacts_test.go index 610d0fa..8ddeff1 100644 --- a/admin_contacts_test.go +++ b/admin_contacts_test.go @@ -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) @@ -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) { diff --git a/contacts_test.go b/contacts_test.go index 1d10411..4f6b0ba 100644 --- a/contacts_test.go +++ b/contacts_test.go @@ -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 { diff --git a/http.go b/http.go index 7f12cfb..a858410 100644 --- a/http.go +++ b/http.go @@ -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), @@ -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 { @@ -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), @@ -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) }