Convert PageLinker to DeltaPageLinker for NonDelta pagers (#3411)
This ensures that the interface for both Delta and NonDelta requests are the same and we don't have to cast the type before getting delta url from the returned object. Follow up to https://github.com/alcionai/corso/pull/3212#discussion_r1191511216 --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
a55758020f
commit
5a2cd41d57
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user