Skip to content

Commit

Permalink
[feature] : 레트로핏 모듈 #9
Browse files Browse the repository at this point in the history
  • Loading branch information
PicturePark1101 committed Dec 24, 2023
1 parent 76f79fe commit 3efc692
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion app/src/main/java/ddwucom/moblie/hilo/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ddwucom.moblie.hilo.di

import com.google.gson.Gson
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import ddwucom.moblie.hilo.BuildConfig
import ddwucom.moblie.hilo.data.repository.LocationApiRepository
import ddwucom.moblie.hilo.data.service.LocationApiService
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
Expand All @@ -14,7 +18,7 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
val BASE_URL = ""
val BASE_URL = "http://apis.data.go.kr/B551014/SRVC_API_SFMS_FACI/"

@Provides
@Singleton
Expand Down Expand Up @@ -47,6 +51,47 @@ object NetworkModule {
return GsonConverterFactory.create()
}

@Provides
@Singleton
fun provideApiService(retrofit: Retrofit): LocationApiService {
return retrofit.create(LocationApiService::class.java)
}

private fun getLoggingInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }

// @Provides
// fun provideBaseUrl() = "http://apis.data.go.kr/B551014/SRVC_API_SFMS_FACI/"
//
// @Singleton
// @Provides
// fun provideOkHttpClient() = if (BuildConfig.DEBUG) {
// val loggingInterceptor = HttpLoggingInterceptor()
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
// OkHttpClient.Builder()
// .addInterceptor(loggingInterceptor)
// .build()
// } else {
// OkHttpClient.Builder().build()
// }
//
// @Singleton
// @Provides
// fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
// return Retrofit.Builder()
// .client(okHttpClient)
// .baseUrl(provideBaseUrl())
// .addConverterFactory(GsonConverterFactory.create())
// .build()
// }
//
// @Provides
// @Singleton
// fun provideApiService(retrofit: Retrofit): LocationApiService {
// return retrofit.create(LocationApiService::class.java)
// }
//
// @Singleton
// @Provides
// fun provideMainRepository(apiService: LocationApiService) = LocationApiRepository(apiService)
}

0 comments on commit 3efc692

Please sign in to comment.