From 00662c4cd90ece54c1b94a2d1b7622a10cf4f615 Mon Sep 17 00:00:00 2001 From: Hitesh Pattanayak <48874082+HiteshRepo@users.noreply.github.com> Date: Fri, 22 Dec 2023 15:29:19 +0530 Subject: [PATCH] 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_entry: No #### Type of change - [x] :sunflower: Feature #### Issue(s) #4754 #### Test Plan - [x] :muscle: Manual - [x] :zap: Unit test - [x] :green_heart: E2E --- src/internal/m365/collection/site/handlers.go | 43 +++++++++++++ .../m365/collection/site/lists_handler.go | 64 +++++++++++++++++++ .../m365/collection/site/mock/list.go | 49 ++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 src/internal/m365/collection/site/handlers.go create mode 100644 src/internal/m365/collection/site/lists_handler.go create mode 100644 src/internal/m365/collection/site/mock/list.go diff --git a/src/internal/m365/collection/site/handlers.go b/src/internal/m365/collection/site/handlers.go new file mode 100644 index 000000000..fac778de7 --- /dev/null +++ b/src/internal/m365/collection/site/handlers.go @@ -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 +} diff --git a/src/internal/m365/collection/site/lists_handler.go b/src/internal/m365/collection/site/lists_handler.go new file mode 100644 index 000000000..a9e130974 --- /dev/null +++ b/src/internal/m365/collection/site/lists_handler.go @@ -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) +} diff --git a/src/internal/m365/collection/site/mock/list.go b/src/internal/m365/collection/site/mock/list.go new file mode 100644 index 000000000..0f66057fd --- /dev/null +++ b/src/internal/m365/collection/site/mock/list.go @@ -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 +}