Skip to content

Commit

Permalink
Merge pull request #15 from meongmory/feature/clean
Browse files Browse the repository at this point in the history
[feature/clean] 클린아키텍쳐 구조, 모듈화 구현
  • Loading branch information
SsongSik authored Jul 19, 2023
2 parents 82d8f94 + 22ba473 commit a059fb3
Show file tree
Hide file tree
Showing 55 changed files with 897 additions and 7 deletions.
18 changes: 18 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
id("dagger.hilt.android.plugin")
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -51,6 +53,10 @@ android {
}

dependencies {
implementation(project(":presentation"))
implementation(project(":domain"))
implementation(project(":data"))

implementation(libs.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.activity.compose)
Expand All @@ -66,4 +72,16 @@ dependencies {
androidTestImplementation(libs.ui.test.junit4)
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)

// Hilt
implementation(libs.hilt)
kapt(libs.hilt.testing.compiler)

// Retrofit
implementation(libs.retrofit)
implementation(libs.okhttp.logging.interceptor)

// Serialization
implementation(libs.serialization)
implementation(libs.kotlin.serilization)
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".MeongMoryApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.Meongmory"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name="com.meongmoryteam.presentation.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Meongmory">
Expand Down
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 app/src/main/java/com/meongmoryteam/meongmory/di/NetworkModule.kt
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)
}
}
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
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ buildscript {
dependencies {
classpath(libs.kotlin.gradleplugin)
classpath(libs.agp)
classpath(libs.hilt.plugin)
}
}

Expand All @@ -17,6 +18,7 @@ plugins {
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.serilization) apply false
}

tasks.register("clean", Delete::class) {
Expand Down
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
53 changes: 53 additions & 0 deletions data/build.gradle.kts
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)
}
21 changes: 21 additions & 0 deletions data/proguard-rules.pro
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
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)
}
}
6 changes: 6 additions & 0 deletions data/src/main/AndroidManifest.xml
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>
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>
}
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 data/src/main/java/com/meongmoryteam/data/model/GetWeekFood.kt
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
)
}
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 data/src/main/java/com/meongmoryteam/data/service/ExampleApi.kt
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
}
Loading

0 comments on commit a059fb3

Please sign in to comment.