adds list backup and restore handlers (#4919)
adds list backup and restore handlers Changes previously approved in: - https://github.com/alcionai/corso/pull/4786 - https://github.com/alcionai/corso/pull/4854 #### 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
1270e64637
commit
00662c4cd9
43
src/internal/m365/collection/site/handlers.go
Normal file
43
src/internal/m365/collection/site/handlers.go
Normal file
@ -0,0 +1,43 @@
|
||||
package site
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
type backupHandler interface {
|
||||
getItemByIDer
|
||||
getItemser
|
||||
}
|
||||
|
||||
type getItemByIDer interface {
|
||||
GetItemByID(ctx context.Context, itemID string) (models.Listable, *details.SharePointInfo, error)
|
||||
}
|
||||
|
||||
type getItemser interface {
|
||||
GetItems(ctx context.Context, cc api.CallConfig) ([]models.Listable, error)
|
||||
}
|
||||
|
||||
type restoreHandler interface {
|
||||
PostLister
|
||||
DeleteLister
|
||||
}
|
||||
|
||||
type PostLister interface {
|
||||
PostList(
|
||||
ctx context.Context,
|
||||
listName string,
|
||||
storedListData []byte,
|
||||
) (models.Listable, error)
|
||||
}
|
||||
|
||||
type DeleteLister interface {
|
||||
DeleteList(
|
||||
ctx context.Context,
|
||||
listID string,
|
||||
) error
|
||||
}
|
||||
64
src/internal/m365/collection/site/lists_handler.go
Normal file
64
src/internal/m365/collection/site/lists_handler.go
Normal file
@ -0,0 +1,64 @@
|
||||
package site
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
var _ backupHandler = &listsBackupHandler{}
|
||||
|
||||
type listsBackupHandler struct {
|
||||
ac api.Lists
|
||||
protectedResource string
|
||||
}
|
||||
|
||||
func NewListsBackupHandler(protectedResource string, ac api.Lists) listsBackupHandler {
|
||||
return listsBackupHandler{
|
||||
ac: ac,
|
||||
protectedResource: protectedResource,
|
||||
}
|
||||
}
|
||||
|
||||
func (bh listsBackupHandler) GetItemByID(
|
||||
ctx context.Context,
|
||||
itemID string,
|
||||
) (models.Listable, *details.SharePointInfo, error) {
|
||||
return bh.ac.GetListByID(ctx, bh.protectedResource, itemID)
|
||||
}
|
||||
|
||||
func (bh listsBackupHandler) GetItems(ctx context.Context, cc api.CallConfig) ([]models.Listable, error) {
|
||||
return bh.ac.GetLists(ctx, bh.protectedResource, cc)
|
||||
}
|
||||
|
||||
var _ restoreHandler = &listsRestoreHandler{}
|
||||
|
||||
type listsRestoreHandler struct {
|
||||
ac api.Lists
|
||||
protectedResource string
|
||||
}
|
||||
|
||||
func NewListsRestoreHandler(protectedResource string, ac api.Lists) listsRestoreHandler {
|
||||
return listsRestoreHandler{
|
||||
ac: ac,
|
||||
protectedResource: protectedResource,
|
||||
}
|
||||
}
|
||||
|
||||
func (rh listsRestoreHandler) PostList(
|
||||
ctx context.Context,
|
||||
listName string,
|
||||
storedListData []byte,
|
||||
) (models.Listable, error) {
|
||||
return rh.ac.PostList(ctx, rh.protectedResource, listName, storedListData)
|
||||
}
|
||||
|
||||
func (rh listsRestoreHandler) DeleteList(
|
||||
ctx context.Context,
|
||||
listID string,
|
||||
) error {
|
||||
return rh.ac.DeleteList(ctx, rh.protectedResource, listID)
|
||||
}
|
||||
49
src/internal/m365/collection/site/mock/list.go
Normal file
49
src/internal/m365/collection/site/mock/list.go
Normal file
@ -0,0 +1,49 @@
|
||||
package mock
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||
)
|
||||
|
||||
type ListHandler struct {
|
||||
List models.Listable
|
||||
Err error
|
||||
}
|
||||
|
||||
func (lh *ListHandler) GetItemByID(
|
||||
ctx context.Context,
|
||||
itemID string,
|
||||
) (models.Listable, *details.SharePointInfo, error) {
|
||||
ls := models.NewList()
|
||||
|
||||
lh.List = ls
|
||||
lh.List.SetId(ptr.To(itemID))
|
||||
|
||||
info := &details.SharePointInfo{
|
||||
ItemName: itemID,
|
||||
}
|
||||
|
||||
return ls, info, lh.Err
|
||||
}
|
||||
|
||||
type ListRestoreHandler struct {
|
||||
List models.Listable
|
||||
Err error
|
||||
}
|
||||
|
||||
func (lh *ListRestoreHandler) PostList(
|
||||
ctx context.Context,
|
||||
listName string,
|
||||
storedListBytes []byte,
|
||||
) (models.Listable, error) {
|
||||
ls := models.NewList()
|
||||
|
||||
lh.List = ls
|
||||
lh.List.SetDisplayName(ptr.To(listName))
|
||||
|
||||
return lh.List, lh.Err
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user