Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename API interfaces #125

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class CommonMonitoringModule(val environment: MonitoringEnvironment) : DiMo
}
bindSingleton {
provideSlackReportExceptionRepository(
api = instance(),
slackReportExceptionApi = instance(),
)
}
bindSingleton {
Expand All @@ -44,9 +44,9 @@ data class CommonMonitoringModule(val environment: MonitoringEnvironment) : DiMo
)

private fun provideSlackReportExceptionRepository(
api: SlackReportExceptionApi,
slackReportExceptionApi: SlackReportExceptionApi,
): SlackReportExceptionRepository = RealSlackReportExceptionRepository(
apiService = api,
slackReportExceptionApi = slackReportExceptionApi,
)

private fun provideMonitoringLogWriter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface SlackReportExceptionRepository {
}

internal class RealSlackReportExceptionRepository(
private val apiService: SlackReportExceptionApi,
private val slackReportExceptionApi: SlackReportExceptionApi,
) : SlackReportExceptionRepository {
override suspend fun reportException(
message: String,
stacktrace: String,
): Either<Throwable, Unit> = try {
apiService.reportException(
slackReportExceptionApi.reportException(
ApiSlackReportException(
message = message,
stacktrace = stacktrace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import kotlinx.coroutines.withContext

sealed class FakeResponse {
data class Error(val message: String? = null) : FakeResponse()
object CompletesNormally : FakeResponse()
object LoadsForever : FakeResponse()
data object CompletesNormally : FakeResponse()
data object LoadsForever : FakeResponse()
}

suspend fun <T> FakeResponse.execute(value: T): T = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import com.gchristov.thecodinglove.search.adapter.db.mapper.toSearchSession
import com.gchristov.thecodinglove.search.adapter.htmlparser.mapper.toPost
import com.gchristov.thecodinglove.search.adapter.htmlparser.usecase.ParseHtmlPostsUseCase
import com.gchristov.thecodinglove.search.adapter.htmlparser.usecase.ParseHtmlTotalPostsUseCase
import com.gchristov.thecodinglove.search.adapter.http.SearchApi
import com.gchristov.thecodinglove.search.adapter.http.TheCodingLoveApi
import com.gchristov.thecodinglove.search.domain.model.SearchError
import com.gchristov.thecodinglove.search.domain.model.SearchPost
import com.gchristov.thecodinglove.search.domain.model.SearchSession
import com.gchristov.thecodinglove.search.domain.port.SearchRepository
import io.ktor.client.statement.*

internal class RealSearchRepository(
private val apiService: SearchApi,
private val theCodingLoveApi: TheCodingLoveApi,
private val parseHtmlTotalPostsUseCase: ParseHtmlTotalPostsUseCase,
private val parseHtmlPostsUseCase: ParseHtmlPostsUseCase,
private val firebaseAdmin: FirebaseAdmin,
private val jsonSerializer: JsonSerializer,
) : SearchRepository {
override suspend fun getTotalPosts(query: String): Either<Throwable, Int> = try {
val responseHtml = apiService.search(
val responseHtml = theCodingLoveApi.search(
// First page should always exist if there are results
page = 1,
query = query
Expand All @@ -42,7 +42,7 @@ internal class RealSearchRepository(
page: Int,
query: String
): Either<Throwable, List<SearchPost>> = try {
val responseHtml = apiService.search(
val responseHtml = theCodingLoveApi.search(
page = page,
query = query
).bodyAsText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ object SearchAdapterModule : DiModule() {

override fun bindDependencies(builder: DI.Builder) {
builder.apply {
bindSingleton { provideSearchApi(client = instance()) }
bindSingleton { provideTheCodingLoveApi(client = instance()) }
bindSingleton {
provideSearchRepository(
api = instance(),
theCodingLoveApi = instance(),
parseHtmlTotalPostsUseCase = instance(),
parseHtmlPostsUseCase = instance(),
firebaseAdmin = instance(),
Expand Down Expand Up @@ -87,16 +87,16 @@ object SearchAdapterModule : DiModule() {
}
}

private fun provideSearchApi(client: NetworkClient.Html) = SearchApi(client)
private fun provideTheCodingLoveApi(client: NetworkClient.Html) = TheCodingLoveApi(client)

private fun provideSearchRepository(
api: SearchApi,
theCodingLoveApi: TheCodingLoveApi,
parseHtmlTotalPostsUseCase: ParseHtmlTotalPostsUseCase,
parseHtmlPostsUseCase: ParseHtmlPostsUseCase,
firebaseAdmin: FirebaseAdmin,
jsonSerializer: JsonSerializer.ExplicitNulls,
): SearchRepository = RealSearchRepository(
apiService = api,
theCodingLoveApi = theCodingLoveApi,
parseHtmlTotalPostsUseCase = parseHtmlTotalPostsUseCase,
parseHtmlPostsUseCase = parseHtmlPostsUseCase,
firebaseAdmin = firebaseAdmin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*

internal class SearchApi(private val client: NetworkClient.Html) {
internal class TheCodingLoveApi(private val client: NetworkClient.Html) {
suspend fun search(
page: Int,
query: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object SelfDestructAdapterModule : DiModule() {
}
bindSingleton {
provideSlackSelfDestructRepository(
api = instance(),
slackSelfDestructApi = instance(),
)
}
}
Expand All @@ -61,8 +61,8 @@ object SelfDestructAdapterModule : DiModule() {
)

private fun provideSlackSelfDestructRepository(
api: SlackSelfDestructApi,
slackSelfDestructApi: SlackSelfDestructApi,
): SlackSelfDestructRepository = RealSlackSelfDestructRepository(
apiService = api,
slackSelfDestructApi = slackSelfDestructApi,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import arrow.core.Either
import com.gchristov.thecodinglove.selfdestruct.domain.port.SlackSelfDestructRepository

internal class RealSlackSelfDestructRepository(
private val apiService: SlackSelfDestructApi,
private val slackSelfDestructApi: SlackSelfDestructApi,
) : SlackSelfDestructRepository {
override suspend fun selfDestruct(): Either<Throwable, Unit> = try {
apiService.selfDestruct()
slackSelfDestructApi.selfDestruct()
Either.Right(Unit)
} catch (error: Throwable) {
Either.Left(Throwable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.ktor.client.statement.*
import io.ktor.http.*

internal class RealSlackRepository(
private val apiService: SlackApi,
private val slackApi: SlackApi,
private val firebaseAdmin: FirebaseAdmin,
private val jsonSerializer: JsonSerializer,
) : SlackRepository {
Expand All @@ -31,7 +31,7 @@ internal class RealSlackRepository(
clientId: String,
clientSecret: String
) = try {
val slackResponse: ApiSlackAuthResponse = apiService.authUser(
val slackResponse: ApiSlackAuthResponse = slackApi.authUser(
code = code,
clientId = clientId,
clientSecret = clientSecret
Expand Down Expand Up @@ -108,7 +108,7 @@ internal class RealSlackRepository(
url: String,
message: SlackMessage,
) = try {
val slackResponse = apiService.postMessageToUrl(
val slackResponse = slackApi.postMessageToUrl(
url = url,
message = message.toSlackMessage(),
)
Expand Down Expand Up @@ -140,7 +140,7 @@ internal class RealSlackRepository(
authToken: String,
message: SlackMessage,
) = try {
val slackResponse: ApiSlackPostMessageResponse = apiService.postMessage(
val slackResponse: ApiSlackPostMessageResponse = slackApi.postMessage(
authToken = authToken,
message = message.toSlackMessage(),
).body()
Expand All @@ -161,7 +161,7 @@ internal class RealSlackRepository(
channelId: String,
messageTs: String,
): Either<Throwable, Unit> = try {
val slackResponse: ApiSlackDeleteMessageResponse = apiService.deleteMessage(
val slackResponse: ApiSlackDeleteMessageResponse = slackApi.deleteMessage(
authToken = authToken,
deleteMessage = ApiSlackDeleteMessage(
channelId = channelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object SlackAdapterModule : DiModule() {
bindSingleton { provideSlackConfig() }
bindSingleton {
provideSlackRepository(
api = instance(),
slackApi = instance(),
firebaseAdmin = instance(),
jsonSerializer = instance(),
)
Expand Down Expand Up @@ -149,11 +149,11 @@ object SlackAdapterModule : DiModule() {
)

private fun provideSlackRepository(
api: SlackApi,
slackApi: SlackApi,
firebaseAdmin: FirebaseAdmin,
jsonSerializer: JsonSerializer.ExplicitNulls,
): SlackRepository = RealSlackRepository(
apiService = api,
slackApi = slackApi,
firebaseAdmin = firebaseAdmin,
jsonSerializer = jsonSerializer,
)
Expand All @@ -162,10 +162,10 @@ object SlackAdapterModule : DiModule() {
RealSlackAuthStateSerializer(jsonSerializer = jsonSerializer)

private fun provideSearchSessionStorage(searchApi: SearchApi): SearchSessionStorage =
RealSearchSessionStorage(apiService = searchApi)
RealSearchSessionStorage(searchApi = searchApi)

private fun provideSearchSessionShuffle(searchApi: SearchApi): SearchEngine =
RealSearchEngine(apiService = searchApi)
RealSearchEngine(searchApi = searchApi)

private fun provideSlackEventHttpHandler(
jsonSerializer: JsonSerializer.Default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.gchristov.thecodinglove.slack.adapter.search.model.ApiSearchResult
import com.gchristov.thecodinglove.slack.domain.port.SearchEngine
import io.ktor.client.call.*

internal class RealSearchEngine(private val apiService: SearchApi) : SearchEngine {
internal class RealSearchEngine(private val searchApi: SearchApi) : SearchEngine {
override suspend fun search(query: String) = try {
val response: ApiSearchResult = apiService.search(query).body()
val response: ApiSearchResult = searchApi.search(query).body()
Either.Right(response.toSearchResult())
} catch (error: Throwable) {
Either.Left(Throwable(
Expand All @@ -18,7 +18,7 @@ internal class RealSearchEngine(private val apiService: SearchApi) : SearchEngin
}

override suspend fun shuffle(searchSessionId: String) = try {
val response: ApiSearchResult = apiService.shuffle(searchSessionId).body()
val response: ApiSearchResult = searchApi.shuffle(searchSessionId).body()
Either.Right(response.toSearchResult())
} catch (error: Throwable) {
Either.Left(Throwable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.gchristov.thecodinglove.slack.domain.port.SearchSessionStateDto
import com.gchristov.thecodinglove.slack.domain.port.SearchSessionStorage
import io.ktor.client.call.*

internal class RealSearchSessionStorage(private val apiService: SearchApi) : SearchSessionStorage {
internal class RealSearchSessionStorage(private val searchApi: SearchApi) : SearchSessionStorage {
override suspend fun deleteSearchSession(searchSessionId: String) = try {
apiService.deleteSearchSession(searchSessionId)
searchApi.deleteSearchSession(searchSessionId)
Either.Right(Unit)
} catch (error: Throwable) {
Either.Left(Throwable(
Expand All @@ -23,7 +23,7 @@ internal class RealSearchSessionStorage(private val apiService: SearchApi) : Sea
searchSessionId: String,
state: SearchSessionStateDto
): Either<Throwable, Unit> = try {
apiService.updateSearchSessionState(
searchApi.updateSearchSessionState(
ApiUpdateSearchSessionState(
searchSessionId = searchSessionId,
state = when (state) {
Expand All @@ -41,7 +41,7 @@ internal class RealSearchSessionStorage(private val apiService: SearchApi) : Sea
}

override suspend fun getSearchSessionPost(searchSessionId: String) = try {
val response: ApiSearchSessionPost = apiService.getSearchSessionPost(searchSessionId).body()
val response: ApiSearchSessionPost = searchApi.getSearchSessionPost(searchSessionId).body()
Either.Right(response.toSearchSessionPost())
} catch (error: Throwable) {
Either.Left(Throwable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ object StatisticsAdapterModule : DiModule() {
}
bindSingleton {
provideSearchStatisticsRepository(
api = instance(),
searchStatisticsApi = instance(),
)
}
bindSingleton {
provideSlackStatisticsRepository(
api = instance(),
slackStatisticsApi = instance(),
)
}
}
Expand All @@ -67,15 +67,15 @@ object StatisticsAdapterModule : DiModule() {
)

private fun provideSearchStatisticsRepository(
api: SearchStatisticsApi,
searchStatisticsApi: SearchStatisticsApi,
): SearchStatisticsRepository = RealSearchStatisticsRepository(
apiService = api,
searchStatisticsApi = searchStatisticsApi,
)

private fun provideSlackStatisticsRepository(
api: SlackStatisticsApi,
slackStatisticsApi: SlackStatisticsApi,
): SlackStatisticsRepository = RealSlackStatisticsRepository(
apiService = api,
slackStatisticsApi = slackStatisticsApi,
)

private fun provideSlackStatisticsApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.gchristov.thecodinglove.statistics.domain.port.SearchStatisticsReposi
import io.ktor.client.call.*

internal class RealSearchStatisticsRepository(
private val apiService: SearchStatisticsApi,
private val searchStatisticsApi: SearchStatisticsApi,
) : SearchStatisticsRepository {
override suspend fun statistics(): Either<Throwable, StatisticsReport.SearchStatistics> = try {
val response: ApiSearchStatistics = apiService.statistics().body()
val response: ApiSearchStatistics = searchStatisticsApi.statistics().body()
Either.Right(response.toStatistics())
} catch (error: Throwable) {
Either.Left(Throwable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.gchristov.thecodinglove.statistics.domain.port.SlackStatisticsReposit
import io.ktor.client.call.*

internal class RealSlackStatisticsRepository(
private val apiService: SlackStatisticsApi,
private val slackStatisticsApi: SlackStatisticsApi,
) : SlackStatisticsRepository {
override suspend fun statistics(): Either<Throwable, StatisticsReport.SlackStatistics> = try {
val response: ApiSlackStatistics = apiService.statistics().body()
val response: ApiSlackStatistics = slackStatisticsApi.statistics().body()
Either.Right(response.toStatistics())
} catch (error: Throwable) {
Either.Left(Throwable(
Expand Down