Skip to content

Commit

Permalink
feat: named을 통해 추상화 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
rhkrwngud445 committed May 29, 2024
1 parent dbeb796 commit a12beda
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import okhttp3.OkHttpClient
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import javax.inject.Named

@Module
@InstallIn(SingletonComponent::class)
Expand Down Expand Up @@ -43,6 +44,7 @@ internal object ApiModule {
.create(GithubApi::class.java)
}

@Named("GithubRawApi")
@Provides
@Singleton
fun provideGitRawApi(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import javax.inject.Named
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
Expand Down Expand Up @@ -48,24 +49,25 @@ internal abstract class DataModule {
@Provides
@Singleton
fun provideSponsorRepository(
githubRawApi: GithubRawApi,
@Named("AssetsGithubRawApi") githubRawApi: GithubRawApi,
): SponsorRepository =
DefaultSponsorRepository(githubRawApi)

@Provides
@Singleton
fun provideSessionRepository(
githubRawApi: GithubRawApi,
@Named("AssetsGithubRawApi") githubRawApi: GithubRawApi,
sessionDataSource: SessionPreferencesDataSource,
): SessionRepository =
DefaultSessionRepository(githubRawApi, sessionDataSource)

@Provides
@Singleton
@Named("AssetsGithubRawApi")
fun provideGithubRawApi(
@ApplicationContext context: Context,
json: Json,
): AssetsGithubRawApi =
): GithubRawApi =
AssetsGithubRawApi(context, json)
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.droidknights.app.core.data.repository

import com.droidknights.app.core.data.api.GithubApi
import com.droidknights.app.core.data.api.fake.AssetsGithubRawApi
import com.droidknights.app.core.data.api.GithubRawApi
import com.droidknights.app.core.data.mapper.toData
import com.droidknights.app.core.data.repository.api.ContributorRepository
import com.droidknights.app.core.model.Contributor
import javax.inject.Inject
import javax.inject.Named

internal class DefaultContributorRepository @Inject constructor(
private val githubApi: GithubApi,
private val githubRawApi: AssetsGithubRawApi,
@Named("AssetsGithubRawApi") private val githubRawApi: GithubRawApi,
) : ContributorRepository {

override suspend fun getContributors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import javax.inject.Inject
import javax.inject.Named

internal class DefaultSessionRepository @Inject constructor(
private val githubRawApi: GithubRawApi,
private val sessionDataSource: SessionPreferencesDataSource
@Named("GithubRawApi") private val sessionDataSource: SessionPreferencesDataSource,
) : SessionRepository {

private var cachedSessions: List<Session> = emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import com.droidknights.app.core.data.mapper.toData
import com.droidknights.app.core.data.repository.api.SponsorRepository
import com.droidknights.app.core.model.Sponsor
import javax.inject.Inject
import javax.inject.Named

internal class DefaultSponsorRepository @Inject constructor(
private val githubRawApi: GithubRawApi,
@Named("GithubRawApi") private val githubRawApi: GithubRawApi,
) : SponsorRepository {

override suspend fun getSponsors(): List<Sponsor> {
Expand Down

0 comments on commit a12beda

Please sign in to comment.