Add initial commit

This commit is contained in:
Abhishek Pandey 2023-05-01 20:25:47 -07:00
parent 3b9d2841d4
commit c641e457fd
3 changed files with 29 additions and 0 deletions

View File

@ -55,6 +55,22 @@ func (c Contacts) CreateContactFolder(
return mdl, nil
}
// CreateContactFolder makes a contact folder with the displayName of folderName.
// If successful, returns the created folder object.
func (c Contacts) GetContactFolders(
ctx context.Context,
user string,
) (models.ContactFolderCollectionResponseable, error) {
// TODO: Add pagination or just reuse EnumerateContainer logic
// with base id at root
mdl, err := c.Stable.Client().UsersById(user).ContactFolders().Get(ctx, nil)
if err != nil {
return nil, graph.Wrap(ctx, err, "creating contact folder")
}
return mdl, nil
}
// DeleteContainer deletes the ContactFolder associated with the M365 ID if permissions are valid.
func (c Contacts) DeleteContainer(
ctx context.Context,

View File

@ -649,10 +649,18 @@ func establishContactsRestoreLocation(
return cached, nil
}
folders[0] = "Corso_Restore_02-May-2023_00:06:19"
ctx = clues.Add(ctx, "is_new_cache", isNewCache)
// This is where destination folder gets created by corso in graph
// This is the POST operation which may fail if the folder exists
temp, err := ac.Contacts().CreateContactFolder(ctx, user, folders[0])
if err != nil {
// TODO:: Add status code check too
if graph.IsErrFolderExists(err) {
result, _ := ac.Contacts().GetContactFolders(ctx, user)
//fmt.Println(result.GetValue())
}
return "", err
}

View File

@ -41,6 +41,7 @@ const (
syncFolderNotFound errorCode = "ErrorSyncFolderNotFound"
syncStateInvalid errorCode = "SyncStateInvalid"
syncStateNotFound errorCode = "SyncStateNotFound"
folderExists errorCode = "ErrorFolderExists"
)
const (
@ -172,6 +173,10 @@ func IsMalwareResp(ctx context.Context, resp *http.Response) bool {
return false
}
func IsErrFolderExists(err error) bool {
return hasErrorCode(err, folderExists)
}
// ---------------------------------------------------------------------------
// error parsers
// ---------------------------------------------------------------------------