diff --git a/shared/data/core/src/androidTest/java/com/ivy/data/backup/BackupDataUseCaseAndroidTest.kt b/shared/data/core/src/androidTest/java/com/ivy/data/backup/BackupDataUseCaseAndroidTest.kt index b60bc9086d..0940597b9a 100644 --- a/shared/data/core/src/androidTest/java/com/ivy/data/backup/BackupDataUseCaseAndroidTest.kt +++ b/shared/data/core/src/androidTest/java/com/ivy/data/backup/BackupDataUseCaseAndroidTest.kt @@ -74,6 +74,10 @@ class BackupDataUseCaseAndroidTest { dispatchersProvider = TestDispatchersProvider, fileSystem = FileSystem(appContext), dataObserver = DataObserver(), + tagsReader = db.tagDao, + tagAssociationReader = db.tagAssociationDao, + tagsWriter = db.writeTagDao, + tagAssociationWriter = db.writeTagAssociationDao ) } diff --git a/shared/data/core/src/main/java/com/ivy/data/backup/BackupDataUseCase.kt b/shared/data/core/src/main/java/com/ivy/data/backup/BackupDataUseCase.kt index 059543ffb6..ee29022f9d 100644 --- a/shared/data/core/src/main/java/com/ivy/data/backup/BackupDataUseCase.kt +++ b/shared/data/core/src/main/java/com/ivy/data/backup/BackupDataUseCase.kt @@ -16,6 +16,8 @@ import com.ivy.data.db.dao.read.LoanDao import com.ivy.data.db.dao.read.LoanRecordDao import com.ivy.data.db.dao.read.PlannedPaymentRuleDao import com.ivy.data.db.dao.read.SettingsDao +import com.ivy.data.db.dao.read.TagAssociationDao +import com.ivy.data.db.dao.read.TagDao import com.ivy.data.db.dao.read.TransactionDao import com.ivy.data.db.dao.write.WriteBudgetDao import com.ivy.data.db.dao.write.WriteCategoryDao @@ -23,6 +25,8 @@ import com.ivy.data.db.dao.write.WriteLoanDao import com.ivy.data.db.dao.write.WriteLoanRecordDao import com.ivy.data.db.dao.write.WritePlannedPaymentRuleDao import com.ivy.data.db.dao.write.WriteSettingsDao +import com.ivy.data.db.dao.write.WriteTagAssociationDao +import com.ivy.data.db.dao.write.WriteTagDao import com.ivy.data.db.dao.write.WriteTransactionDao import com.ivy.data.file.FileSystem import com.ivy.data.repository.AccountRepository @@ -65,6 +69,10 @@ class BackupDataUseCase @Inject constructor( private val dispatchersProvider: DispatchersProvider, private val fileSystem: FileSystem, private val dataObserver: DataObserver, + private val tagsReader: TagDao, + private val tagAssociationReader: TagAssociationDao, + private val tagsWriter: WriteTagDao, + private val tagAssociationWriter: WriteTagAssociationDao ) { suspend fun exportToFile( zipFileUri: Uri @@ -98,6 +106,8 @@ class BackupDataUseCase @Inject constructor( val settings = async { settingsDao.findAll() } val transactions = async { transactionDao.findAll() } val sharedPrefs = async { getSharedPrefsData() } + val tags = async { tagsReader.findAll() } + val tagAssociations = async { tagAssociationReader.findAll() } val completeData = IvyWalletCompleteData( accounts = accounts.await(), @@ -108,7 +118,9 @@ class BackupDataUseCase @Inject constructor( plannedPaymentRules = plannedPaymentRules.await(), settings = settings.await(), transactions = transactions.await(), - sharedPrefs = sharedPrefs.await() + sharedPrefs = sharedPrefs.await(), + tags = tags.await(), + tagAssociations = tagAssociations.await() ) json.encodeToString(completeData) @@ -263,6 +275,9 @@ class BackupDataUseCase @Inject constructor( onProgress(0.8) + val tags = async { tagsWriter.save(completeData.tags) } + val tagAssociations = async { tagAssociationWriter.save(completeData.tagAssociations) } + val plannedPayments = async { plannedPaymentRuleWriter.saveMany(completeData.plannedPaymentRules) } val settings = async { @@ -295,6 +310,8 @@ class BackupDataUseCase @Inject constructor( plannedPayments.await() settings.await() + tags.await() + tagAssociations.await() onProgress(0.9) } diff --git a/shared/data/core/src/main/java/com/ivy/data/backup/IvyWalletCompleteData.kt b/shared/data/core/src/main/java/com/ivy/data/backup/IvyWalletCompleteData.kt index f3cf3e359d..26f244dde8 100644 --- a/shared/data/core/src/main/java/com/ivy/data/backup/IvyWalletCompleteData.kt +++ b/shared/data/core/src/main/java/com/ivy/data/backup/IvyWalletCompleteData.kt @@ -8,12 +8,15 @@ import com.ivy.data.db.entity.LoanEntity import com.ivy.data.db.entity.LoanRecordEntity import com.ivy.data.db.entity.PlannedPaymentRuleEntity import com.ivy.data.db.entity.SettingsEntity +import com.ivy.data.db.entity.TagAssociationEntity +import com.ivy.data.db.entity.TagEntity import com.ivy.data.db.entity.TransactionEntity import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Keep @Serializable +@Suppress("DataClassDefaultValues") data class IvyWalletCompleteData( @SerialName("accounts") val accounts: List = emptyList(), @@ -32,5 +35,9 @@ data class IvyWalletCompleteData( @SerialName("transactions") val transactions: List = emptyList(), @SerialName("sharedPrefs") - val sharedPrefs: HashMap = HashMap() + val sharedPrefs: HashMap = HashMap(), + @SerialName("tags") + val tags: List = emptyList(), + @SerialName("tagAssociations") + val tagAssociations: List = emptyList() ) diff --git a/shared/data/core/src/test/java/com/ivy/data/backup/BackupDataUseCaseTest.kt b/shared/data/core/src/test/java/com/ivy/data/backup/BackupDataUseCaseTest.kt index f8d7dd5de9..bae69bb01c 100644 --- a/shared/data/core/src/test/java/com/ivy/data/backup/BackupDataUseCaseTest.kt +++ b/shared/data/core/src/test/java/com/ivy/data/backup/BackupDataUseCaseTest.kt @@ -10,6 +10,8 @@ import com.ivy.data.db.dao.fake.FakeLoanDao import com.ivy.data.db.dao.fake.FakeLoanRecordDao import com.ivy.data.db.dao.fake.FakePlannedPaymentDao import com.ivy.data.db.dao.fake.FakeSettingsDao +import com.ivy.data.db.dao.fake.FakeTagAssociationDao +import com.ivy.data.db.dao.fake.FakeTagDao import com.ivy.data.db.dao.fake.FakeTransactionDao import com.ivy.data.repository.AccountRepository import com.ivy.data.repository.CurrencyRepository @@ -32,6 +34,8 @@ class BackupDataUseCaseTest { settingsDao: FakeSettingsDao = FakeSettingsDao(), loanDao: FakeLoanDao = FakeLoanDao(), loanRecordDao: FakeLoanRecordDao = FakeLoanRecordDao(), + tagDao: FakeTagDao = FakeTagDao(), + tagAssociationDao: FakeTagAssociationDao = FakeTagAssociationDao() ): BackupDataUseCase { val accountMapper = AccountMapper( CurrencyRepository( @@ -71,6 +75,10 @@ class BackupDataUseCaseTest { dispatchersProvider = TestDispatchersProvider, fileSystem = mockk(relaxed = true), dataObserver = DataObserver(), + tagsReader = tagDao, + tagsWriter = tagDao, + tagAssociationReader = tagAssociationDao, + tagAssociationWriter = tagAssociationDao ) }