-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Merge multiple instances of same asset in one portfolio
- Loading branch information
Showing
5 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/dev/arkbuilders/rate/domain/usecase/AddNewAssetsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.arkbuilders.rate.domain.usecase | ||
|
||
import dev.arkbuilders.rate.domain.model.Asset | ||
import dev.arkbuilders.rate.domain.repo.PortfolioRepo | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class AddNewAssetsUseCase @Inject constructor( | ||
private val portfolioRepo: PortfolioRepo, | ||
) { | ||
suspend operator fun invoke(assets: List<Asset>) { | ||
val mergedAssets = | ||
assets.map { asset -> | ||
val roomAsset = | ||
portfolioRepo.getAllByCode(asset.code).find { | ||
it.group == asset.group | ||
} | ||
val mergedAsset = | ||
roomAsset?.let { | ||
roomAsset.copy(value = asset.value + roomAsset.value) | ||
} ?: asset | ||
mergedAsset | ||
} | ||
portfolioRepo.setAssetsList(mergedAssets) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters