Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
[IVY-3445] Fix Tag Backup and Restore (#3450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwa-Raghavendra authored Aug 31, 2024
1 parent 0ca8c03 commit dc89aee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -295,6 +310,8 @@ class BackupDataUseCase @Inject constructor(

plannedPayments.await()
settings.await()
tags.await()
tagAssociations.await()

onProgress(0.9)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountEntity> = emptyList(),
Expand All @@ -32,5 +35,9 @@ data class IvyWalletCompleteData(
@SerialName("transactions")
val transactions: List<TransactionEntity> = emptyList(),
@SerialName("sharedPrefs")
val sharedPrefs: HashMap<String, String> = HashMap()
val sharedPrefs: HashMap<String, String> = HashMap(),
@SerialName("tags")
val tags: List<TagEntity> = emptyList(),
@SerialName("tagAssociations")
val tagAssociations: List<TagAssociationEntity> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -71,6 +75,10 @@ class BackupDataUseCaseTest {
dispatchersProvider = TestDispatchersProvider,
fileSystem = mockk(relaxed = true),
dataObserver = DataObserver(),
tagsReader = tagDao,
tagsWriter = tagDao,
tagAssociationReader = tagAssociationDao,
tagAssociationWriter = tagAssociationDao
)
}

Expand Down

0 comments on commit dc89aee

Please sign in to comment.