Skip to content

Commit

Permalink
Issues #287 chore: data-remote 모듈로 분리 및 의존성 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Feb 7, 2023
1 parent 70d5f50 commit 3a6298f
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 93 deletions.
9 changes: 3 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
versionCode = 1
versionName = "1.0.0"

buildConfigField("String", "kakaoSearchId", getApiKey("kakao_search_id"))
manifestPlaceholders["naver_map_api_id"] = getApiKey("naver_map_api_id")
val naverMapApiId = gradleLocalProperties(rootDir).getProperty("naver_map_api_id")
manifestPlaceholders["naver_map_api_id"] = naverMapApiId
}

buildFeatures {
Expand All @@ -40,6 +40,7 @@ dependencies {
implementation(projects.domain)
implementation(projects.presentation)
implementation(projects.data)
implementation(projects.dataRemote)

implementation(libs.androidX.hilt.work)
implementation(libs.androidX.work.runtime.ktx)
Expand Down Expand Up @@ -69,7 +70,3 @@ dependencies {
kapt {
useBuildCache = true
}

fun getApiKey(propertyKey: String): String {
return gradleLocalProperties(rootDir).getProperty(propertyKey)
}
31 changes: 31 additions & 0 deletions data-remote/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("beep.android.library")
id("beep.android.hilt")
alias(libs.plugins.ksp)
}

android {
namespace = "com.lighthouse.data.remote"

defaultConfig {
val kakaoSearchId = gradleLocalProperties(rootDir).getProperty("kakao_search_id")
buildConfigField("String", "kakaoSearchId", kakaoSearchId)
}
}

dependencies {
implementation(projects.core)
implementation(projects.coreAndroid)
implementation(projects.model)
implementation(projects.common)
implementation(projects.commonAndroid)
implementation(projects.data)

implementation(libs.squareup.retrofit2)
implementation(libs.squareup.retrofit2.converter.moshi)

implementation(libs.timber)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.lighthouse.network
package com.lighthouse.data.remote.api

import com.lighthouse.model.BrandPlaceInfoDataContainer
import com.lighthouse.data.remote.model.BrandPlaceInfoDataContainer
import retrofit2.http.GET
import retrofit2.http.Query

interface NetworkApiService {
internal interface KakaoApiService {

@GET("v2/local/search/keyword.json")
suspend fun getAllBrandPlaceInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.lighthouse.data.remote.di

import com.lighthouse.data.remote.api.KakaoApiService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import javax.inject.Singleton

@Suppress("unused")
@Module
@InstallIn(SingletonComponent::class)
internal object ApiModule {
@Provides
@Singleton
fun provideApiService(
retrofit: Retrofit
): KakaoApiService {
return retrofit.create(KakaoApiService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lighthouse.data.remote.di

import com.lighthouse.data.remote.repository.BrandRemoteRepositoryImpl
import com.lighthouse.repository.brand.BrandRemoteRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Suppress("unused")
@Module
@InstallIn(SingletonComponent::class)
internal abstract class DataModule {

@Binds
abstract fun bindsRemoteRepository(
repository: BrandRemoteRepositoryImpl
): BrandRemoteRepository
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.lighthouse.di
package com.lighthouse.data.remote.di

import com.lighthouse.network.NetworkApiService
import com.lighthouse.data.remote.utils.HTTPRequestInterceptor
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -12,16 +11,13 @@ import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import javax.inject.Singleton

@Suppress("unused")
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
internal object NetworkModule {

private const val KAKAO_URL = "https://dapi.kakao.com/"

private val moshi = Moshi.Builder()
.addLast(KotlinJsonAdapterFactory())
.build()

@Provides
@Singleton
fun provideOkHttpClient(): OkHttpClient {
Expand All @@ -32,17 +28,14 @@ object NetworkModule {

@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
fun provideRetrofit(
okHttpClient: OkHttpClient,
moshi: Moshi
): Retrofit {
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl(KAKAO_URL)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
}

@Provides
@Singleton
fun provideApiService(retrofit: Retrofit): NetworkApiService {
return retrofit.create(NetworkApiService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.lighthouse.mapper
package com.lighthouse.data.remote.mapper

import com.lighthouse.beep.model.brand.BrandPlaceInfo
import com.lighthouse.model.BrandPlaceInfoDataContainer
import com.lighthouse.data.remote.model.BrandPlaceInfoDataContainer

internal fun List<BrandPlaceInfoDataContainer.BrandPlaceInfoData>.toDomain(brandName: String): List<BrandPlaceInfo> {
internal fun List<BrandPlaceInfoDataContainer.BrandPlaceInfoData>.toDomain(
brandName: String
): List<BrandPlaceInfo> {
return this.map {
BrandPlaceInfo(
addressName = it.addressName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.lighthouse.model
package com.lighthouse.data.remote.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class BrandPlaceInfoDataContainer(
internal data class BrandPlaceInfoDataContainer(
val documents: List<BrandPlaceInfoData>,
val meta: Meta
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.lighthouse.data.remote.repository

import com.lighthouse.beep.model.brand.BrandPlaceInfo
import com.lighthouse.beep.model.error.BeepError
import com.lighthouse.beep.model.location.Dms
import com.lighthouse.common.utils.geography.LocationConverter
import com.lighthouse.data.remote.api.KakaoApiService
import com.lighthouse.data.remote.mapper.toDomain
import com.lighthouse.repository.brand.BrandRemoteRepository
import java.net.UnknownHostException
import javax.inject.Inject

internal class BrandRemoteRepositoryImpl @Inject constructor(
private val kakaoApiService: KakaoApiService
) : BrandRemoteRepository {

override suspend fun getBrandPlaceInfo(
brandName: String,
x: Dms,
y: Dms,
size: Int
): Result<List<BrandPlaceInfo>> {
val vertex = LocationConverter.getVertex(x, y)

return try {
val list = kakaoApiService.getAllBrandPlaceInfo(
brandName,
vertex,
size
).documents.toDomain(brandName)
Result.success(list)
} catch (unknownHostException: UnknownHostException) {
Result.failure(BeepError.NetworkFailure)
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.lighthouse.di
package com.lighthouse.data.remote.utils

import com.lighthouse.beep.BuildConfig
import com.lighthouse.data.remote.BuildConfig
import okhttp3.Interceptor
import okhttp3.Response

class HTTPRequestInterceptor : Interceptor {
internal class HTTPRequestInterceptor : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response {
val origin = chain.request()
Expand Down

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions data/src/main/java/com/lighthouse/mapper/ErrorMapper.kt

This file was deleted.

9 changes: 0 additions & 9 deletions data/src/main/java/com/lighthouse/model/BeepErrorData.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lighthouse.repository.brand

import com.lighthouse.beep.model.brand.BrandPlaceInfo
import com.lighthouse.beep.model.location.Dms

interface BrandRemoteRepository {
suspend fun getBrandPlaceInfo(
brandName: String,
x: Dms,
y: Dms,
size: Int
): Result<List<BrandPlaceInfo>>
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ includeProject(":common-android", "commons")
includeProject(":common-location", "commons")
includeProject(":common-recognizer", "commons")
includeProject(":data")
includeProject(":data-remote")
includeProject(":presentation")
includeProject(":domain")

0 comments on commit 3a6298f

Please sign in to comment.