Skip to content

Commit

Permalink
feed-datasource -> networking.
Browse files Browse the repository at this point in the history
  • Loading branch information
ychescale9 committed Jan 7, 2024
1 parent 873d885 commit 6c6d5c9
Show file tree
Hide file tree
Showing 39 changed files with 154 additions and 154 deletions.
8 changes: 4 additions & 4 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ androidComponents {
}

dependencies {
mockImplementation(project(":kmp:feed-datasource:testing"))
demoImplementation(project(":kmp:feed-datasource:edge"))
devImplementation(project(":kmp:feed-datasource:cloud"))
prodImplementation(project(":kmp:feed-datasource:cloud"))
mockImplementation(project(":kmp:networking:testing"))
demoImplementation(project(":kmp:networking:edge"))
devImplementation(project(":kmp:networking:cloud"))
prodImplementation(project(":kmp:networking:cloud"))
implementation(project(":kmp:persistence"))
implementation(project(":kmp:data"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.EdgeFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.networking.EdgeFeedService
import io.github.reactivecircus.kstreamlined.kmp.networking.FeedService
import javax.inject.Singleton

@Module
Expand All @@ -14,7 +14,7 @@ object EdgeDataModule {

@Provides
@Singleton
fun feedDataSource(): FeedDataSource {
return EdgeFeedDataSource()
fun feedService(): FeedService {
return EdgeFeedService()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.CloudFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.networking.CloudFeedService
import io.github.reactivecircus.kstreamlined.kmp.networking.FeedService
import javax.inject.Singleton

@Module
Expand All @@ -15,7 +15,7 @@ object CloudDataModule {

@Provides
@Singleton
fun feedDataSource(apolloClient: ApolloClient): FeedDataSource {
return CloudFeedDataSource(apolloClient)
fun feedService(apolloClient: ApolloClient): FeedService {
return CloudFeedService(apolloClient)
}
}
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.feed.datasource.networking.ApolloClientConfigs
import io.github.reactivecircus.kstreamlined.kmp.networking.apollo.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 @@ -5,7 +5,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.data.feed.FeedRepository
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.networking.FeedService
import javax.inject.Singleton

@Module
Expand All @@ -14,7 +14,7 @@ object DataModule {

@Provides
@Singleton
fun feedRepository(feedDataSource: FeedDataSource): FeedRepository {
return FeedRepository(feedDataSource)
fun feedRepository(feedService: FeedService): FeedRepository {
return FeedRepository(feedService)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FakeFeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.networking.FakeFeedService
import io.github.reactivecircus.kstreamlined.kmp.networking.FeedService
import javax.inject.Singleton

@Module
Expand All @@ -14,7 +14,7 @@ object MockDataModule {

@Provides
@Singleton
fun feedDataSource(): FeedDataSource {
return FakeFeedDataSource()
fun feedService(): FeedService {
return FakeFeedService()
}
}
2 changes: 1 addition & 1 deletion kmp/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
implementation(project(":kmp:feed-datasource:common"))
implementation(project(":kmp:networking:common"))
implementation(project(":kmp:persistence"))
api(project(":kmp:model"))
implementation(libs.kotlinx.coroutines.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package io.github.reactivecircus.kstreamlined.kmp.data.feed

import co.touchlab.kermit.Logger
import io.github.reactivecircus.kstreamlined.kmp.data.feed.mapper.asExternalModel
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.FeedDataSource
import io.github.reactivecircus.kstreamlined.kmp.model.feed.FeedItem
import io.github.reactivecircus.kstreamlined.kmp.model.feed.FeedOrigin
import io.github.reactivecircus.kstreamlined.kmp.model.feed.KotlinWeeklyIssueItem
import io.github.reactivecircus.kstreamlined.kmp.networking.FeedService
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.datetime.toInstant

public class FeedRepository(
private val feedDataSource: FeedDataSource
private val feedService: FeedService
) {

public val feedSyncState: Flow<FeedSyncState> = emptyFlow()

public suspend fun syncNow() {
feedDataSource.loadFeedEntries(null, true).also {
feedService.fetchFeedEntries(null, true).also {
Logger.i("<<Number of entries: ${it.size}>>")
it.forEach { entry ->
Logger.i("${entry::class.simpleName}: ${entry.title}, ${entry.publishTime}}")
Expand Down Expand Up @@ -72,7 +72,7 @@ public class FeedRepository(

public suspend fun loadKotlinWeeklyIssue(url: String): List<KotlinWeeklyIssueItem> {
// TODO persist fetched entry to DB
return feedDataSource.loadKotlinWeeklyIssue(url).map {
return feedService.fetchKotlinWeeklyIssue(url).map {
it.asExternalModel()
}
}
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

import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.KotlinWeeklyIssueEntry
import io.github.reactivecircus.kstreamlined.kmp.model.feed.KotlinWeeklyIssueItem
import io.github.reactivecircus.kstreamlined.kmp.networking.model.KotlinWeeklyIssueEntry

internal fun KotlinWeeklyIssueEntry.asExternalModel(): KotlinWeeklyIssueItem {
return KotlinWeeklyIssueItem(
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

import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.KotlinWeeklyIssueEntry
import io.github.reactivecircus.kstreamlined.kmp.model.feed.KotlinWeeklyIssueItem
import io.github.reactivecircus.kstreamlined.kmp.networking.model.KotlinWeeklyIssueEntry
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down

This file was deleted.

This file was deleted.

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

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.graphql.KotlinWeeklyIssueQuery
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.mapper.asApolloModel
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.mapper.asExternalModel
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.FeedSource
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.KotlinWeeklyIssueEntry
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.networking.defaultFetchPolicy
import io.github.reactivecircus.kstreamlined.kmp.networking.apollo.defaultFetchPolicy
import io.github.reactivecircus.kstreamlined.kmp.networking.mapper.asApolloModel
import io.github.reactivecircus.kstreamlined.kmp.networking.mapper.asExternalModel
import io.github.reactivecircus.kstreamlined.kmp.networking.model.FeedEntry
import io.github.reactivecircus.kstreamlined.kmp.networking.model.FeedSource
import io.github.reactivecircus.kstreamlined.kmp.networking.model.KotlinWeeklyIssueEntry

public class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedDataSource {
public class CloudFeedService(private val apolloClient: ApolloClient) : FeedService {

override suspend fun loadFeedOrigins(refresh: Boolean): List<FeedSource> {
override suspend fun fetchFeedOrigins(refresh: Boolean): List<FeedSource> {
return runCatching {
apolloClient.query(FeedSourcesQuery())
.defaultFetchPolicy(refresh)
Expand All @@ -27,7 +27,7 @@ public class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedD
}.getOrThrow().mapNotNull { it.asExternalModel() }
}

override suspend fun loadFeedEntries(
override suspend fun fetchFeedEntries(
filters: List<FeedSource.Key>?,
refresh: Boolean,
): List<FeedEntry> {
Expand All @@ -46,7 +46,7 @@ public class CloudFeedDataSource(private val apolloClient: ApolloClient) : FeedD
}.getOrThrow().map { it.asExternalModel() }
}

override suspend fun loadKotlinWeeklyIssue(
override suspend fun fetchKotlinWeeklyIssue(
url: String
): List<KotlinWeeklyIssueEntry> {
return runCatching {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.reactivecircus.kstreamlined.kmp.feed.datasource.networking
package io.github.reactivecircus.kstreamlined.kmp.networking.apollo

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.feed.datasource.networking
package io.github.reactivecircus.kstreamlined.kmp.networking.apollo

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

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

internal fun FeedEntriesQuery.FeedEntry.asExternalModel(): 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.feed.datasource.mapper
package io.github.reactivecircus.kstreamlined.kmp.networking.mapper

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

internal fun FeedSource.Key.asApolloModel(): FeedSourceKey {
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.feed.datasource.mapper
package io.github.reactivecircus.kstreamlined.kmp.networking.mapper

import io.github.reactivecircus.kstreamlined.graphql.KotlinWeeklyIssueQuery
import io.github.reactivecircus.kstreamlined.graphql.type.KotlinWeeklyIssueEntryGroup
import io.github.reactivecircus.kstreamlined.kmp.feed.datasource.model.KotlinWeeklyIssueEntry
import io.github.reactivecircus.kstreamlined.kmp.networking.model.KotlinWeeklyIssueEntry

internal fun KotlinWeeklyIssueQuery.KotlinWeeklyIssueEntry.asExternalModel(): KotlinWeeklyIssueEntry? {
return KotlinWeeklyIssueEntry(
Expand Down
Loading

0 comments on commit 6c6d5c9

Please sign in to comment.