Updated on 2026-08-14
This commit is contained in:
parent
69754e4159
commit
34cfc843ab
31 changed files with 322 additions and 170 deletions
|
|
@ -1,13 +1,24 @@
|
|||
package com.tangem.domain.promo
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import com.tangem.domain.promo.models.StoryContent
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEmpty
|
||||
|
||||
class GetStoryContentUseCase(
|
||||
private val promoRepository: PromoRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(id: String): Either<Throwable, StoryContent> = Either.catch {
|
||||
promoRepository.getStoryById(id)
|
||||
operator fun invoke(id: String): Flow<Either<Throwable, StoryContent?>> = promoRepository.getStoryById(id)
|
||||
.map<StoryContent?, Either<Throwable, StoryContent?>> { it.right() }
|
||||
.catch { emit(it.left()) }
|
||||
.onEmpty { emit(null.right()) }
|
||||
|
||||
suspend fun invokeSync(id: String): Either<Throwable, StoryContent?> = Either.catch {
|
||||
promoRepository.getStoryByIdSync(id)
|
||||
}
|
||||
}
|
||||
|
|
@ -16,12 +16,14 @@ interface PromoRepository {
|
|||
// endregion
|
||||
|
||||
// region Stories
|
||||
suspend fun getStoryById(id: String): StoryContent
|
||||
fun getStoryById(id: String): Flow<StoryContent?>
|
||||
|
||||
fun isReadyToShowSwapStories(): Flow<Boolean>
|
||||
suspend fun getStoryByIdSync(id: String): StoryContent?
|
||||
|
||||
suspend fun isReadyToShowSwapStoriesSync(): Boolean
|
||||
fun isReadyToShowStories(storyId: String): Flow<Boolean>
|
||||
|
||||
suspend fun setNeverToShowSwapStories()
|
||||
suspend fun isReadyToShowStoriesSync(storyId: String): Boolean
|
||||
|
||||
suspend fun setNeverToShowStories(storyId: String)
|
||||
// endregion
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.domain.promo
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class ShouldShowStoriesUseCase(private val promoRepository: PromoRepository) {
|
||||
operator fun invoke(storyId: String): Flow<Boolean> = promoRepository.isReadyToShowStories(storyId)
|
||||
suspend fun invokeSync(storyId: String): Boolean = promoRepository.isReadyToShowStoriesSync(storyId)
|
||||
|
||||
suspend fun neverToShow(storyId: String) = promoRepository.setNeverToShowStories(storyId)
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
package com.tangem.domain.promo
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
class ShouldShowSwapStoriesUseCase(private val promoRepository: PromoRepository) {
|
||||
operator fun invoke(): Flow<Boolean> = promoRepository.isReadyToShowSwapStories()
|
||||
suspend fun invokeSync(): Boolean = promoRepository.isReadyToShowSwapStoriesSync()
|
||||
|
||||
suspend fun neverToShow() = promoRepository.setNeverToShowSwapStories()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue