Skip to content

Commit

Permalink
feat(SPV-804): adjust contact search methods (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 authored May 23, 2024
1 parent 474ab3e commit 7ea6895
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
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

0 comments on commit 7ea6895

Please sign in to comment.