get lists with collision key (#5009)
gets lists with collision key #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature #### Issue(s) #4754 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
e16d4c5bd9
commit
c43ad6c517
@ -556,3 +556,18 @@ func ListToSPInfo(lst models.Listable) *details.SharePointInfo {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listCollisionKeyProps() []string {
|
||||||
|
return idAnd("displayName")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two lists with same name cannot be created,
|
||||||
|
// hence going by the displayName itself as the collision key.
|
||||||
|
// Only displayName can be set. name is system generated based on displayName.
|
||||||
|
func ListCollisionKey(list models.Listable) string {
|
||||||
|
if list == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr.Val(list.GetDisplayName())
|
||||||
|
}
|
||||||
|
|||||||
@ -3,9 +3,11 @@ package api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/sites"
|
"github.com/microsoftgraph/msgraph-sdk-go/sites"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
|
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
|
||||||
"github.com/alcionai/corso/src/pkg/services/m365/api/pagers"
|
"github.com/alcionai/corso/src/pkg/services/m365/api/pagers"
|
||||||
)
|
)
|
||||||
@ -77,6 +79,26 @@ func (c Lists) GetLists(
|
|||||||
return items, graph.Stack(ctx, err).OrNil()
|
return items, graph.Stack(ctx, err).OrNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Lists) GetListsByCollisionKey(
|
||||||
|
ctx context.Context,
|
||||||
|
siteID string,
|
||||||
|
) (map[string]string, error) {
|
||||||
|
pager := c.NewListsPager(siteID, CallConfig{Select: listCollisionKeyProps()})
|
||||||
|
|
||||||
|
items, err := pagers.BatchEnumerateItems[models.Listable](ctx, pager)
|
||||||
|
if err != nil {
|
||||||
|
return nil, clues.WrapWC(ctx, err, "enumerating lists")
|
||||||
|
}
|
||||||
|
|
||||||
|
m := map[string]string{}
|
||||||
|
|
||||||
|
for _, item := range items {
|
||||||
|
m[ListCollisionKey(item)] = ptr.Val(item.GetId())
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// list items pager
|
// list items pager
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -42,6 +42,7 @@ func (suite *ListsPagerIntgSuite) TestEnumerateLists_withAssociatedRelationships
|
|||||||
ac = suite.its.gockAC.Lists()
|
ac = suite.its.gockAC.Lists()
|
||||||
|
|
||||||
listID = "fake-list-id"
|
listID = "fake-list-id"
|
||||||
|
listDisplayName = "fake-list-name"
|
||||||
listLastModifiedTime = time.Now()
|
listLastModifiedTime = time.Now()
|
||||||
siteID = suite.its.site.id
|
siteID = suite.its.site.id
|
||||||
textColumnDefID = "fake-text-column-id"
|
textColumnDefID = "fake-text-column-id"
|
||||||
@ -65,6 +66,7 @@ func (suite *ListsPagerIntgSuite) TestEnumerateLists_withAssociatedRelationships
|
|||||||
|
|
||||||
suite.setStubListAndItsRelationShip(
|
suite.setStubListAndItsRelationShip(
|
||||||
listID,
|
listID,
|
||||||
|
listDisplayName,
|
||||||
siteID,
|
siteID,
|
||||||
textColumnDefID,
|
textColumnDefID,
|
||||||
textColumnDefName,
|
textColumnDefName,
|
||||||
@ -249,8 +251,60 @@ func (suite *ListsPagerIntgSuite) testEnumerateCTypeColumns(
|
|||||||
return cTypeCols
|
return cTypeCols
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ListsPagerIntgSuite) TestGetListsByCollisionKey() {
|
||||||
|
var (
|
||||||
|
t = suite.T()
|
||||||
|
ac = suite.its.gockAC.Lists()
|
||||||
|
|
||||||
|
listID = "fake-list-id"
|
||||||
|
listDisplayName = "fake-list-name"
|
||||||
|
listLastModifiedTime = time.Now()
|
||||||
|
siteID = suite.its.site.id
|
||||||
|
textColumnDefID = "fake-text-column-id"
|
||||||
|
textColumnDefName = "itemName"
|
||||||
|
numColumnDefID = "fake-num-column-id"
|
||||||
|
numColumnDefName = "itemSize"
|
||||||
|
colLinkID = "fake-collink-id"
|
||||||
|
cTypeID = "fake-ctype-id"
|
||||||
|
listItemID = "fake-list-item-id"
|
||||||
|
|
||||||
|
fieldsData = map[string]any{
|
||||||
|
"itemName": "item1",
|
||||||
|
"itemSize": 4,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
suite.setStubListAndItsRelationShip(
|
||||||
|
listID,
|
||||||
|
listDisplayName,
|
||||||
|
siteID,
|
||||||
|
textColumnDefID,
|
||||||
|
textColumnDefName,
|
||||||
|
numColumnDefID,
|
||||||
|
numColumnDefName,
|
||||||
|
colLinkID,
|
||||||
|
cTypeID,
|
||||||
|
listItemID,
|
||||||
|
listLastModifiedTime,
|
||||||
|
fieldsData)
|
||||||
|
|
||||||
|
expected := map[string]string{
|
||||||
|
listDisplayName: listID,
|
||||||
|
}
|
||||||
|
|
||||||
|
lists, err := ac.GetListsByCollisionKey(ctx, suite.its.site.id)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, expected, lists)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *ListsPagerIntgSuite) setStubListAndItsRelationShip(
|
func (suite *ListsPagerIntgSuite) setStubListAndItsRelationShip(
|
||||||
listID,
|
listID,
|
||||||
|
listDisplayName,
|
||||||
siteID,
|
siteID,
|
||||||
textColumnDefID,
|
textColumnDefID,
|
||||||
textColumnDefName,
|
textColumnDefName,
|
||||||
@ -265,6 +319,7 @@ func (suite *ListsPagerIntgSuite) setStubListAndItsRelationShip(
|
|||||||
list := models.NewList()
|
list := models.NewList()
|
||||||
list.SetId(ptr.To(listID))
|
list.SetId(ptr.To(listID))
|
||||||
list.SetLastModifiedDateTime(ptr.To(listLastModifiedTime))
|
list.SetLastModifiedDateTime(ptr.To(listLastModifiedTime))
|
||||||
|
list.SetDisplayName(ptr.To(listDisplayName))
|
||||||
|
|
||||||
listCol := models.NewListCollectionResponse()
|
listCol := models.NewListCollectionResponse()
|
||||||
listCol.SetValue([]models.Listable{list})
|
listCol.SetValue([]models.Listable{list})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user