From d53cd43fb6a73052bd4be9313b9d6a49c22278e6 Mon Sep 17 00:00:00 2001 From: Lasta apps Date: Thu, 4 Jul 2024 00:51:40 +0300 Subject: [PATCH] feat: Disable Strahov and Kocourkov menzas --- .../menza/api/agata/data/mapers/EntityToDomainMapper.kt | 1 + .../lastaapps/menza/api/agata/data/repo/MenzaRepoImpl.kt | 1 + .../cz/lastaapps/api/buffet/data/repo/MenzaRepoImpl.kt | 2 ++ .../kotlin/cz/lastaapps/api/core/domain/model/Menza.kt | 1 + .../cz/lastaapps/api/main/data/KocourkovRepoImpl.kt | 6 +++++- .../kotlin/cz/lastaapps/api/main/di/ApiModule.kt | 2 +- .../lastaapps/api/main/domain/usecase/GetMenzaListUC.kt | 8 ++++---- .../features/settings/ui/screens/ReorderMenzaScreen.kt | 2 ++ 8 files changed, 17 insertions(+), 6 deletions(-) diff --git a/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/mapers/EntityToDomainMapper.kt b/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/mapers/EntityToDomainMapper.kt index a0c6a06e..e5cf90a7 100644 --- a/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/mapers/EntityToDomainMapper.kt +++ b/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/mapers/EntityToDomainMapper.kt @@ -61,6 +61,7 @@ private fun SubsystemEntity.toDomain() = Menza( Subsystem(id.toInt()), name, + true, opened, supportsDaily, supportsWeekly, diff --git a/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/repo/MenzaRepoImpl.kt b/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/repo/MenzaRepoImpl.kt index 0a30b02a..035a0f2a 100644 --- a/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/repo/MenzaRepoImpl.kt +++ b/api/agata/src/commonMain/kotlin/cz/lastaapps/menza/api/agata/data/repo/MenzaRepoImpl.kt @@ -144,6 +144,7 @@ internal object MenzaStrahovRepoImpl : MenzaRepo { Menza( type = Strahov, name = getName(params), + isActive = false, isOpened = true, supportsDaily = true, supportsWeekly = false, diff --git a/api/buffet/src/commonMain/kotlin/cz/lastaapps/api/buffet/data/repo/MenzaRepoImpl.kt b/api/buffet/src/commonMain/kotlin/cz/lastaapps/api/buffet/data/repo/MenzaRepoImpl.kt index a8b12a71..47fa04b8 100644 --- a/api/buffet/src/commonMain/kotlin/cz/lastaapps/api/buffet/data/repo/MenzaRepoImpl.kt +++ b/api/buffet/src/commonMain/kotlin/cz/lastaapps/api/buffet/data/repo/MenzaRepoImpl.kt @@ -50,6 +50,7 @@ internal object MenzaFSRepoImpl : MenzaRepo { Menza( type = FS, name = "Bufet FS", + isActive = true, isOpened = true, supportsDaily = true, supportsWeekly = true, @@ -80,6 +81,7 @@ internal object MenzaFELRepoImpl : MenzaRepo { Menza( type = FEL, name = "Bufet FEL", + isActive = true, isOpened = true, supportsDaily = true, supportsWeekly = true, diff --git a/api/core/src/commonMain/kotlin/cz/lastaapps/api/core/domain/model/Menza.kt b/api/core/src/commonMain/kotlin/cz/lastaapps/api/core/domain/model/Menza.kt index 844240bd..df02bc12 100644 --- a/api/core/src/commonMain/kotlin/cz/lastaapps/api/core/domain/model/Menza.kt +++ b/api/core/src/commonMain/kotlin/cz/lastaapps/api/core/domain/model/Menza.kt @@ -24,6 +24,7 @@ import kotlinx.collections.immutable.ImmutableList data class Menza( val type: MenzaType, val name: String, + val isActive: Boolean, val isOpened: Boolean, val supportsDaily: Boolean, val supportsWeekly: Boolean, diff --git a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/data/KocourkovRepoImpl.kt b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/data/KocourkovRepoImpl.kt index 7e919d7f..d99bf6df 100644 --- a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/data/KocourkovRepoImpl.kt +++ b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/data/KocourkovRepoImpl.kt @@ -38,6 +38,7 @@ import cz.lastaapps.api.core.domain.repo.WeekRepoParams import cz.lastaapps.api.core.domain.sync.SyncOutcome import cz.lastaapps.api.core.domain.sync.SyncResult import cz.lastaapps.api.core.domain.sync.SyncResult.Unavailable +import cz.lastaapps.core.data.AppInfoProvider import cz.lastaapps.core.util.extensions.localLogger import kotlin.random.Random import kotlin.random.nextInt @@ -53,7 +54,9 @@ import kotlinx.coroutines.flow.onCompletion import kotlinx.coroutines.flow.onStart import org.koin.core.component.KoinComponent -internal class KocourkovRepoImpl : MenzaRepo { +internal class KocourkovRepoImpl( + private val appInfoProvider: AppInfoProvider, +) : MenzaRepo { override fun isReady(params: MenzaRepoParams): Flow = flow { emit(true) } @@ -64,6 +67,7 @@ internal class KocourkovRepoImpl : MenzaRepo { Menza( MenzaType.Testing.Kocourkov, name = "Kocourkov", + isActive = appInfoProvider.isDebug(), isOpened = true, supportsDaily = true, supportsWeekly = false, diff --git a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/di/ApiModule.kt b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/di/ApiModule.kt index 5127053a..65ae094b 100644 --- a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/di/ApiModule.kt +++ b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/di/ApiModule.kt @@ -82,7 +82,7 @@ val apiModule = module { factoryOf(::GetImportantRequestParams) registerMenzaType( - menzaRepo = { KocourkovRepoImpl() }, + menzaRepo = { KocourkovRepoImpl(get()) }, dishRepo = { TodayKocourkovDishRepoImpl }, infoRepo = { InfoKocourkovRepoImpl }, weekRepo = { WeekKocourkovRepoImpl }, diff --git a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/domain/usecase/GetMenzaListUC.kt b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/domain/usecase/GetMenzaListUC.kt index 41cf336b..ad78cdd6 100644 --- a/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/domain/usecase/GetMenzaListUC.kt +++ b/api/main/src/commonMain/kotlin/cz/lastaapps/api/main/domain/usecase/GetMenzaListUC.kt @@ -19,13 +19,12 @@ package cz.lastaapps.api.main.domain.usecase -import cz.lastaapps.api.core.domain.sync.getData -import cz.lastaapps.api.core.domain.sync.sync +import cz.lastaapps.api.core.domain.model.Menza import cz.lastaapps.api.core.domain.repo.MenzaRepo +import cz.lastaapps.api.core.domain.sync.getData import cz.lastaapps.core.domain.UCContext import cz.lastaapps.core.domain.UseCase -import kotlinx.coroutines.flow.onCompletion -import kotlinx.coroutines.flow.onStart +import kotlinx.coroutines.flow.map class GetMenzaListUC( context: UCContext, @@ -33,4 +32,5 @@ class GetMenzaListUC( private val getRequestParamsUC: GetRequestParamsUC, ) : UseCase(context) { operator fun invoke() = menzaRepo.getData(getRequestParamsUC()) + .map { it.filter(Menza::isActive) } } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/features/settings/ui/screens/ReorderMenzaScreen.kt b/app/src/main/kotlin/cz/lastaapps/menza/features/settings/ui/screens/ReorderMenzaScreen.kt index 62befd27..ba930f17 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/features/settings/ui/screens/ReorderMenzaScreen.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/features/settings/ui/screens/ReorderMenzaScreen.kt @@ -243,6 +243,7 @@ private fun MenzaItemPreview() { menza = Menza( Strahov, "Menza Strahov", + isActive = true, isOpened = true, supportsDaily = true, supportsWeekly = true, @@ -255,6 +256,7 @@ private fun MenzaItemPreview() { menza = Menza( Strahov, "Restaurace Strahov", + isActive = true, isOpened = true, supportsDaily = true, supportsWeekly = true,