diff --git a/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/CommonServiceModule.kt b/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/CommonServiceModule.kt index 6c41dd18..6adf5808 100644 --- a/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/CommonServiceModule.kt +++ b/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/CommonServiceModule.kt @@ -8,6 +8,7 @@ import com.gchristov.thecodinglove.commonservice.pubsub.GoogleCloudPubSubSubscri import com.gchristov.thecodinglove.commonservicedata.http.HttpService import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubPublisher import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription +import com.gchristov.thecodinglove.kmpcommonkotlin.AppConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import org.kodein.di.DI import org.kodein.di.bindProvider @@ -26,6 +27,7 @@ object CommonServiceModule : DiModule() { providePubSubSubscription( log = instance(), pubSub = instance(), + appConfig = instance(), ) } } @@ -42,8 +44,10 @@ object CommonServiceModule : DiModule() { private fun providePubSubSubscription( log: Logger, pubSub: GoogleCloudPubSubExternals.PubSub, + appConfig: AppConfig, ): PubSubSubscription = GoogleCloudPubSubSubscription( log = log, pubSub = pubSub, + appConfig = appConfig, ) } \ No newline at end of file diff --git a/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/pubsub/GoogleCloudPubSubSubscription.kt b/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/pubsub/GoogleCloudPubSubSubscription.kt index 6be056d6..ffb0e8ce 100644 --- a/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/pubsub/GoogleCloudPubSubSubscription.kt +++ b/backend/common-service/src/jsMain/kotlin/com/gchristov/thecodinglove/commonservice/pubsub/GoogleCloudPubSubSubscription.kt @@ -3,6 +3,7 @@ package com.gchristov.thecodinglove.commonservice.pubsub import arrow.core.Either import co.touchlab.kermit.Logger import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription +import com.gchristov.thecodinglove.kmpcommonkotlin.AppConfig import com.gchristov.thecodinglove.kmpcommonkotlin.process import kotlinx.coroutines.await import kotlin.js.json @@ -10,6 +11,7 @@ import kotlin.js.json internal class GoogleCloudPubSubSubscription( private val log: Logger, private val pubSub: GoogleCloudPubSubExternals.PubSub, + private val appConfig: AppConfig, ) : PubSubSubscription { init { process.env.GOOGLE_APPLICATION_CREDENTIALS = "local-credentials-pubsub.json" @@ -28,9 +30,11 @@ internal class GoogleCloudPubSubSubscription( val pubSubSubscription = pubSubTopic.subscription(subscription) if (!pubSubSubscription.exists().await().first()) { log.d("Creating PubSub subscription $subscription") + val trimmedDomain = appConfig.publicUrl + val trimmedPath = httpPath.removePrefix("/") pubSubSubscription.create( // TODO: Fix this to use a env variable for the website - json("pushEndpoint" to "https://cloudrun-test-oe6rkpnjrq-uw.a.run.app/$httpPath") + json("pushEndpoint" to "$trimmedDomain/$trimmedPath") ).await() } Either.Right(Unit) diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchDataModule.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchDataModule.kt index e72c8989..2cbce4d7 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchDataModule.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchDataModule.kt @@ -3,9 +3,10 @@ package com.gchristov.thecodinglove.searchdata import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubPublisher import com.gchristov.thecodinglove.htmlparsedata.usecase.ParseHtmlPostsUseCase import com.gchristov.thecodinglove.htmlparsedata.usecase.ParseHtmlTotalPostsUseCase +import com.gchristov.thecodinglove.kmpcommonkotlin.BuildConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import com.gchristov.thecodinglove.kmpcommonnetwork.HtmlClient -import com.gchristov.thecodinglove.searchdata.model.SearchConfig +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig import com.gchristov.thecodinglove.searchdata.usecase.* import dev.gitlive.firebase.firestore.FirebaseFirestore import kotlinx.coroutines.Dispatchers @@ -42,6 +43,7 @@ object SearchDataModule : DiModule() { searchWithHistoryUseCase = instance(), pubSubPublisher = instance(), jsonSerializer = instance(), + searchConfig = instance(), ) } bindProvider { @@ -67,7 +69,10 @@ object SearchDataModule : DiModule() { firebaseFirestore = firebaseFirestore ) - private fun provideSearchConfig(): SearchConfig = SearchConfig(postsPerPage = 4) + private fun provideSearchConfig(): SearchConfig = SearchConfig( + postsPerPage = 4, + preloadPubSubTopic = BuildConfig.SEARCH_PRELOAD_PUBSUB_TOPIC, + ) private fun provideSearchWithHistoryUseCase( searchRepository: SearchRepository, @@ -83,12 +88,14 @@ object SearchDataModule : DiModule() { searchWithHistoryUseCase: SearchWithHistoryUseCase, pubSubPublisher: PubSubPublisher, jsonSerializer: Json, + searchConfig: SearchConfig, ): SearchUseCase = RealSearchUseCase( dispatcher = Dispatchers.Default, searchRepository = searchRepository, searchWithHistoryUseCase = searchWithHistoryUseCase, pubSubPublisher = pubSubPublisher, jsonSerializer = jsonSerializer, + searchConfig = searchConfig, ) private fun providePreloadSearchResultUseCase( diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchRepository.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchRepository.kt index d42b4b85..c1ac4dcf 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchRepository.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/SearchRepository.kt @@ -5,7 +5,7 @@ import com.gchristov.thecodinglove.htmlparsedata.usecase.ParseHtmlPostsUseCase import com.gchristov.thecodinglove.htmlparsedata.usecase.ParseHtmlTotalPostsUseCase import com.gchristov.thecodinglove.searchdata.db.DbSearchSession import com.gchristov.thecodinglove.searchdata.db.toSearchSession -import com.gchristov.thecodinglove.searchdata.model.* +import com.gchristov.thecodinglove.searchdata.domain.* import dev.gitlive.firebase.firestore.FirebaseFirestore import io.ktor.client.statement.* diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/api/ApiPost.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/api/ApiPost.kt index 19173011..1f510f89 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/api/ApiPost.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/api/ApiPost.kt @@ -1,6 +1,6 @@ package com.gchristov.thecodinglove.searchdata.api -import com.gchristov.thecodinglove.searchdata.model.Post +import com.gchristov.thecodinglove.searchdata.domain.Post import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbPost.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbPost.kt index 4c0ee3dc..22b4807e 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbPost.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbPost.kt @@ -1,6 +1,6 @@ package com.gchristov.thecodinglove.searchdata.db -import com.gchristov.thecodinglove.searchdata.model.Post +import com.gchristov.thecodinglove.searchdata.domain.Post import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbSearchSession.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbSearchSession.kt index f006d284..3f2c7390 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbSearchSession.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/db/DbSearchSession.kt @@ -2,7 +2,7 @@ package com.gchristov.thecodinglove.searchdata.db import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiGraph import com.gchristov.thecodinglove.kmpcommonkotlin.di.inject -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.SearchSession import kotlinx.serialization.* import kotlinx.serialization.descriptors.PrimitiveKind import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/Post.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/Post.kt similarity index 88% rename from backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/Post.kt rename to backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/Post.kt index f6752bae..bf6ed48e 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/Post.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/Post.kt @@ -1,4 +1,4 @@ -package com.gchristov.thecodinglove.searchdata.model +package com.gchristov.thecodinglove.searchdata.domain import com.gchristov.thecodinglove.htmlparsedata.HtmlPost import com.gchristov.thecodinglove.searchdata.db.DbPost diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/PreloadSearchPubSubMessage.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/PreloadSearchPubSubMessage.kt similarity index 54% rename from backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/PreloadSearchPubSubMessage.kt rename to backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/PreloadSearchPubSubMessage.kt index 3a517c97..0c2f4056 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/PreloadSearchPubSubMessage.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/PreloadSearchPubSubMessage.kt @@ -1,10 +1,8 @@ -package com.gchristov.thecodinglove.searchdata.model +package com.gchristov.thecodinglove.searchdata.domain import kotlinx.serialization.Serializable @Serializable data class PreloadSearchPubSubMessage( val searchSessionId: String -) - -const val PreloadSearchPubSubTopic = "preload_search" \ No newline at end of file +) \ No newline at end of file diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchConfig.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchConfig.kt new file mode 100644 index 00000000..7614908f --- /dev/null +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchConfig.kt @@ -0,0 +1,6 @@ +package com.gchristov.thecodinglove.searchdata.domain + +data class SearchConfig( + val postsPerPage: Int, + val preloadPubSubTopic: String, +) \ No newline at end of file diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchError.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchError.kt similarity index 81% rename from backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchError.kt rename to backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchError.kt index 2d6bf167..47c0db5a 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchError.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchError.kt @@ -1,4 +1,4 @@ -package com.gchristov.thecodinglove.searchdata.model +package com.gchristov.thecodinglove.searchdata.domain sealed class SearchError(error: String? = null) : Throwable(error) { object Empty : SearchError("No results found") diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchSession.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchSession.kt similarity index 95% rename from backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchSession.kt rename to backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchSession.kt index 293d8eb3..237b3f48 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchSession.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/domain/SearchSession.kt @@ -1,4 +1,4 @@ -package com.gchristov.thecodinglove.searchdata.model +package com.gchristov.thecodinglove.searchdata.domain import com.gchristov.thecodinglove.searchdata.db.DbSearchSession diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchConfig.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchConfig.kt deleted file mode 100644 index bfa02c83..00000000 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/model/SearchConfig.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.gchristov.thecodinglove.searchdata.model - -data class SearchConfig( - val postsPerPage: Int -) \ No newline at end of file diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/PreloadSearchResultUseCase.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/PreloadSearchResultUseCase.kt index f28fca38..74f2e3f7 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/PreloadSearchResultUseCase.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/PreloadSearchResultUseCase.kt @@ -3,8 +3,8 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either import arrow.core.flatMap import com.gchristov.thecodinglove.searchdata.SearchRepository -import com.gchristov.thecodinglove.searchdata.model.SearchError -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchSession import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/Random.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/Random.kt index d2ca768e..6a5884d2 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/Random.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/Random.kt @@ -1,7 +1,7 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either -import com.gchristov.thecodinglove.searchdata.model.Post +import com.gchristov.thecodinglove.searchdata.domain.Post import kotlin.math.max import kotlin.random.Random diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchUseCase.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchUseCase.kt index f772aacb..d2e0e64a 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchUseCase.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchUseCase.kt @@ -5,7 +5,7 @@ import arrow.core.flatMap import com.benasher44.uuid.uuid4 import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubPublisher import com.gchristov.thecodinglove.searchdata.SearchRepository -import com.gchristov.thecodinglove.searchdata.model.* +import com.gchristov.thecodinglove.searchdata.domain.* import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json @@ -32,16 +32,19 @@ class RealSearchUseCase( private val searchWithHistoryUseCase: SearchWithHistoryUseCase, private val pubSubPublisher: PubSubPublisher, private val jsonSerializer: Json, + private val searchConfig: SearchConfig, ) : SearchUseCase { override suspend operator fun invoke( type: SearchUseCase.Type ): Either = withContext(dispatcher) { search(type) .flatMap { searchResult -> - publishSearchPreloadMessage(searchResult.searchSessionId) - .flatMap { - Either.Right(searchResult) - } + publishSearchPreloadMessage( + searchSessionId = searchResult.searchSessionId, + searchConfig = searchConfig, + ).flatMap { + Either.Right(searchResult) + } } } @@ -106,9 +109,12 @@ class RealSearchUseCase( } } - private suspend fun publishSearchPreloadMessage(searchSessionId: String) = pubSubPublisher + private suspend fun publishSearchPreloadMessage( + searchSessionId: String, + searchConfig: SearchConfig, + ) = pubSubPublisher .publishJson( - topic = PreloadSearchPubSubTopic, + topic = searchConfig.preloadPubSubTopic, body = PreloadSearchPubSubMessage(searchSessionId), jsonSerializer = jsonSerializer, strategy = PreloadSearchPubSubMessage.serializer(), diff --git a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchWithHistoryUseCase.kt b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchWithHistoryUseCase.kt index ad6563bd..c9bff0d2 100644 --- a/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchWithHistoryUseCase.kt +++ b/backend/search-data/src/jsMain/kotlin/com/gchristov/thecodinglove/searchdata/usecase/SearchWithHistoryUseCase.kt @@ -3,9 +3,9 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either import arrow.core.flatMap import com.gchristov.thecodinglove.searchdata.SearchRepository -import com.gchristov.thecodinglove.searchdata.model.Post -import com.gchristov.thecodinglove.searchdata.model.SearchConfig -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.Post +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig +import com.gchristov.thecodinglove.searchdata.domain.SearchError import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext import kotlin.random.Random diff --git a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealPreloadSearchResultUseCaseTest.kt b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealPreloadSearchResultUseCaseTest.kt index c01efe83..003a838e 100644 --- a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealPreloadSearchResultUseCaseTest.kt +++ b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealPreloadSearchResultUseCaseTest.kt @@ -2,8 +2,8 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeCoroutineDispatcher -import com.gchristov.thecodinglove.searchdata.model.SearchError -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchSession import com.gchristov.thecodinglove.searchtestfixtures.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestResult diff --git a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchUseCaseTest.kt b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchUseCaseTest.kt index ca127b04..743282a7 100644 --- a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchUseCaseTest.kt +++ b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchUseCaseTest.kt @@ -3,10 +3,10 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either import com.gchristov.thecodinglove.commonservicetestfixtures.FakePubSubPublisher import com.gchristov.thecodinglove.kmpcommontest.FakeCoroutineDispatcher -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubMessage -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubTopic -import com.gchristov.thecodinglove.searchdata.model.SearchError -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.PreloadSearchPubSubMessage +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig +import com.gchristov.thecodinglove.searchdata.domain.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchSession import com.gchristov.thecodinglove.searchtestfixtures.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestResult @@ -98,7 +98,7 @@ class RealSearchUseCaseTest { actual = actualResult ) pubSub.assertEquals( - topic = PreloadSearchPubSubTopic, + topic = TestPreloadSearchPubSubTopic, message = PreloadSearchPubSubMessage(TestSearchSessionId), ) } @@ -195,7 +195,7 @@ class RealSearchUseCaseTest { ) ) pubSub.assertEquals( - topic = PreloadSearchPubSubTopic, + topic = TestPreloadSearchPubSubTopic, message = PreloadSearchPubSubMessage(TestSearchSessionId), ) } @@ -221,10 +221,16 @@ class RealSearchUseCaseTest { searchWithHistoryUseCase = searchWithHistoryUseCase, jsonSerializer = Json, pubSubPublisher = pubSubPublisher, + searchConfig = SearchConfig( + postsPerPage = TestSearchPostsPerPage, + preloadPubSubTopic = TestPreloadSearchPubSubTopic, + ) ) testBlock(useCase, pubSubPublisher, searchRepository, searchWithHistoryUseCase) } } private const val TestSearchQuery = "test" -private const val TestSearchSessionId = "session_123" \ No newline at end of file +private const val TestSearchSessionId = "session_123" +private const val TestSearchPostsPerPage = 4 +private const val TestPreloadSearchPubSubTopic = "topic_123" \ No newline at end of file diff --git a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchWithHistoryUseCaseTest.kt b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchWithHistoryUseCaseTest.kt index 106a6f5d..89797c37 100644 --- a/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchWithHistoryUseCaseTest.kt +++ b/backend/search-data/src/jsTest/kotlin/com/gchristov/thecodinglove/searchdata/usecase/RealSearchWithHistoryUseCaseTest.kt @@ -2,9 +2,9 @@ package com.gchristov.thecodinglove.searchdata.usecase import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeCoroutineDispatcher -import com.gchristov.thecodinglove.searchdata.model.Post -import com.gchristov.thecodinglove.searchdata.model.SearchConfig -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.Post +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchtestfixtures.FakeSearchRepository import com.gchristov.thecodinglove.searchtestfixtures.PostCreator import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -185,6 +185,8 @@ class RealSearchWithHistoryUseCaseTest { } private const val TestSearchQuery = "test" +private const val TestSearchPreloadPubSubTopic = "topic_123" private val TestSearchConfig = SearchConfig( - postsPerPage = PostCreator.multiPageMultiPostPageSize() + postsPerPage = PostCreator.multiPageMultiPostPageSize(), + preloadPubSubTopic = TestSearchPreloadPubSubTopic, ) \ No newline at end of file diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakePreloadSearchResultUseCase.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakePreloadSearchResultUseCase.kt index bc947de7..0d00965d 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakePreloadSearchResultUseCase.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakePreloadSearchResultUseCase.kt @@ -3,7 +3,7 @@ package com.gchristov.thecodinglove.searchtestfixtures import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeResponse import com.gchristov.thecodinglove.kmpcommontest.execute -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchdata.usecase.PreloadSearchResultUseCase import kotlin.test.assertEquals diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchRepository.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchRepository.kt index 333df1be..414144d9 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchRepository.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchRepository.kt @@ -4,9 +4,9 @@ import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeResponse import com.gchristov.thecodinglove.kmpcommontest.execute import com.gchristov.thecodinglove.searchdata.SearchRepository -import com.gchristov.thecodinglove.searchdata.model.Post -import com.gchristov.thecodinglove.searchdata.model.SearchError -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.Post +import com.gchristov.thecodinglove.searchdata.domain.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchSession import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchUseCase.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchUseCase.kt index c30adb86..e546dd13 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchUseCase.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchUseCase.kt @@ -3,7 +3,7 @@ package com.gchristov.thecodinglove.searchtestfixtures import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeResponse import com.gchristov.thecodinglove.kmpcommontest.execute -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchdata.usecase.SearchUseCase import kotlin.test.assertEquals diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchWithHistoryUseCase.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchWithHistoryUseCase.kt index 2363ffcf..0c88fca1 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchWithHistoryUseCase.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/FakeSearchWithHistoryUseCase.kt @@ -3,7 +3,7 @@ package com.gchristov.thecodinglove.searchtestfixtures import arrow.core.Either import com.gchristov.thecodinglove.kmpcommontest.FakeResponse import com.gchristov.thecodinglove.kmpcommontest.execute -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchdata.usecase.SearchWithHistoryUseCase import kotlin.test.assertEquals diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PostCreator.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PostCreator.kt index fc9b308a..f606f373 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PostCreator.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PostCreator.kt @@ -1,6 +1,6 @@ package com.gchristov.thecodinglove.searchtestfixtures -import com.gchristov.thecodinglove.searchdata.model.Post +import com.gchristov.thecodinglove.searchdata.domain.Post object PostCreator { fun multiPageMultiPostPageSize() = 4 diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PreloadSearchPubSubCreator.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PreloadSearchPubSubCreator.kt index 118f0bf5..5afa8ae7 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PreloadSearchPubSubCreator.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/PreloadSearchPubSubCreator.kt @@ -1,6 +1,6 @@ package com.gchristov.thecodinglove.searchtestfixtures -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubMessage +import com.gchristov.thecodinglove.searchdata.domain.PreloadSearchPubSubMessage object PreloadSearchPubSubCreator { fun defaultMessage() = PreloadSearchPubSubMessage( diff --git a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/SearchSessionCreator.kt b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/SearchSessionCreator.kt index 0ac0f903..f5ce9ba7 100644 --- a/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/SearchSessionCreator.kt +++ b/backend/search-testfixtures/src/jsMain/kotlin/com/gchristov/thecodinglove/searchtestfixtures/SearchSessionCreator.kt @@ -1,7 +1,7 @@ package com.gchristov.thecodinglove.searchtestfixtures -import com.gchristov.thecodinglove.searchdata.model.Post -import com.gchristov.thecodinglove.searchdata.model.SearchSession +import com.gchristov.thecodinglove.searchdata.domain.Post +import com.gchristov.thecodinglove.searchdata.domain.SearchSession object SearchSessionCreator { fun searchSession( diff --git a/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHandler.kt b/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHandler.kt index 58de3756..c8b22677 100644 --- a/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHandler.kt +++ b/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHandler.kt @@ -9,8 +9,8 @@ import com.gchristov.thecodinglove.commonservicedata.http.HttpHandler import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubHandler import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubRequest import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubMessage -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubTopic +import com.gchristov.thecodinglove.searchdata.domain.PreloadSearchPubSubMessage +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig import com.gchristov.thecodinglove.searchdata.usecase.PreloadSearchResultUseCase import io.ktor.http.* import kotlinx.coroutines.CoroutineDispatcher @@ -22,6 +22,7 @@ class PreloadSearchPubSubHandler( log: Logger, private val preloadSearchResultUseCase: PreloadSearchResultUseCase, pubSubSubscription: PubSubSubscription, + private val searchConfig: SearchConfig, ) : BasePubSubHandler( dispatcher = dispatcher, jsonSerializer = jsonSerializer, @@ -35,7 +36,7 @@ class PreloadSearchPubSubHandler( ) override fun pubSubConfig() = PubSubHandler.PubSubConfig( - topic = PreloadSearchPubSubTopic, + topic = searchConfig.preloadPubSubTopic, ) override suspend fun handlePubSubRequest(request: PubSubRequest): Either = diff --git a/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/SearchModule.kt b/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/SearchModule.kt index 89b6b84e..25be073d 100644 --- a/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/SearchModule.kt +++ b/backend/search/src/jsMain/kotlin/com/gchristov/thecodinglove/search/SearchModule.kt @@ -3,6 +3,7 @@ package com.gchristov.thecodinglove.search import co.touchlab.kermit.Logger import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig import com.gchristov.thecodinglove.searchdata.usecase.PreloadSearchResultUseCase import com.gchristov.thecodinglove.searchdata.usecase.SearchUseCase import kotlinx.coroutines.Dispatchers @@ -29,6 +30,7 @@ object SearchModule : DiModule() { log = instance(), preloadSearchResultUseCase = instance(), pubSubSubscription = instance(), + searchConfig = instance(), ) } } @@ -50,11 +52,13 @@ object SearchModule : DiModule() { log: Logger, preloadSearchResultUseCase: PreloadSearchResultUseCase, pubSubSubscription: PubSubSubscription, + searchConfig: SearchConfig, ): PreloadSearchPubSubHandler = PreloadSearchPubSubHandler( dispatcher = Dispatchers.Default, jsonSerializer = jsonSerializer, log = log, preloadSearchResultUseCase = preloadSearchResultUseCase, pubSubSubscription = pubSubSubscription, + searchConfig = searchConfig, ) } \ No newline at end of file diff --git a/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHttpHandlerTest.kt b/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHttpHandlerTest.kt index fa4fe09d..58b0bb85 100644 --- a/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHttpHandlerTest.kt +++ b/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/PreloadSearchPubSubHttpHandlerTest.kt @@ -5,9 +5,9 @@ import com.gchristov.thecodinglove.commonservicetestfixtures.FakePubSubRequest import com.gchristov.thecodinglove.commonservicetestfixtures.FakePubSubSubscription import com.gchristov.thecodinglove.kmpcommontest.FakeCoroutineDispatcher import com.gchristov.thecodinglove.kmpcommontest.FakeLogger -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubMessage -import com.gchristov.thecodinglove.searchdata.model.PreloadSearchPubSubTopic -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.PreloadSearchPubSubMessage +import com.gchristov.thecodinglove.searchdata.domain.SearchConfig +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchtestfixtures.FakePreloadSearchResultUseCase import com.gchristov.thecodinglove.searchtestfixtures.PreloadSearchPubSubCreator import io.ktor.http.* @@ -38,7 +38,7 @@ class PreloadSearchPubSubHttpHandlerTest { preloadSearchResultInvocationResult = Either.Left(SearchError.Empty), ) { handler, _, _ -> val config = handler.pubSubConfig() - assertEquals(PreloadSearchPubSubTopic, config.topic) + assertEquals(TestPreloadSearchPubSubTopic, config.topic) } @Test @@ -94,7 +94,14 @@ class PreloadSearchPubSubHttpHandlerTest { log = FakeLogger, preloadSearchResultUseCase = preloadSearchResultUseCase, pubSubSubscription = FakePubSubSubscription(), + searchConfig = SearchConfig( + postsPerPage = TestSearchPostsPerPage, + preloadPubSubTopic = TestPreloadSearchPubSubTopic, + ), ) testBlock(handler, preloadSearchResultUseCase, request) } -} \ No newline at end of file +} + +private const val TestSearchPostsPerPage = 4 +private const val TestPreloadSearchPubSubTopic = "topic_123" \ No newline at end of file diff --git a/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/SearchHttpHandlerTest.kt b/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/SearchHttpHandlerTest.kt index 87cab809..a8701201 100644 --- a/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/SearchHttpHandlerTest.kt +++ b/backend/search/src/jsTest/kotlin/com/gchristov/thecodinglove/search/SearchHttpHandlerTest.kt @@ -4,7 +4,7 @@ import arrow.core.Either import com.gchristov.thecodinglove.commonservicetestfixtures.FakeHttpResponse import com.gchristov.thecodinglove.kmpcommontest.FakeCoroutineDispatcher import com.gchristov.thecodinglove.kmpcommontest.FakeLogger -import com.gchristov.thecodinglove.searchdata.model.SearchError +import com.gchristov.thecodinglove.searchdata.domain.SearchError import com.gchristov.thecodinglove.searchdata.usecase.SearchUseCase import com.gchristov.thecodinglove.searchtestfixtures.FakeSearchHttpRequest import com.gchristov.thecodinglove.searchtestfixtures.FakeSearchUseCase diff --git a/backend/slack-data/build.gradle.kts b/backend/slack-data/build.gradle.kts index 2077b001..587130d7 100644 --- a/backend/slack-data/build.gradle.kts +++ b/backend/slack-data/build.gradle.kts @@ -1,10 +1,5 @@ -import com.gchristov.thecodinglove.gradleplugins.getLocalSecret - -val packageId = "com.gchristov.thecodinglove.slackdata" - plugins { id("kmp-data-plugin") - id("build-config-plugin") } kotlin { @@ -21,30 +16,4 @@ kotlin { } } } -} - -buildkonfig { - packageName = packageId - defaultConfigs { - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "SLACK_SIGNING_SECRET", - value = getLocalSecret(rootProject, "SLACK_SIGNING_SECRET") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN, - name = "SLACK_REQUEST_VERIFICATION_ENABLED", - value = getLocalSecret(rootProject, "SLACK_REQUEST_VERIFICATION_ENABLED") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "SLACK_CLIENT_ID", - value = getLocalSecret(rootProject, "SLACK_CLIENT_ID") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "SLACK_CLIENT_SECRET", - value = getLocalSecret(rootProject, "SLACK_CLIENT_SECRET") - ) - } } \ No newline at end of file diff --git a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/SlackDataModule.kt b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/SlackDataModule.kt index 99a2156e..bf122b9f 100644 --- a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/SlackDataModule.kt +++ b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/SlackDataModule.kt @@ -1,6 +1,7 @@ package com.gchristov.thecodinglove.slackdata import co.touchlab.kermit.Logger +import com.gchristov.thecodinglove.kmpcommonkotlin.BuildConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import com.gchristov.thecodinglove.kmpcommonnetwork.JsonClient import com.gchristov.thecodinglove.searchdata.SearchRepository @@ -77,11 +78,13 @@ object SlackDataModule : DiModule() { private fun provideSlackApi(client: JsonClient) = SlackApi(client) private fun provideSlackConfig(): SlackConfig = SlackConfig( - signingSecret = BuildKonfig.SLACK_SIGNING_SECRET, + signingSecret = BuildConfig.SLACK_SIGNING_SECRET, timestampValidityMinutes = 5, - requestVerificationEnabled = BuildKonfig.SLACK_REQUEST_VERIFICATION_ENABLED, - clientId = BuildKonfig.SLACK_CLIENT_ID, - clientSecret = BuildKonfig.SLACK_CLIENT_SECRET, + requestVerificationEnabled = BuildConfig.SLACK_REQUEST_VERIFICATION_ENABLED, + clientId = BuildConfig.SLACK_CLIENT_ID, + clientSecret = BuildConfig.SLACK_CLIENT_SECRET, + interactivityPubSubTopic = BuildConfig.SLACK_INTERACTIVITY_PUBSUB_TOPIC, + slashCommandPubSubTopic = BuildConfig.SLACK_SLASH_COMMAND_PUBSUB_TOPIC, ) private fun provideSlackRepository( diff --git a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackConfig.kt b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackConfig.kt index 737e0f5d..c9a08351 100644 --- a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackConfig.kt +++ b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackConfig.kt @@ -6,4 +6,6 @@ data class SlackConfig( val requestVerificationEnabled: Boolean, val clientId: String, val clientSecret: String, + val interactivityPubSubTopic: String, + val slashCommandPubSubTopic: String, ) \ No newline at end of file diff --git a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackInteractivityPubSubMessage.kt b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackInteractivityPubSubMessage.kt index 810efac0..d999b0d3 100644 --- a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackInteractivityPubSubMessage.kt +++ b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackInteractivityPubSubMessage.kt @@ -82,6 +82,4 @@ private fun ApiSlackInteractivity.ApiSlackInteractivityPayload.ApiInteractiveMes SlackInteractivityPubSubMessage.InteractivityPayload.InteractiveMessage.User( id = id, name = name - ) - -const val SlackInteractivityPubSubTopic = "slack_interactivity" \ No newline at end of file + ) \ No newline at end of file diff --git a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackSlashCommandPubSubMessage.kt b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackSlashCommandPubSubMessage.kt index 795660f9..0c54f693 100644 --- a/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackSlashCommandPubSubMessage.kt +++ b/backend/slack-data/src/jsMain/kotlin/com/gchristov/thecodinglove/slackdata/domain/SlackSlashCommandPubSubMessage.kt @@ -26,6 +26,4 @@ fun ApiSlackSlashCommand.toPubSubMessage() = SlackSlashCommandPubSubMessage( command = command, text = text, responseUrl = responseUrl -) - -const val SlackSlashCommandPubSubTopic = "slack_slash_command" \ No newline at end of file +) \ No newline at end of file diff --git a/backend/slack-data/src/jsTest/kotlin/com/gchristov/thecodinglove/slackdata/RealVerifySlackRequestUseCaseTest.kt b/backend/slack-data/src/jsTest/kotlin/com/gchristov/thecodinglove/slackdata/RealVerifySlackRequestUseCaseTest.kt index ca835755..98030af1 100644 --- a/backend/slack-data/src/jsTest/kotlin/com/gchristov/thecodinglove/slackdata/RealVerifySlackRequestUseCaseTest.kt +++ b/backend/slack-data/src/jsTest/kotlin/com/gchristov/thecodinglove/slackdata/RealVerifySlackRequestUseCaseTest.kt @@ -132,6 +132,8 @@ class RealVerifySlackRequestUseCaseTest { requestVerificationEnabled = true, clientId = TestClientId, clientSecret = TestClientSecret, + interactivityPubSubTopic = TestInteractivityPubSubTopic, + slashCommandPubSubTopic = TestSlashCommandPubSubTopic, ), clock = TestClock, log = FakeLogger @@ -146,4 +148,6 @@ private const val TestClientId = "client_1" private const val TestClientSecret = "client_secret_1" private val TestClock = object : Clock { override fun now(): Instant = Instant.fromEpochMilliseconds(1675611196847) -} \ No newline at end of file +} +private const val TestInteractivityPubSubTopic = "topic_123" +private const val TestSlashCommandPubSubTopic = "topic_456" \ No newline at end of file diff --git a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/SlackModule.kt b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/SlackModule.kt index a74b1fa8..06f8bfa2 100644 --- a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/SlackModule.kt +++ b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/SlackModule.kt @@ -39,6 +39,7 @@ object SlackModule : DiModule() { slackRepository = instance(), searchUseCase = instance(), pubSubSubscription = instance(), + slackConfig = instance(), ) } bindSingleton { @@ -58,6 +59,7 @@ object SlackModule : DiModule() { slackShuffleSearchUseCase = instance(), slackCancelSearchUseCase = instance(), pubSubSubscription = instance(), + slackConfig = instance(), ) } bindSingleton { @@ -101,6 +103,7 @@ object SlackModule : DiModule() { slackRepository: SlackRepository, searchUseCase: SearchUseCase, pubSubSubscription: PubSubSubscription, + slackConfig: SlackConfig, ): SlackSlashCommandPubSubHandler = SlackSlashCommandPubSubHandler( dispatcher = Dispatchers.Default, jsonSerializer = jsonSerializer, @@ -108,6 +111,7 @@ object SlackModule : DiModule() { slackRepository = slackRepository, searchUseCase = searchUseCase, pubSubSubscription = pubSubSubscription, + slackConfig = slackConfig, ) private fun provideSlackInteractivityHttpHandler( @@ -132,6 +136,7 @@ object SlackModule : DiModule() { slackShuffleSearchUseCase: SlackShuffleSearchUseCase, slackCancelSearchUseCase: SlackCancelSearchUseCase, pubSubSubscription: PubSubSubscription, + slackConfig: SlackConfig, ): SlackInteractivityPubSubHandler = SlackInteractivityPubSubHandler( dispatcher = Dispatchers.Default, jsonSerializer = jsonSerializer, @@ -140,6 +145,7 @@ object SlackModule : DiModule() { slackShuffleSearchUseCase = slackShuffleSearchUseCase, slackCancelSearchUseCase = slackCancelSearchUseCase, pubSubSubscription = pubSubSubscription, + slackConfig = slackConfig, ) private fun provideSlackAuthHttpHandler( diff --git a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityHttpHandler.kt b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityHttpHandler.kt index ec110575..ae47ac80 100644 --- a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityHttpHandler.kt +++ b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityHttpHandler.kt @@ -13,7 +13,6 @@ import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubPublisher import com.gchristov.thecodinglove.slackdata.api.ApiSlackInteractivity import com.gchristov.thecodinglove.slackdata.domain.SlackConfig import com.gchristov.thecodinglove.slackdata.domain.SlackInteractivityPubSubMessage -import com.gchristov.thecodinglove.slackdata.domain.SlackInteractivityPubSubTopic import com.gchristov.thecodinglove.slackdata.domain.toPubSubMessage import com.gchristov.thecodinglove.slackdata.usecase.SlackVerifyRequestUseCase import io.ktor.http.* @@ -58,7 +57,7 @@ class SlackInteractivityHttpHandler( private suspend fun publishInteractivityMessage(interactivity: ApiSlackInteractivity) = pubSubPublisher .publishJson( - topic = SlackInteractivityPubSubTopic, + topic = slackConfig.interactivityPubSubTopic, body = interactivity.toPubSubMessage(), jsonSerializer = jsonSerializer, strategy = SlackInteractivityPubSubMessage.serializer(), diff --git a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityPubSubHandler.kt b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityPubSubHandler.kt index b8413003..419c3c50 100644 --- a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityPubSubHandler.kt +++ b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/interactivity/SlackInteractivityPubSubHandler.kt @@ -10,8 +10,8 @@ import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubHandler import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubRequest import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription import com.gchristov.thecodinglove.slackdata.api.ApiSlackActionName +import com.gchristov.thecodinglove.slackdata.domain.SlackConfig import com.gchristov.thecodinglove.slackdata.domain.SlackInteractivityPubSubMessage -import com.gchristov.thecodinglove.slackdata.domain.SlackInteractivityPubSubTopic import com.gchristov.thecodinglove.slackdata.usecase.SlackCancelSearchUseCase import com.gchristov.thecodinglove.slackdata.usecase.SlackSendSearchUseCase import com.gchristov.thecodinglove.slackdata.usecase.SlackShuffleSearchUseCase @@ -27,6 +27,7 @@ class SlackInteractivityPubSubHandler( private val slackShuffleSearchUseCase: SlackShuffleSearchUseCase, private val slackCancelSearchUseCase: SlackCancelSearchUseCase, pubSubSubscription: PubSubSubscription, + private val slackConfig: SlackConfig, ) : BasePubSubHandler( dispatcher = dispatcher, jsonSerializer = jsonSerializer, @@ -40,7 +41,7 @@ class SlackInteractivityPubSubHandler( ) override fun pubSubConfig() = PubSubHandler.PubSubConfig( - topic = SlackInteractivityPubSubTopic, + topic = slackConfig.interactivityPubSubTopic, ) override suspend fun handlePubSubRequest(request: PubSubRequest): Either = diff --git a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandHttpHandler.kt b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandHttpHandler.kt index e86c59d7..7bc73e96 100644 --- a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandHttpHandler.kt +++ b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandHttpHandler.kt @@ -13,7 +13,6 @@ import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubPublisher import com.gchristov.thecodinglove.slackdata.api.ApiSlackSlashCommand import com.gchristov.thecodinglove.slackdata.domain.SlackConfig import com.gchristov.thecodinglove.slackdata.domain.SlackSlashCommandPubSubMessage -import com.gchristov.thecodinglove.slackdata.domain.SlackSlashCommandPubSubTopic import com.gchristov.thecodinglove.slackdata.domain.toPubSubMessage import com.gchristov.thecodinglove.slackdata.usecase.SlackVerifyRequestUseCase import io.ktor.http.* @@ -58,7 +57,7 @@ class SlackSlashCommandHttpHandler( private suspend fun publishSlashCommandMessage(slashCommand: ApiSlackSlashCommand) = pubSubPublisher .publishJson( - topic = SlackSlashCommandPubSubTopic, + topic = slackConfig.slashCommandPubSubTopic, body = slashCommand.toPubSubMessage(), jsonSerializer = jsonSerializer, strategy = SlackSlashCommandPubSubMessage.serializer(), diff --git a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandPubSubHandler.kt b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandPubSubHandler.kt index e8f0ef40..958ebbd2 100644 --- a/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandPubSubHandler.kt +++ b/backend/slack/src/jsMain/kotlin/com/gchristov/thecodinglove/slack/slashcommand/SlackSlashCommandPubSubHandler.kt @@ -12,8 +12,8 @@ import com.gchristov.thecodinglove.commonservicedata.pubsub.PubSubSubscription import com.gchristov.thecodinglove.searchdata.usecase.SearchUseCase import com.gchristov.thecodinglove.slackdata.SlackRepository import com.gchristov.thecodinglove.slackdata.api.ApiSlackMessageFactory +import com.gchristov.thecodinglove.slackdata.domain.SlackConfig import com.gchristov.thecodinglove.slackdata.domain.SlackSlashCommandPubSubMessage -import com.gchristov.thecodinglove.slackdata.domain.SlackSlashCommandPubSubTopic import io.ktor.http.* import kotlinx.coroutines.CoroutineDispatcher import kotlinx.serialization.json.Json @@ -25,6 +25,7 @@ class SlackSlashCommandPubSubHandler( private val slackRepository: SlackRepository, private val searchUseCase: SearchUseCase, pubSubSubscription: PubSubSubscription, + private val slackConfig: SlackConfig, ) : BasePubSubHandler( dispatcher = dispatcher, jsonSerializer = jsonSerializer, @@ -38,7 +39,7 @@ class SlackSlashCommandPubSubHandler( ) override fun pubSubConfig() = PubSubHandler.PubSubConfig( - topic = SlackSlashCommandPubSubTopic, + topic = slackConfig.slashCommandPubSubTopic, ) override suspend fun handlePubSubRequest(request: PubSubRequest): Either = diff --git a/gradle-plugins/src/main/kotlin/com/gchristov/thecodinglove/gradleplugins/LocalSecrets.kt b/gradle-plugins/src/main/kotlin/com/gchristov/thecodinglove/gradleplugins/LocalSecrets.kt deleted file mode 100644 index ba3aae5f..00000000 --- a/gradle-plugins/src/main/kotlin/com/gchristov/thecodinglove/gradleplugins/LocalSecrets.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.gchristov.thecodinglove.gradleplugins - -import org.gradle.api.Project -import java.io.FileInputStream -import java.util.* - -@Suppress("unused") -fun getLocalSecret( - rootProject: Project, - key: String -): String { - val propFile = rootProject.file("./local.properties") - val properties = Properties() - properties.load(FileInputStream(propFile)) - return properties.getProperty(key) -} \ No newline at end of file diff --git a/scripts/env.sh b/scripts/env.sh index ac5a8542..925d108d 100644 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -11,6 +11,10 @@ echo SLACK_SIGNING_SECRET="$SLACK_SIGNING_SECRET" >> ./local.properties echo SLACK_REQUEST_VERIFICATION_ENABLED="$SLACK_REQUEST_VERIFICATION_ENABLED" >> ./local.properties echo SLACK_CLIENT_ID="$SLACK_CLIENT_ID" >> ./local.properties echo SLACK_CLIENT_SECRET="$SLACK_CLIENT_SECRET" >> ./local.properties +echo SLACK_INTERACTIVITY_PUBSUB_TOPIC="$SLACK_INTERACTIVITY_PUBSUB_TOPIC" >> ./local.properties +echo SLACK_SLASH_COMMAND_PUBSUB_TOPIC="$SLACK_SLASH_COMMAND_PUBSUB_TOPIC" >> ./local.properties echo APP_LOG_LEVEL="$APP_LOG_LEVEL" >> ./local.properties echo APP_NETWORK_HTML_LOG_LEVEL="$APP_NETWORK_HTML_LOG_LEVEL" >> ./local.properties -echo APP_NETWORK_JSON_LOG_LEVEL="$APP_NETWORK_JSON_LOG_LEVEL" >> ./local.properties \ No newline at end of file +echo APP_NETWORK_JSON_LOG_LEVEL="$APP_NETWORK_JSON_LOG_LEVEL" >> ./local.properties +echo APP_PUBLIC_URL="$APP_PUBLIC_URL" >> ./local.properties +echo SEARCH_PRELOAD_PUBSUB_TOPIC="$SEARCH_PRELOAD_PUBSUB_TOPIC" >> ./local.properties \ No newline at end of file diff --git a/shared/kmp-common-firebase/build.gradle.kts b/shared/kmp-common-firebase/build.gradle.kts index 1df38914..5a0911c2 100644 --- a/shared/kmp-common-firebase/build.gradle.kts +++ b/shared/kmp-common-firebase/build.gradle.kts @@ -1,11 +1,7 @@ import com.gchristov.thecodinglove.gradleplugins.Deps -import com.gchristov.thecodinglove.gradleplugins.getLocalSecret - -val packageId = "com.gchristov.thecodinglove.kmpcommonfirebase" plugins { id("kmp-module-plugin") - id("build-config-plugin") } kotlin { @@ -16,40 +12,4 @@ kotlin { } } } -} - -buildkonfig { - packageName = packageId - defaultConfigs { - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_API_KEY", - value = getLocalSecret(rootProject, "FIREBASE_API_KEY") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_AUTH_DOMAIN", - value = getLocalSecret(rootProject, "FIREBASE_AUTH_DOMAIN") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_PROJECT_ID", - value = getLocalSecret(rootProject, "FIREBASE_PROJECT_ID") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_STORAGE_BUCKET", - value = getLocalSecret(rootProject, "FIREBASE_STORAGE_BUCKET") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_GCM_SENDER_ID", - value = getLocalSecret(rootProject, "FIREBASE_GCM_SENDER_ID") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "FIREBASE_APPLICATION_ID", - value = getLocalSecret(rootProject, "FIREBASE_APPLICATION_ID") - ) - } } \ No newline at end of file diff --git a/shared/kmp-common-firebase/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonfirebase/KmpCommonFirebaseModule.kt b/shared/kmp-common-firebase/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonfirebase/KmpCommonFirebaseModule.kt index c9912b8a..e4a8de08 100644 --- a/shared/kmp-common-firebase/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonfirebase/KmpCommonFirebaseModule.kt +++ b/shared/kmp-common-firebase/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonfirebase/KmpCommonFirebaseModule.kt @@ -1,5 +1,6 @@ package com.gchristov.thecodinglove.kmpcommonfirebase +import com.gchristov.thecodinglove.kmpcommonkotlin.BuildConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp @@ -22,12 +23,12 @@ object KmpCommonFirebaseModule : DiModule() { } private fun provideFirebaseOptions(): FirebaseOptions = FirebaseOptions( - apiKey = BuildKonfig.FIREBASE_API_KEY, - authDomain = BuildKonfig.FIREBASE_AUTH_DOMAIN, - projectId = BuildKonfig.FIREBASE_PROJECT_ID, - storageBucket = BuildKonfig.FIREBASE_STORAGE_BUCKET, - gcmSenderId = BuildKonfig.FIREBASE_GCM_SENDER_ID, - applicationId = BuildKonfig.FIREBASE_APPLICATION_ID + apiKey = BuildConfig.FIREBASE_API_KEY, + authDomain = BuildConfig.FIREBASE_AUTH_DOMAIN, + projectId = BuildConfig.FIREBASE_PROJECT_ID, + storageBucket = BuildConfig.FIREBASE_STORAGE_BUCKET, + gcmSenderId = BuildConfig.FIREBASE_GCM_SENDER_ID, + applicationId = BuildConfig.FIREBASE_APPLICATION_ID ) private fun provideFirestore(app: FirebaseApp): FirebaseFirestore = Firebase.firestore(app) diff --git a/shared/kmp-common-kotlin/build.gradle.kts b/shared/kmp-common-kotlin/build.gradle.kts index 3d0df491..76e855e9 100644 --- a/shared/kmp-common-kotlin/build.gradle.kts +++ b/shared/kmp-common-kotlin/build.gradle.kts @@ -1,5 +1,6 @@ import com.gchristov.thecodinglove.gradleplugins.Deps -import com.gchristov.thecodinglove.gradleplugins.getLocalSecret +import java.io.FileInputStream +import java.util.* val packageId = "com.gchristov.thecodinglove.kmpcommonkotlin" @@ -28,11 +29,103 @@ kotlin { buildkonfig { packageName = packageId + exposeObjectWithName = "BuildConfig" defaultConfigs { + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_API_KEY", + value = getLocalSecret(rootProject, "FIREBASE_API_KEY") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_AUTH_DOMAIN", + value = getLocalSecret(rootProject, "FIREBASE_AUTH_DOMAIN") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_PROJECT_ID", + value = getLocalSecret(rootProject, "FIREBASE_PROJECT_ID") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_STORAGE_BUCKET", + value = getLocalSecret(rootProject, "FIREBASE_STORAGE_BUCKET") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_GCM_SENDER_ID", + value = getLocalSecret(rootProject, "FIREBASE_GCM_SENDER_ID") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "FIREBASE_APPLICATION_ID", + value = getLocalSecret(rootProject, "FIREBASE_APPLICATION_ID") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SLACK_SIGNING_SECRET", + value = getLocalSecret(rootProject, "SLACK_SIGNING_SECRET") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.BOOLEAN, + name = "SLACK_REQUEST_VERIFICATION_ENABLED", + value = getLocalSecret(rootProject, "SLACK_REQUEST_VERIFICATION_ENABLED") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SLACK_CLIENT_ID", + value = getLocalSecret(rootProject, "SLACK_CLIENT_ID") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SLACK_CLIENT_SECRET", + value = getLocalSecret(rootProject, "SLACK_CLIENT_SECRET") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SLACK_INTERACTIVITY_PUBSUB_TOPIC", + value = getLocalSecret(rootProject, "SLACK_INTERACTIVITY_PUBSUB_TOPIC") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SLACK_SLASH_COMMAND_PUBSUB_TOPIC", + value = getLocalSecret(rootProject, "SLACK_SLASH_COMMAND_PUBSUB_TOPIC") + ) buildConfigField( type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, name = "APP_LOG_LEVEL", value = getLocalSecret(rootProject, "APP_LOG_LEVEL") ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "APP_NETWORK_HTML_LOG_LEVEL", + value = getLocalSecret(rootProject, "APP_NETWORK_HTML_LOG_LEVEL") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "APP_NETWORK_JSON_LOG_LEVEL", + value = getLocalSecret(rootProject, "APP_NETWORK_JSON_LOG_LEVEL") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "APP_PUBLIC_URL", + value = getLocalSecret(rootProject, "APP_PUBLIC_URL") + ) + buildConfigField( + type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, + name = "SEARCH_PRELOAD_PUBSUB_TOPIC", + value = getLocalSecret(rootProject, "SEARCH_PRELOAD_PUBSUB_TOPIC") + ) } +} + +@Suppress("unused") +fun getLocalSecret( + rootProject: Project, + key: String +): String { + val propFile = rootProject.file("./local.properties") + val properties = Properties() + properties.load(FileInputStream(propFile)) + return properties.getProperty(key) } \ No newline at end of file diff --git a/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/AppConfig.kt b/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/AppConfig.kt new file mode 100644 index 00000000..434d9e4a --- /dev/null +++ b/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/AppConfig.kt @@ -0,0 +1,8 @@ +package com.gchristov.thecodinglove.kmpcommonkotlin + +data class AppConfig( + val logLevel: String, + val networkHtmlLogLevel: String, + val networkJsonLogLevel: String, + val publicUrl: String, +) \ No newline at end of file diff --git a/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/KmpCommonKotlinModule.kt b/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/KmpCommonKotlinModule.kt index f5d17bfa..e1622c6f 100644 --- a/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/KmpCommonKotlinModule.kt +++ b/shared/kmp-common-kotlin/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonkotlin/KmpCommonKotlinModule.kt @@ -7,19 +7,28 @@ import co.touchlab.kermit.StaticConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import org.kodein.di.DI import org.kodein.di.bindSingleton +import org.kodein.di.instance object KmpCommonKotlinModule : DiModule() { override fun name() = "kmp-common-kotlin" override fun bindDependencies(builder: DI.Builder) { builder.apply { - bindSingleton { provideLogger() } + bindSingleton { provideAppConfig() } + bindSingleton { provideLogger(appConfig = instance()) } } } - private fun provideLogger(): Logger = Logger( + private fun provideAppConfig(): AppConfig = AppConfig( + logLevel = BuildConfig.APP_LOG_LEVEL, + networkHtmlLogLevel = BuildConfig.APP_NETWORK_HTML_LOG_LEVEL, + networkJsonLogLevel = BuildConfig.APP_NETWORK_JSON_LOG_LEVEL, + publicUrl = BuildConfig.APP_PUBLIC_URL.removeSuffix("/"), + ) + + private fun provideLogger(appConfig: AppConfig): Logger = Logger( config = StaticConfig( - minSeverity = when (BuildKonfig.APP_LOG_LEVEL) { + minSeverity = when (appConfig.logLevel) { "debug" -> Severity.Debug "verbose" -> Severity.Verbose "error" -> Severity.Error diff --git a/shared/kmp-common-network/build.gradle.kts b/shared/kmp-common-network/build.gradle.kts index ec9ef6d6..8c5a6cc5 100644 --- a/shared/kmp-common-network/build.gradle.kts +++ b/shared/kmp-common-network/build.gradle.kts @@ -1,11 +1,7 @@ import com.gchristov.thecodinglove.gradleplugins.Deps -import com.gchristov.thecodinglove.gradleplugins.getLocalSecret - -val packageId = "com.gchristov.thecodinglove.kmpcommonnetwork" plugins { id("kmp-module-plugin") - id("build-config-plugin") } kotlin { @@ -20,20 +16,4 @@ kotlin { } } } -} - -buildkonfig { - packageName = packageId - defaultConfigs { - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "APP_NETWORK_HTML_LOG_LEVEL", - value = getLocalSecret(rootProject, "APP_NETWORK_HTML_LOG_LEVEL") - ) - buildConfigField( - type = com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING, - name = "APP_NETWORK_JSON_LOG_LEVEL", - value = getLocalSecret(rootProject, "APP_NETWORK_JSON_LOG_LEVEL") - ) - } } \ No newline at end of file diff --git a/shared/kmp-common-network/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonnetwork/KmpCommonNetworkModule.kt b/shared/kmp-common-network/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonnetwork/KmpCommonNetworkModule.kt index 97a2047d..5ab70d1e 100644 --- a/shared/kmp-common-network/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonnetwork/KmpCommonNetworkModule.kt +++ b/shared/kmp-common-network/src/commonMain/kotlin/com/gchristov/thecodinglove/kmpcommonnetwork/KmpCommonNetworkModule.kt @@ -1,5 +1,6 @@ package com.gchristov.thecodinglove.kmpcommonnetwork +import com.gchristov.thecodinglove.kmpcommonkotlin.AppConfig import com.gchristov.thecodinglove.kmpcommonkotlin.di.DiModule import io.ktor.client.* import io.ktor.client.plugins.* @@ -18,8 +19,13 @@ object KmpCommonNetworkModule : DiModule() { override fun bindDependencies(builder: DI.Builder) { builder.apply { bindSingleton { provideJsonSerializer() } - bindSingleton { provideHtmlClient() } - bindSingleton { provideJsonClient(serializer = instance()) } + bindSingleton { provideHtmlClient(appConfig = instance()) } + bindSingleton { + provideJsonClient( + serializer = instance(), + appConfig = instance(), + ) + } } } @@ -30,14 +36,17 @@ object KmpCommonNetworkModule : DiModule() { explicitNulls = false } - private fun provideHtmlClient() = HtmlClient( - provideHttpClient(BuildKonfig.APP_NETWORK_HTML_LOG_LEVEL).config { + private fun provideHtmlClient(appConfig: AppConfig) = HtmlClient( + provideHttpClient(appConfig.networkHtmlLogLevel).config { BrowserUserAgent() } ) - private fun provideJsonClient(serializer: Json) = JsonClient( - provideHttpClient(BuildKonfig.APP_NETWORK_JSON_LOG_LEVEL).config { + private fun provideJsonClient( + serializer: Json, + appConfig: AppConfig, + ) = JsonClient( + provideHttpClient(appConfig.networkJsonLogLevel).config { install(ContentNegotiation) { json(serializer) }