Skip to content

Commit

Permalink
Rename modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Nov 12, 2023
1 parent 6154314 commit f468142
Show file tree
Hide file tree
Showing 37 changed files with 112 additions and 114 deletions.
10 changes: 5 additions & 5 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ androidComponents {
}

dependencies {
mockImplementation(project(":kmp:data-testing"))
devImplementation(project(":kmp:data-runtime-cloud"))
demoImplementation(project(":kmp:data-runtime-edge"))
prodImplementation(project(":kmp:data-runtime-cloud"))
mockImplementation(project(":kmp:datasource:testing"))
devImplementation(project(":kmp:datasource:runtime-cloud"))
demoImplementation(project(":kmp:datasource:runtime-edge"))
prodImplementation(project(":kmp:datasource:runtime-cloud"))

implementation(project(":ui-common"))
implementation(project(":feature:common"))

// Firebase
releaseImplementation(libs.firebase.perf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.data.feed.EdgeFeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.feed.FeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.data.util.KtorApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.EdgeFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.KtorApiErrorChecker
import javax.inject.Singleton

@Module
Expand All @@ -16,8 +16,8 @@ object EdgeDataModule {

@Provides
@Singleton
fun feedRepo(): FeedRepo {
return EdgeFeedRepo()
fun feedDataSource(): FeedDataSource {
return EdgeFeedDataSource()
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.data.feed.CloudFeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.feed.FeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.data.util.ApolloApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.CloudFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.ApolloApiErrorChecker
import javax.inject.Singleton

@Module
Expand All @@ -17,8 +17,8 @@ object CloudDataModule {

@Provides
@Singleton
fun feedRepo(apolloClient: ApolloClient): FeedRepo {
return CloudFeedRepo(apolloClient)
fun feedDataSource(apolloClient: ApolloClient): FeedDataSource {
return CloudFeedDataSource(apolloClient)
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.android.BuildConfig
import io.github.reactivecircus.kstreamlined.kmp.data.networking.ApolloClientConfigs
import io.github.reactivecircus.kstreamlined.kmp.datasource.networking.ApolloClientConfigs
import javax.inject.Singleton
import kotlin.time.DurationUnit
import kotlin.time.toDuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.data.feed.FakeFeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.feed.FeedRepo
import io.github.reactivecircus.kstreamlined.kmp.data.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.data.util.NoOpApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.FakeFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.ApiErrorChecker
import io.github.reactivecircus.kstreamlined.kmp.datasource.util.NoOpApiErrorChecker
import javax.inject.Singleton

@Module
Expand All @@ -16,8 +16,8 @@ object MockDataModule {

@Provides
@Singleton
fun feedRepo(): FeedRepo {
return FakeFeedRepo()
fun feedDataSource(): FeedDataSource {
return FakeFeedDataSource()
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

android {
namespace = "io.github.reactivecircus.kstreamlined.android.ui.common"
namespace = "io.github.reactivecircus.kstreamlined.android.feature.common"
buildFeatures {
androidResources = true
}
Expand All @@ -20,8 +20,6 @@ androidComponents {
}

dependencies {
api(project(":kmp:data-common"))

// AndroidX
api(libs.androidx.core)

Expand Down

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.reactivecircus.kstreamlined.kmp.datasource

import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedSource

interface FeedDataSource {

suspend fun loadFeedSources(
refresh: Boolean = false
): List<FeedSource>

suspend fun loadFeedEntries(
filters: List<FeedSource.Key>? = null,
refresh: Boolean = false,
): List<FeedEntry>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.model
package io.github.reactivecircus.kstreamlined.kmp.datasource.model

sealed interface FeedEntry {
val id: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.model
package io.github.reactivecircus.kstreamlined.kmp.datasource.model

data class FeedSource(
val key: Key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.util
package io.github.reactivecircus.kstreamlined.kmp.datasource.util

interface ApiErrorChecker {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api(project(":kmp:data-common"))
api(project(":kmp:datasource:common"))
api(libs.apollo.runtime)
api(libs.apollo.normalizedCache)
implementation(libs.kotlinx.coroutines.core)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed
package io.github.reactivecircus.kstreamlined.kmp.datasource

import co.touchlab.kermit.Logger
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.Optional
import io.github.reactivecircus.kstreamlined.graphql.FeedEntriesQuery
import io.github.reactivecircus.kstreamlined.graphql.FeedSourcesQuery
import io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper.toApollo
import io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper.toModel
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedSource
import io.github.reactivecircus.kstreamlined.kmp.data.networking.defaultFetchPolicy
import io.github.reactivecircus.kstreamlined.kmp.datasource.mapper.toApollo
import io.github.reactivecircus.kstreamlined.kmp.datasource.mapper.toModel
import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.networking.defaultFetchPolicy

class CloudFeedRepo(private val apolloClient: ApolloClient) : FeedRepo {
class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedDataSource {

override suspend fun loadFeedSources(refresh: Boolean): List<FeedSource> {
return runCatching {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper
package io.github.reactivecircus.kstreamlined.kmp.datasource.mapper

import io.github.reactivecircus.kstreamlined.graphql.FeedEntriesQuery
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedEntry

internal fun FeedEntriesQuery.FeedEntry.toModel(): FeedEntry {
return when (this) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper
package io.github.reactivecircus.kstreamlined.kmp.datasource.mapper

import io.github.reactivecircus.kstreamlined.graphql.FeedSourcesQuery
import io.github.reactivecircus.kstreamlined.graphql.type.FeedSourceKey
import io.github.reactivecircus.kstreamlined.kmp.data.feed.model.FeedSource
import io.github.reactivecircus.kstreamlined.kmp.datasource.model.FeedSource

internal fun FeedSource.Key.toApollo(): FeedSourceKey {
return when (this) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.networking
package io.github.reactivecircus.kstreamlined.kmp.datasource.networking

import com.apollographql.apollo3.cache.normalized.ApolloStore
import com.apollographql.apollo3.cache.normalized.api.MemoryCacheFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.networking
package io.github.reactivecircus.kstreamlined.kmp.datasource.networking

import com.apollographql.apollo3.ApolloCall
import com.apollographql.apollo3.api.Operation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.util
package io.github.reactivecircus.kstreamlined.kmp.datasource.util

import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.exception.NoDataException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.data.feed
package io.github.reactivecircus.kstreamlined.kmp.datasource

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.annotations.ApolloExperimental
Expand All @@ -15,19 +15,19 @@ import io.github.reactivecircus.kstreamlined.graphql.FeedSourcesQuery
import io.github.reactivecircus.kstreamlined.graphql.type.buildFeedSource
import io.github.reactivecircus.kstreamlined.graphql.type.buildKotlinBlog
import io.github.reactivecircus.kstreamlined.graphql.type.buildKotlinYouTube
import io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper.toModel
import io.github.reactivecircus.kstreamlined.kmp.datasource.mapper.toModel
import io.github.reactivecircus.kstreamlined.kmp.test.utils.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

@ApolloExperimental
class CloudFeedRepoTest {
class CloudFeedDataSourceTest {

private lateinit var mockServer: MockServer

private lateinit var cloudFeedRepo: CloudFeedRepo
private lateinit var cloudFeedDataSource: CloudFeedDataSource

private val dummyFeedSources = FeedSourcesQuery.Data {
feedSources = listOf(
Expand All @@ -53,7 +53,7 @@ class CloudFeedRepoTest {

private suspend fun setUp() {
mockServer = MockServer()
cloudFeedRepo = CloudFeedRepo(
cloudFeedDataSource = CloudFeedDataSource(
apolloClient = ApolloClient.Builder()
.serverUrl(mockServer.url())
.normalizedCache(MemoryCacheFactory())
Expand All @@ -71,7 +71,7 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedSourcesQuery.Data(feedSources = dummyFeedSources)
)
val actual = cloudFeedRepo.loadFeedSources(refresh = true)
val actual = cloudFeedDataSource.loadFeedSources(refresh = true)
assertEquals(dummyFeedSources.map { it.toModel() }, actual)
}

Expand All @@ -80,7 +80,7 @@ class CloudFeedRepoTest {
runTest(before = { setUp() }, after = { tearDown() }) {
mockServer.enqueueString(statusCode = 404)
val exception = assertFailsWith<NoDataException> {
cloudFeedRepo.loadFeedSources(refresh = true)
cloudFeedDataSource.loadFeedSources(refresh = true)
}
assertEquals(404, (exception.cause as ApolloHttpException).statusCode)
}
Expand All @@ -91,7 +91,7 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedSourcesQuery.Data(feedSources = dummyFeedSources)
)
val actual = cloudFeedRepo.loadFeedSources(refresh = false)
val actual = cloudFeedDataSource.loadFeedSources(refresh = false)
assertEquals(dummyFeedSources.map { it.toModel() }, actual)
}

Expand All @@ -102,11 +102,11 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedSourcesQuery.Data(feedSources = dummyFeedSources)
)
cloudFeedRepo.loadFeedSources(refresh = false)
cloudFeedDataSource.loadFeedSources(refresh = false)

// 2nd request to consume cache
mockServer.enqueueString(statusCode = 404)
val actual = cloudFeedRepo.loadFeedSources(refresh = false)
val actual = cloudFeedDataSource.loadFeedSources(refresh = false)
assertEquals(dummyFeedSources.map { it.toModel() }, actual)
}

Expand All @@ -115,7 +115,7 @@ class CloudFeedRepoTest {
runTest(before = { setUp() }, after = { tearDown() }) {
mockServer.enqueueString(statusCode = 404)
val exception = assertFailsWith<NoDataException> {
cloudFeedRepo.loadFeedSources(refresh = false)
cloudFeedDataSource.loadFeedSources(refresh = false)
}
assertTrue(exception.cause is CacheMissException)
}
Expand All @@ -126,7 +126,7 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedEntriesQuery.Data(feedEntries = dummyFeedEntries)
)
val actual = cloudFeedRepo.loadFeedEntries(
val actual = cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = true,
)
Expand All @@ -138,7 +138,7 @@ class CloudFeedRepoTest {
runTest(before = { setUp() }, after = { tearDown() }) {
mockServer.enqueueString(statusCode = 404)
val exception = assertFailsWith<NoDataException> {
cloudFeedRepo.loadFeedEntries(
cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = true,
)
Expand All @@ -152,7 +152,7 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedEntriesQuery.Data(feedEntries = dummyFeedEntries)
)
val actual = cloudFeedRepo.loadFeedEntries(
val actual = cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = false,
)
Expand All @@ -166,14 +166,14 @@ class CloudFeedRepoTest {
mockServer.enqueueData(
FeedEntriesQuery.Data(feedEntries = dummyFeedEntries)
)
cloudFeedRepo.loadFeedEntries(
cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = false,
)

// 2nd request to consume cache
mockServer.enqueueString(statusCode = 404)
val actual = cloudFeedRepo.loadFeedEntries(
val actual = cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = false,
)
Expand All @@ -185,7 +185,7 @@ class CloudFeedRepoTest {
runTest(before = { setUp() }, after = { tearDown() }) {
mockServer.enqueueString(statusCode = 404)
val exception = assertFailsWith<NoDataException> {
cloudFeedRepo.loadFeedEntries(
cloudFeedDataSource.loadFeedEntries(
filters = null,
refresh = false,
)
Expand Down
Loading

0 comments on commit f468142

Please sign in to comment.