Skip to content

Commit

Permalink
feat: add pagination opts to AutocompleteSearchCustomObjectRecords
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Romolini <[email protected]>
  • Loading branch information
paoloromolini committed May 20, 2024
1 parent 6dd2223 commit bbf65df
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions zendesk/custom_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type CustomObjectAPI interface {
AutocompleteSearchCustomObjectRecords(
ctx context.Context,
customObjectKey string,
opts *PageOptions,
) ([]CustomObjectRecord, Page, error)
opts *AutocompleteSearchCustomObjectRecordsOptions,
) ([]CustomObjectRecord, CursorPaginationMeta, error)
SearchCustomObjectRecords(
ctx context.Context, customObjectKey string, opts *SearchCustomObjectRecordsOptions,
) ([]CustomObjectRecord, CursorPaginationMeta, error)
Expand Down Expand Up @@ -103,6 +103,12 @@ type CustomObjectListOptions struct {
ExternalIds string `url:"filter[external_ids],omitempty"`
}

// AutocompleteSearchCustomObjectRecordsOptions custom object search
type AutocompleteSearchCustomObjectRecordsOptions struct {
Name string `url:"name,omitempty"`
CursorPagination
}

// ListCustomObjectRecords list objects
// https://developer.zendesk.com/api-reference/custom-data/custom-objects/custom_object_records/#list-custom-object-records
func (z *Client) ListCustomObjectRecords(
Expand Down Expand Up @@ -132,28 +138,28 @@ func (z *Client) ListCustomObjectRecords(
// AutocompleteSearchCustomObjectRecords search for a custom object record by the name field
// https://developer.zendesk.com/api-reference/custom-objects/custom_object_records/#autocomplete-custom-object-record-search
func (z *Client) AutocompleteSearchCustomObjectRecords(
ctx context.Context, customObjectKey string, opts *PageOptions,
) ([]CustomObjectRecord, Page, error) {
ctx context.Context, customObjectKey string, opts *AutocompleteSearchCustomObjectRecordsOptions,
) ([]CustomObjectRecord, CursorPaginationMeta, error) {
var result struct {
CustomObjectRecords []CustomObjectRecord `json:"custom_object_records"`
Page
Meta CursorPaginationMeta `json:"meta"`
}
tmp := opts
if tmp == nil {
tmp = &PageOptions{}
tmp = &AutocompleteSearchCustomObjectRecordsOptions{}
}
url := fmt.Sprintf("/custom_objects/%s/records/autocomplete", customObjectKey)
urlWithOptions, err := addOptions(url, tmp)
body, err := z.get(ctx, urlWithOptions)

if err != nil {
return nil, Page{}, err
return nil, CursorPaginationMeta{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return nil, Page{}, err
return nil, CursorPaginationMeta{}, err
}
return result.CustomObjectRecords, result.Page, nil
return result.CustomObjectRecords, result.Meta, nil
}

type SearchCustomObjectRecordsOptions struct {
Expand Down

0 comments on commit bbf65df

Please sign in to comment.