From 76051aa78d78667451ddbab50a0bc40310d17300 Mon Sep 17 00:00:00 2001 From: takahirom Date: Sat, 15 Jun 2024 18:10:25 +0900 Subject: [PATCH] Add empty eventmap module --- .../data/eventmap/EventMapApiModule.kt | 15 ++++++++ .../data/eventmap/EventMapRepositoryModule.kt | 34 ++++++++++++++++++ .../eventmap/DefaultEventMapRepository.kt | 36 +++++++++++++++++++ .../data/eventmap/EventMapApiClient.kt | 21 +++++++++++ .../data/eventmap/FakeEventMapApiClient.kt | 33 +++++++++++++++++ .../eventmap/response/EventMapResponse.kt | 3 ++ .../confsched/model/EventMapEvent.kt | 3 ++ .../confsched/model/EventMapRepository.kt | 18 ++++++++++ .../confsched/testing/MiniRobots.kt | 24 +++++++++++++ gradle.properties | 2 +- settings.gradle.kts | 1 + 11 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiModule.kt create mode 100644 core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapRepositoryModule.kt create mode 100644 core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/DefaultEventMapRepository.kt create mode 100644 core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiClient.kt create mode 100644 core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/FakeEventMapApiClient.kt create mode 100644 core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/response/EventMapResponse.kt create mode 100644 core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapEvent.kt create mode 100644 core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapRepository.kt diff --git a/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiModule.kt b/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiModule.kt new file mode 100644 index 000000000..77e6213f2 --- /dev/null +++ b/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiModule.kt @@ -0,0 +1,15 @@ +package io.github.droidkaigi.confsched.data.eventmap + +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent + +@Module +@InstallIn(SingletonComponent::class) +public class EventMapApiModule { + @Provides + public fun provideEventMapApi(): EventMapApiClient { + return FakeEventMapApiClient() + } +} diff --git a/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapRepositoryModule.kt b/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapRepositoryModule.kt new file mode 100644 index 000000000..97ffaa3a1 --- /dev/null +++ b/core/data/src/androidMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapRepositoryModule.kt @@ -0,0 +1,34 @@ +package io.github.droidkaigi.confsched.data.eventmap + +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap +import io.github.droidkaigi.confsched.data.di.RepositoryQualifier +import io.github.droidkaigi.confsched.model.EventMapRepository +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +public abstract class EventMapRepositoryModule { + @Binds + @RepositoryQualifier + @IntoMap + @ClassKey(EventMapRepository::class) + public abstract fun bind(repository: EventMapRepository): Any + + public companion object { + @Provides + @Singleton + public fun provideEventMapRepository( + eventMapApi: EventMapApiClient, + ): EventMapRepository { + return DefaultEventMapRepository( + eventMapApi = eventMapApi, + ) + } + } +} diff --git a/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/DefaultEventMapRepository.kt b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/DefaultEventMapRepository.kt new file mode 100644 index 000000000..f83847fe5 --- /dev/null +++ b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/DefaultEventMapRepository.kt @@ -0,0 +1,36 @@ +package io.github.droidkaigi.confsched.data.eventmap + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import io.github.droidkaigi.confsched.compose.SafeLaunchedEffect +import io.github.droidkaigi.confsched.compose.safeCollectAsState +import io.github.droidkaigi.confsched.model.EventMapEvent +import io.github.droidkaigi.confsched.model.EventMapRepository +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.flow.MutableStateFlow + +public class DefaultEventMapRepository( + private val eventMapApi: EventMapApiClient, +) : EventMapRepository { + private val eventMapStateFlow = + MutableStateFlow>(persistentListOf()) + + @Composable + override fun eventMapEvents(): PersistentList { + val eventMap by eventMapStateFlow.safeCollectAsState() + SafeLaunchedEffect(Unit) { + if (eventMap.isEmpty()) { + refresh() + } + } + return eventMap + } + + override suspend fun refresh() { + eventMapApi + .eventMapEvents() + .toPersistentList().also { eventMapStateFlow.value = it } + } +} diff --git a/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiClient.kt b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiClient.kt new file mode 100644 index 000000000..dee8bc5e2 --- /dev/null +++ b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/EventMapApiClient.kt @@ -0,0 +1,21 @@ +package io.github.droidkaigi.confsched.data.eventmap + +import de.jensklingenberg.ktorfit.http.GET +import io.github.droidkaigi.confsched.data.eventmap.response.EventMapResponse +import io.github.droidkaigi.confsched.model.EventMapEvent +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.toPersistentList + +internal interface EventMapApi { + @GET("/events/droidkaigi2023/eventmap") + suspend fun getEventMap(): EventMapResponse +} + +public interface EventMapApiClient { + + public suspend fun eventMapEvents(): PersistentList +} + +public fun EventMapResponse.toEventMapList(): PersistentList { + return listOf(EventMapEvent()).toPersistentList() +} diff --git a/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/FakeEventMapApiClient.kt b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/FakeEventMapApiClient.kt new file mode 100644 index 000000000..baa0036da --- /dev/null +++ b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/FakeEventMapApiClient.kt @@ -0,0 +1,33 @@ +package io.github.droidkaigi.confsched.data.eventmap + +import io.github.droidkaigi.confsched.data.eventmap.response.EventMapResponse +import io.github.droidkaigi.confsched.model.EventMapEvent +import kotlinx.collections.immutable.PersistentList +import okio.IOException + +public class FakeEventMapApiClient : EventMapApiClient { + + public sealed class Status : EventMapApiClient { + public data object Operational : Status() { + override suspend fun eventMapEvents(): PersistentList { + return EventMapResponse().toEventMapList() + } + } + + public data object Error : Status() { + override suspend fun eventMapEvents(): PersistentList { + throw IOException("Fake IO Exception") + } + } + } + + private var status: Status = Status.Operational + + public fun setup(status: Status) { + this.status = status + } + + override suspend fun eventMapEvents(): PersistentList { + return status.eventMapEvents() + } +} diff --git a/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/response/EventMapResponse.kt b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/response/EventMapResponse.kt new file mode 100644 index 000000000..b8047c5c7 --- /dev/null +++ b/core/data/src/commonMain/kotlin/io/github/droidkaigi/confsched/data/eventmap/response/EventMapResponse.kt @@ -0,0 +1,3 @@ +package io.github.droidkaigi.confsched.data.eventmap.response + +public class EventMapResponse diff --git a/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapEvent.kt b/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapEvent.kt new file mode 100644 index 000000000..82dcba0e7 --- /dev/null +++ b/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapEvent.kt @@ -0,0 +1,3 @@ +package io.github.droidkaigi.confsched.model + +class EventMapEvent diff --git a/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapRepository.kt b/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapRepository.kt new file mode 100644 index 000000000..f5f988d35 --- /dev/null +++ b/core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched/model/EventMapRepository.kt @@ -0,0 +1,18 @@ +package io.github.droidkaigi.confsched.model + +import androidx.compose.runtime.Composable +import io.github.droidkaigi.confsched.model.compositionlocal.LocalRepositories +import kotlinx.collections.immutable.PersistentList + +interface EventMapRepository { + + suspend fun refresh() + + @Composable + fun eventMapEvents(): PersistentList +} + +@Composable +fun localEventMapRepository(): EventMapRepository { + return LocalRepositories.current[EventMapRepository::class] as EventMapRepository +} diff --git a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/MiniRobots.kt b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/MiniRobots.kt index 059b985fd..f1919e237 100644 --- a/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/MiniRobots.kt +++ b/core/testing/src/main/java/io/github/droidkaigi/confsched/testing/MiniRobots.kt @@ -3,6 +3,8 @@ package io.github.droidkaigi.confsched.testing import androidx.compose.ui.test.junit4.ComposeTestRule import io.github.droidkaigi.confsched.data.contributors.ContributorsApiClient import io.github.droidkaigi.confsched.data.contributors.FakeContributorsApiClient +import io.github.droidkaigi.confsched.data.eventmap.EventMapApiClient +import io.github.droidkaigi.confsched.data.eventmap.FakeEventMapApiClient import io.github.droidkaigi.confsched.data.sessions.FakeSessionsApiClient import io.github.droidkaigi.confsched.data.sessions.SessionsApiClient import io.github.droidkaigi.confsched.testing.coroutines.runTestWithLogging @@ -136,3 +138,25 @@ class DefaultContributorsServerRobot @Inject constructor(contributorsApiClient: ) } } + +interface EventMapServerRobot { + enum class ServerStatus { + Operational, + Error, + } + + fun setupContributorServer(serverStatus: ServerStatus) +} + +class DefaultEventMapServerRobot @Inject constructor(contributorsApiClient: EventMapApiClient) : + EventMapServerRobot { + private val fakeEventMapApiClient = contributorsApiClient as FakeEventMapApiClient + override fun setupContributorServer(serverStatus: EventMapServerRobot.ServerStatus) { + fakeEventMapApiClient.setup( + when (serverStatus) { + EventMapServerRobot.ServerStatus.Operational -> FakeEventMapApiClient.Status.Operational + EventMapServerRobot.ServerStatus.Error -> FakeEventMapApiClient.Status.Error + }, + ) + } +} diff --git a/gradle.properties b/gradle.properties index c0adf3db9..6ced4ac6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ app.ios.shared.debug=true # gradle -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx6048m -Dfile.encoding=UTF-8 org.gradle.configureondemand=true org.gradle.caching=true org.gradle.parallel=true diff --git a/settings.gradle.kts b/settings.gradle.kts index ad3779140..b8c46244b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,6 +24,7 @@ include( ":feature:main", ":feature:sessions", ":feature:contributors", + ":feature:eventmap", ":core:designsystem", ":core:data", ":core:model",