Skip to content

Commit

Permalink
[PC-259] Domain - Network 모듈까지 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Jan 1, 2025
1 parent eb5c904 commit d71f586
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/data/src/main/java/com/puzzle/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.puzzle.data.di

import com.puzzle.data.repository.AuthRepositoryImpl
import com.puzzle.domain.repository.AuthRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {

@Binds
@Singleton
abstract fun bindsAuthRepository(
authRepositoryImpl: AuthRepositoryImpl,
): AuthRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.puzzle.data.repository

import com.puzzle.domain.repository.AuthRepository
import com.puzzle.network.source.AuthDataSource
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource,
) : AuthRepository {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.puzzle.domain.repository

interface AuthRepository {
}
17 changes: 17 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ plugins {
android {
namespace = "com.puzzle.network"

buildTypes {
debug {
buildConfigField(
"String",
"PIECE_BASE_URL",
"\"${properties["PIECE_DEV_BASE_URL"]}\"",
)
}
release {
buildConfigField(
"String",
"PIECE_BASE_URL",
"\"${properties["PIECE_PROD_BASE_URL"]}\"",
)
}
}

buildFeatures {
buildConfig = true
}
Expand Down
4 changes: 4 additions & 0 deletions core/network/src/main/java/com/puzzle/network/api/PieceApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.puzzle.network.api

interface PieceApi {
}
49 changes: 49 additions & 0 deletions core/network/src/main/java/com/puzzle/network/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.puzzle.network.di

import com.puzzle.network.BuildConfig
import com.puzzle.network.api.PieceApi
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RetrofitModule {

private val json = Json {
ignoreUnknownKeys = true
}

@Singleton
@Provides
fun provideOkHttpClient(): OkHttpClient {
val builder = OkHttpClient.Builder()

if (BuildConfig.DEBUG) {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
builder.addInterceptor(loggingInterceptor)
}

return builder.build()
}

@Singleton
@Provides
fun providesAuthApi(
okHttpClient: OkHttpClient,
): PieceApi = Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.baseUrl(BuildConfig.PIECE_BASE_URL)
.build()
.create(PieceApi::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.puzzle.network.source

import com.puzzle.network.api.PieceApi
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AuthDataSource @Inject constructor(
private val pieceApi: PieceApi,
) {}

0 comments on commit d71f586

Please sign in to comment.