diff --git a/src/internal/connector/exchange/api/contacts.go b/src/internal/connector/exchange/api/contacts.go index 1c5555ca1..9812d0539 100644 --- a/src/internal/connector/exchange/api/contacts.go +++ b/src/internal/connector/exchange/api/contacts.go @@ -222,13 +222,13 @@ func NewContactPager( return &contactPager{gs, builder, options}, nil } -func (p *contactPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *contactPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) } - return resp, nil + return api.EmptyDeltaLinker[models.Contactable]{PageLinkValuer: resp}, nil } func (p *contactPager) setNext(nextLink string) { @@ -301,7 +301,7 @@ func NewContactDeltaPager( return &contactDeltaPager{gs, user, directoryID, builder, options}, nil } -func (p *contactDeltaPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *contactDeltaPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) diff --git a/src/internal/connector/exchange/api/events.go b/src/internal/connector/exchange/api/events.go index 8edeffaba..c6429e897 100644 --- a/src/internal/connector/exchange/api/events.go +++ b/src/internal/connector/exchange/api/events.go @@ -283,13 +283,13 @@ func NewEventPager( return &eventPager{gs, builder, options}, nil } -func (p *eventPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *eventPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) } - return resp, nil + return api.EmptyDeltaLinker[models.Eventable]{PageLinkValuer: resp}, nil } func (p *eventPager) setNext(nextLink string) { @@ -359,7 +359,7 @@ func getEventDeltaBuilder( return builder } -func (p *eventDeltaPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *eventDeltaPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { resp, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) diff --git a/src/internal/connector/exchange/api/mail.go b/src/internal/connector/exchange/api/mail.go index fb9f98e84..d4fbf377c 100644 --- a/src/internal/connector/exchange/api/mail.go +++ b/src/internal/connector/exchange/api/mail.go @@ -385,13 +385,13 @@ func NewMailPager( return &mailPager{gs, builder, options}, nil } -func (p *mailPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *mailPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { page, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) } - return page, nil + return api.EmptyDeltaLinker[models.Messageable]{PageLinkValuer: page}, nil } func (p *mailPager) setNext(nextLink string) { @@ -465,7 +465,7 @@ func NewMailDeltaPager( return &mailDeltaPager{gs, user, directoryID, builder, options}, nil } -func (p *mailDeltaPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *mailDeltaPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { page, err := p.builder.Get(ctx, p.options) if err != nil { return nil, graph.Stack(ctx, err) diff --git a/src/internal/connector/exchange/api/shared.go b/src/internal/connector/exchange/api/shared.go index 87d579140..139eb5ecc 100644 --- a/src/internal/connector/exchange/api/shared.go +++ b/src/internal/connector/exchange/api/shared.go @@ -18,7 +18,7 @@ import ( type itemPager interface { // getPage get a page with the specified options from graph - getPage(context.Context) (api.PageLinker, error) + getPage(context.Context) (api.DeltaPageLinker, error) // setNext is used to pass in the next url got from graph setNext(string) // reset is used to clear delta url in delta pagers. When @@ -119,8 +119,6 @@ func getItemsAddedAndRemovedFromContainer( addedIDs = []string{} removedIDs = []string{} deltaURL string - nextLink string - deltaLink string ) itemCount := 0 @@ -160,13 +158,7 @@ func getItemsAddedAndRemovedFromContainer( } } - dresp, ok := resp.(api.DeltaPageLinker) - if ok { - nextLink, deltaLink = api.NextAndDeltaLink(dresp) - } else { - nextLink = api.NextLink(resp) - deltaLink = "" // to make sure we don't use an old value - } + nextLink, deltaLink := api.NextAndDeltaLink(resp) // the deltaLink is kind of like a cursor for overall data state. // once we run through pages of nextLinks, the last query will diff --git a/src/internal/connector/exchange/api/shared_test.go b/src/internal/connector/exchange/api/shared_test.go index 447d1b2c8..6a2fd1e25 100644 --- a/src/internal/connector/exchange/api/shared_test.go +++ b/src/internal/connector/exchange/api/shared_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph/api" "github.com/alcionai/corso/src/internal/tester" @@ -31,8 +32,13 @@ func (v testPagerValue) GetAdditionalData() map[string]any { type testPage struct{} func (p testPage) GetOdataNextLink() *string { - next := "" // no next, just one page - return &next + // no next, just one page + return ptr.To("") +} + +func (p testPage) GetOdataDeltaLink() *string { + // delta is not tested here + return ptr.To("") } var _ itemPager = &testPager{} @@ -45,7 +51,7 @@ type testPager struct { needsReset bool } -func (p *testPager) getPage(ctx context.Context) (api.PageLinker, error) { +func (p *testPager) getPage(ctx context.Context) (api.DeltaPageLinker, error) { if p.errorCode != "" { ierr := odataerrors.NewMainError() ierr.SetCode(&p.errorCode) diff --git a/src/internal/connector/graph/api/api.go b/src/internal/connector/graph/api/api.go index 0870f9ea0..3db26bf85 100644 --- a/src/internal/connector/graph/api/api.go +++ b/src/internal/connector/graph/api/api.go @@ -27,3 +27,25 @@ func NextLink(pl PageLinker) string { func NextAndDeltaLink(pl DeltaPageLinker) (string, string) { return NextLink(pl), ptr.Val(pl.GetOdataDeltaLink()) } + +type Valuer[T any] interface { + GetValue() []T +} + +type PageLinkValuer[T any] interface { + PageLinker + Valuer[T] +} + +// EmptyDeltaLinker is used to convert PageLinker to DeltaPageLinker +type EmptyDeltaLinker[T any] struct { + PageLinkValuer[T] +} + +func (EmptyDeltaLinker[T]) GetOdataDeltaLink() *string { + return ptr.To("") +} + +func (e EmptyDeltaLinker[T]) GetValue() []T { + return e.PageLinkValuer.GetValue() +}