-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from meongmory/feature/clean
[feature/clean] 클린아키텍쳐 구조, 모듈화 구현
- Loading branch information
Showing
55 changed files
with
897 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/meongmoryteam/meongmory/MeongMoryApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.meongmoryteam.meongmory | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class MeongMoryApplication : Application() { | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/meongmoryteam/meongmory/di/NetworkModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.meongmoryteam.meongmory.di | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import com.meongmoryteam.data.service.ExampleApi | ||
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 retrofit2.Retrofit | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
private val contentType = "application/json".toMediaType() | ||
private val json = Json { ignoreUnknownKeys = true } | ||
|
||
private const val BASE_URL = "https://www.test.com/" | ||
|
||
@Provides | ||
@Singleton | ||
fun provideClient(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.connectTimeout(100, TimeUnit.SECONDS) | ||
.readTimeout(100, TimeUnit.SECONDS) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRetrofit(client: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(json.asConverterFactory(contentType)) | ||
.client(client) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideApi(retrofit: Retrofit): ExampleApi { | ||
return retrofit.create(ExampleApi::class.java) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/meongmoryteam/meongmory/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.meongmoryteam.meongmory.di | ||
|
||
import com.meongmoryteam.data.datasource.FoodDataSource | ||
import com.meongmoryteam.data.datasource.FoodDataSourceImpl | ||
import com.meongmoryteam.data.repository.FoodRepositoryImpl | ||
import com.meongmoryteam.domain.repository.FoodRepository | ||
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 RepositoryModule { | ||
|
||
@Singleton | ||
@Binds | ||
abstract fun bindFoodRepository( | ||
foodRepositoryImpl: FoodRepositoryImpl, | ||
) : FoodRepository | ||
|
||
@Singleton | ||
@Binds | ||
abstract fun bindFoodV2DataSource( | ||
foodDataSourceImpl: FoodDataSourceImpl | ||
): FoodDataSource | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
alias(libs.plugins.kotlinAndroid) | ||
alias(libs.plugins.android.library) | ||
id("dagger.hilt.android.plugin") | ||
id("kotlin-kapt") | ||
id("kotlinx-serialization") | ||
} | ||
|
||
android { | ||
namespace = "com.meongmoryteam.data" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
minSdk = 28 | ||
targetSdk = 33 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":domain")) | ||
|
||
//Retrofit | ||
implementation(libs.retrofit) | ||
implementation(libs.okhttp.logging.interceptor) | ||
|
||
// Hilt | ||
implementation(libs.hilt) | ||
kapt(libs.hilt.testing.compiler) | ||
|
||
// Serialization | ||
implementation(libs.serialization) | ||
implementation(libs.kotlin.serilization) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
data/src/androidTest/java/com/meongmoryteam/data/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.meongmoryteam.data | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.meongmoryteam.data", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
</manifest> |
8 changes: 8 additions & 0 deletions
8
data/src/main/java/com/meongmoryteam/data/datasource/FoodDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.meongmoryteam.data.datasource | ||
|
||
import com.meongmoryteam.data.model.WeekFoodResponse | ||
|
||
interface FoodDataSource { | ||
|
||
suspend fun weekGetFoodArea(s: String): Result<WeekFoodResponse> | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/meongmoryteam/data/datasource/FoodDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.meongmoryteam.data.datasource | ||
|
||
import com.meongmoryteam.data.model.WeekFoodResponse | ||
import com.meongmoryteam.data.service.ExampleApi | ||
import javax.inject.Inject | ||
|
||
class FoodDataSourceImpl @Inject constructor( | ||
private val exampleApi: ExampleApi | ||
) : FoodDataSource { | ||
override suspend fun weekGetFoodArea(s: String): Result<WeekFoodResponse> { | ||
return runCatching { exampleApi.weekGetFoodArea(s) } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
data/src/main/java/com/meongmoryteam/data/model/GetWeekFood.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.meongmoryteam.data.model | ||
|
||
import com.meongmoryteam.domain.model.ResponseWeekFoodEntity | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class WeekFoodResponse( | ||
val success : Boolean, | ||
val message : String, | ||
val localDateTime : String, | ||
val httpStatus : String, | ||
val httpCode : Int, | ||
val data : List<WeekFoodResult>, | ||
) { | ||
@Serializable | ||
data class WeekFoodResult( | ||
val mealId: Int, | ||
val toDay: String, | ||
val mealType : String, | ||
val statusType : String, | ||
val meals : List<String> | ||
) | ||
} | ||
|
||
fun WeekFoodResponse.toWeekFoodEntity(): ResponseWeekFoodEntity { | ||
val weekFoodResultEntityList = this.data.map { result -> | ||
ResponseWeekFoodEntity.WeekFoodResultEntity( | ||
mealId = result.mealId, | ||
toDay = result.toDay, | ||
mealType = result.mealType, | ||
statusType = result.statusType, | ||
meals = result.meals | ||
) | ||
} | ||
|
||
return ResponseWeekFoodEntity( | ||
success = this.success, | ||
message = this.message, | ||
localDateTime = this.localDateTime, | ||
httpStatus = this.httpStatus, | ||
httpCode = this.httpCode, | ||
data = weekFoodResultEntityList | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/meongmoryteam/data/repository/FoodRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.meongmoryteam.data.repository | ||
|
||
import com.meongmoryteam.data.datasource.FoodDataSource | ||
import com.meongmoryteam.data.model.toWeekFoodEntity | ||
import com.meongmoryteam.domain.model.ResponseWeekFoodEntity | ||
import com.meongmoryteam.domain.repository.FoodRepository | ||
import javax.inject.Inject | ||
|
||
class FoodRepositoryImpl @Inject constructor( | ||
private val foodDataSource: FoodDataSource | ||
) : FoodRepository { | ||
|
||
override suspend fun weekFood(area: String): Result<ResponseWeekFoodEntity> { | ||
return foodDataSource.weekGetFoodArea(area).map { it.toWeekFoodEntity() } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/com/meongmoryteam/data/service/ExampleApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.meongmoryteam.data.service | ||
|
||
import com.meongmoryteam.data.model.WeekFoodResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface ExampleApi { | ||
|
||
@GET("/api/v2/meals/week/{area}") | ||
suspend fun weekGetFoodArea( | ||
@Path("area") area: String | ||
): WeekFoodResponse | ||
} |
Oops, something went wrong.