@@ -16,6 +16,7 @@ import (
1616 shimjson "github.com/sentdm/sent-dm-go/internal/encoding/json"
1717 "github.com/sentdm/sent-dm-go/internal/requestconfig"
1818 "github.com/sentdm/sent-dm-go/option"
19+ "github.com/sentdm/sent-dm-go/packages/pagination"
1920 "github.com/sentdm/sent-dm-go/packages/param"
2021 "github.com/sentdm/sent-dm-go/packages/respjson"
2122)
@@ -101,14 +102,30 @@ func (r *ContactService) Update(ctx context.Context, id string, params ContactUp
101102
102103// Retrieves a paginated list of contacts for the authenticated customer. Supports
103104// filtering by search term, channel, or phone number.
104- func (r * ContactService ) List (ctx context.Context , params ContactListParams , opts ... option.RequestOption ) (res * ContactListResponse , err error ) {
105+ func (r * ContactService ) List (ctx context.Context , params ContactListParams , opts ... option.RequestOption ) (res * pagination.ContactsPage [ContactResponse ], err error ) {
106+ var raw * http.Response
105107 if ! param .IsOmitted (params .XProfileID ) {
106108 opts = append (opts , option .WithHeader ("x-profile-id" , fmt .Sprintf ("%v" , params .XProfileID .Value )))
107109 }
108110 opts = slices .Concat (r .Options , opts )
111+ opts = append ([]option.RequestOption {option .WithResponseInto (& raw )}, opts ... )
109112 path := "v3/contacts"
110- err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , params , & res , opts ... )
111- return res , err
113+ cfg , err := requestconfig .NewRequestConfig (ctx , http .MethodGet , path , params , & res , opts ... )
114+ if err != nil {
115+ return nil , err
116+ }
117+ err = cfg .Execute ()
118+ if err != nil {
119+ return nil , err
120+ }
121+ res .SetPageConfig (cfg , raw )
122+ return res , nil
123+ }
124+
125+ // Retrieves a paginated list of contacts for the authenticated customer. Supports
126+ // filtering by search term, channel, or phone number.
127+ func (r * ContactService ) ListAutoPaging (ctx context.Context , params ContactListParams , opts ... option.RequestOption ) * pagination.ContactsPageAutoPager [ContactResponse ] {
128+ return pagination .NewContactsPageAutoPager (r .List (ctx , params , opts ... ))
112129}
113130
114131// **Deprecated.** Use `PATCH /v3/contacts/{id}` with `{"opt_out": true}` instead,
@@ -325,54 +342,6 @@ func (r *ContactResponse) UnmarshalJSON(data []byte) error {
325342 return apijson .UnmarshalRoot (data , r )
326343}
327344
328- // Standard API response envelope for all v3 endpoints
329- type ContactListResponse struct {
330- // A paginated list of contacts.
331- Data ContactListResponseData `json:"data" api:"nullable"`
332- // Error information
333- Error ErrorDetail `json:"error" api:"nullable"`
334- // Request and response metadata
335- Meta APIMeta `json:"meta"`
336- // Indicates whether the request was successful
337- Success bool `json:"success"`
338- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
339- JSON struct {
340- Data respjson.Field
341- Error respjson.Field
342- Meta respjson.Field
343- Success respjson.Field
344- ExtraFields map [string ]respjson.Field
345- raw string
346- } `json:"-"`
347- }
348-
349- // Returns the unmodified JSON received from the API
350- func (r ContactListResponse ) RawJSON () string { return r .JSON .raw }
351- func (r * ContactListResponse ) UnmarshalJSON (data []byte ) error {
352- return apijson .UnmarshalRoot (data , r )
353- }
354-
355- // A paginated list of contacts.
356- type ContactListResponseData struct {
357- // The contacts on this page.
358- Contacts []ContactResponse `json:"contacts"`
359- // Pagination metadata for list responses
360- Pagination PaginationMeta `json:"pagination"`
361- // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
362- JSON struct {
363- Contacts respjson.Field
364- Pagination respjson.Field
365- ExtraFields map [string ]respjson.Field
366- raw string
367- } `json:"-"`
368- }
369-
370- // Returns the unmodified JSON received from the API
371- func (r ContactListResponseData ) RawJSON () string { return r .JSON .raw }
372- func (r * ContactListResponseData ) UnmarshalJSON (data []byte ) error {
373- return apijson .UnmarshalRoot (data , r )
374- }
375-
376345type ContactNewParams struct {
377346 // Phone number of the contact to create
378347 PhoneNumber string `json:"phone_number" api:"required"`
@@ -420,16 +389,16 @@ func (r *ContactUpdateParams) UnmarshalJSON(data []byte) error {
420389}
421390
422391type ContactListParams struct {
423- // Page number (1-indexed)
424- Page int64 `query:"page" api:"required" json:"-"`
425- // Number of items per page
426- PageSize int64 `query:"page_size" api:"required" json:"-"`
427392 // Optional channel filter (sms, whatsapp)
428393 Channel param.Opt [string ] `query:"channel,omitzero" json:"-"`
429394 // Optional phone number filter (alternative to list view)
430395 Phone param.Opt [string ] `query:"phone,omitzero" json:"-"`
431396 // Optional search term for filtering contacts
432- Search param.Opt [string ] `query:"search,omitzero" json:"-"`
397+ Search param.Opt [string ] `query:"search,omitzero" json:"-"`
398+ // Page number (1-indexed)
399+ Page param.Opt [int64 ] `query:"page,omitzero" json:"-"`
400+ // Number of items per page
401+ PageSize param.Opt [int64 ] `query:"page_size,omitzero" json:"-"`
433402 XProfileID param.Opt [string ] `header:"x-profile-id,omitzero" format:"uuid" json:"-"`
434403 paramObj
435404}
0 commit comments