From 9ca0c7385a11ced05a9885a3498246c6d6d8c018 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Tue, 6 Jun 2023 01:30:02 +0700 Subject: [PATCH] TF-1865: Create func update sending email in data layer (cherry picked from commit d2b2f7af4afd4fc817ae404548650182deb9e0ed) --- .../email/data/datasource/email_datasource.dart | 4 +++- .../data/datasource_impl/email_datasource_impl.dart | 5 +++++ .../email_hive_cache_datasource_impl.dart | 7 +++++++ .../manager/sending_email_cache_manager.dart | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/features/email/data/datasource/email_datasource.dart b/lib/features/email/data/datasource/email_datasource.dart index fe150d32d..2ff2d8abb 100644 --- a/lib/features/email/data/datasource/email_datasource.dart +++ b/lib/features/email/data/datasource/email_datasource.dart @@ -92,7 +92,9 @@ abstract class EmailDataSource { Future storeSendingEmail(AccountId accountId, UserName userName, SendingEmail sendingEmail); - Future> getAllSendingEmails(AccountId accountId, UserName userName, {bool needToReopen = false}); + Future updateSendingEmail(AccountId accountId, UserName userName, SendingEmail sendingEmail); + + Future> getAllSendingEmails(AccountId accountId, UserName userName); Future deleteSendingEmail(AccountId accountId, UserName userName, String sendingId); } \ No newline at end of file diff --git a/lib/features/email/data/datasource_impl/email_datasource_impl.dart b/lib/features/email/data/datasource_impl/email_datasource_impl.dart index fc201a055..6f9ee6768 100644 --- a/lib/features/email/data/datasource_impl/email_datasource_impl.dart +++ b/lib/features/email/data/datasource_impl/email_datasource_impl.dart @@ -203,4 +203,9 @@ class EmailDataSourceImpl extends EmailDataSource { Future deleteSendingEmail(AccountId accountId, UserName userName, String sendingId) { throw UnimplementedError(); } + + @override + Future updateSendingEmail(AccountId accountId, UserName userName, SendingEmail sendingEmail) { + throw UnimplementedError(); + } } \ No newline at end of file diff --git a/lib/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart b/lib/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart index bac89761f..813b1e210 100644 --- a/lib/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart +++ b/lib/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart @@ -267,4 +267,11 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource { return await _sendingEmailCacheManager.deleteSendingEmail(accountId, userName, sendingId); }).catchError(_exceptionThrower.throwException); } + + @override + Future updateSendingEmail(AccountId accountId, UserName userName, SendingEmail sendingEmail) { + return Future.sync(() async { + return await _sendingEmailCacheManager.updateSendingEmail(accountId, userName, sendingEmail.toHiveCache()); + }).catchError(_exceptionThrower.throwException); + } } \ No newline at end of file diff --git a/lib/features/offline_mode/manager/sending_email_cache_manager.dart b/lib/features/offline_mode/manager/sending_email_cache_manager.dart index 1951df44b..bdf45a567 100644 --- a/lib/features/offline_mode/manager/sending_email_cache_manager.dart +++ b/lib/features/offline_mode/manager/sending_email_cache_manager.dart @@ -56,4 +56,14 @@ class SendingEmailCacheManager { } Future clearAllSendingEmails() => _hiveCacheClient.clearAllData(); + + Future updateSendingEmail( + AccountId accountId, + UserName userName, + SendingEmailHiveCache sendingEmailHiveCache + ) async { + final keyCache = TupleKey(sendingEmailHiveCache.sendingId, accountId.asString, userName.value).encodeKey; + log('SendingEmailCacheManager::updateSendingEmail():keyCache: $keyCache | sendingEmailHiveCache: $sendingEmailHiveCache'); + return await _hiveCacheClient.updateItem(keyCache, sendingEmailHiveCache, needToReopen: true); + } } \ No newline at end of file