Skip to content

Commit

Permalink
Merge pull request #59 from Nexters/refactor/domain-layer
Browse files Browse the repository at this point in the history
Refactor/layer
  • Loading branch information
eshc123 authored Sep 22, 2024
2 parents 6fe9de5 + 7e3e4ec commit 445ad36
Show file tree
Hide file tree
Showing 224 changed files with 2,124 additions and 1,041 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,11 @@ dependencies {
implementation(project(":feature:main"))
implementation(project(":feature:login"))
implementation(project(":core:designsystem"))
implementation(project(":core:data"))

implementation(project(":core:data:auth"))
implementation(project(":core:data:common"))
implementation(project(":core:data:mission"))
implementation(project(":core:data:onboarding"))
implementation(project(":core:data:setting"))
implementation(project(":core:data:user"))
}
File renamed without changes.
10 changes: 6 additions & 4 deletions core/data/build.gradle.kts → core/data/auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

android {
namespace = "com.goalpanzi.mission_mate.core.data"
namespace = "com.goalpanzi.mission_mate.core.data.auth"
compileSdk = 34

defaultConfig {
Expand Down Expand Up @@ -45,7 +45,9 @@ dependencies {
ksp(libs.hilt.compiler)
implementation(libs.hilt.android)

implementation(project(":core:domain"))
implementation(project(":core:model"))
implementation(project(":core:data:common"))
implementation(project(":core:domain:common"))
implementation(project(":core:domain:auth"))
implementation(project(":core:network"))
}
implementation(project(":core:datastore"))
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class * { *; }
-keep interface * { *; }

# Keep Dependency Injection Framework related classes and methods
-keep class dagger.hilt.** { *; }
-keep class javax.inject.** { *; }
-keep class javax.annotation.** { *; }
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.data.auth.di

import com.goalpanzi.mission_mate.core.data.auth.repository.AuthRepositoryImpl
import com.goalpanzi.mission_mate.core.domain.auth.repository.AuthRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
internal abstract class AuthDataModule {

@Binds
abstract fun bindLoginRepository(impl: AuthRepositoryImpl): AuthRepository

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.data.auth.mapper

import com.goalpanzi.mission_mate.core.data.common.mapper.toModel
import com.goalpanzi.mission_mate.core.domain.auth.model.GoogleLogin
import com.goalpanzi.mission_mate.core.domain.common.model.user.CharacterType
import com.goalpanzi.mission_mate.core.network.model.response.GoogleLoginResponse

fun GoogleLoginResponse.toModel() : GoogleLogin {
return GoogleLogin(
accessToken = accessToken,
refreshToken = refreshToken,
nickname = nickname,
characterType = characterType?.toModel() ?: CharacterType.RABBIT,
isProfileSet = isProfileSet,
memberId = memberId
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.goalpanzi.mission_mate.core.data.auth.repository

import com.goalpanzi.mission_mate.core.data.auth.mapper.toModel
import com.goalpanzi.mission_mate.core.data.common.handleResult
import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.domain.auth.repository.AuthRepository
import com.goalpanzi.mission_mate.core.domain.common.DomainResult
import com.goalpanzi.mission_mate.core.domain.common.convert
import com.goalpanzi.mission_mate.core.network.model.request.GoogleLoginRequest
import com.goalpanzi.mission_mate.core.network.service.LoginService
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val loginService: LoginService,
private val authDataSource: AuthDataSource
): AuthRepository {

override suspend fun requestGoogleLogin(email: String) = handleResult {
val request = GoogleLoginRequest(email = email)
loginService.requestGoogleLogin(request)
}.convert {
it.toModel()
}

override suspend fun requestLogout(): DomainResult<Unit> = handleResult {
loginService.requestLogout()
}

override suspend fun requestAccountDelete(): DomainResult<Unit> = handleResult {
loginService.requestDeleteAccount()
}

override fun getAccessToken(): Flow<String?> = authDataSource.getAccessToken()

override fun getRefreshToken(): Flow<String?> = authDataSource.getRefreshToken()

override fun setAccessToken(accessToken: String): Flow<Unit> = authDataSource.setAccessToken(accessToken)

override fun setRefreshToken(refreshToken: String): Flow<Unit> = authDataSource.setRefreshToken(refreshToken)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.goalpanzi.mission_mate.core.domain
package com.goalpanzi.mission_mate.core.data.auth

import org.junit.Test

Expand All @@ -14,4 +14,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

android {
namespace = "com.goalpanzi.mission_mate.core.domain"
namespace = "com.goalpanzi.mission_mate.core.data.common"
compileSdk = 34

defaultConfig {
Expand Down Expand Up @@ -40,11 +40,12 @@ dependencies {

implementation(libs.bundles.test)
implementation(libs.bundles.coroutines)
implementation(libs.retrofit)

ksp(libs.hilt.compiler)
implementation(libs.hilt.android)
implementation(project(":core:domain:common"))

implementation(project(":core:model"))
implementation(project(":core:datastore"))
implementation(project(":core:network"))
}
implementation(project(":core:datastore"))
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class * { *; }
-keep interface * { *; }

# Keep Dependency Injection Framework related classes and methods
-keep class dagger.hilt.** { *; }
-keep class javax.inject.** { *; }
-keep class javax.annotation.** { *; }
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.goalpanzi.mission_mate.core.data.common

import com.goalpanzi.mission_mate.core.domain.common.DomainResult
import retrofit2.HttpException
import retrofit2.Response

suspend fun <T : Any> handleResult(execute: suspend () -> Response<T>): DomainResult<T> {
return try {
val response = execute()
if (response.isSuccessful) {
val body = response.body()
if (body != null) {
DomainResult.Success(body)
} else {
DomainResult.Error(response.code(), "Response body is null")
}
} else {
DomainResult.Error(response.code(), response.errorBody()?.string())
}
} catch (e: HttpException) {
DomainResult.Error(e.code(), e.message())
} catch (e: Throwable) {
DomainResult.Exception(e)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.goalpanzi.mission_mate.core.data.di
package com.goalpanzi.mission_mate.core.data.common.di

import dagger.Module
import dagger.Provides
Expand All @@ -24,4 +24,4 @@ interface DispatchersModule {
@Dispatcher(MissionMateDispatcher.IO)
fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.goalpanzi.mission_mate.core.data.common.mapper

import com.goalpanzi.mission_mate.core.domain.common.model.user.CharacterType
import com.goalpanzi.mission_mate.core.domain.common.model.user.UserProfile
import com.goalpanzi.mission_mate.core.network.model.response.CharacterTypeResponse
import com.goalpanzi.mission_mate.core.network.model.response.ProfileResponse

fun ProfileResponse.toModel() : UserProfile {
return UserProfile(
nickname = nickname,
characterType = characterType.toModel()
)
}

fun CharacterTypeResponse.toModel() : CharacterType {
return try {
CharacterType.valueOf(this.name)
}catch (e: Exception){
CharacterType.RABBIT
}
}

fun CharacterType.toResponse() : CharacterTypeResponse {
return try {
CharacterTypeResponse.valueOf(this.name)
}catch (e: Exception){
CharacterTypeResponse.RABBIT
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.data.common

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
File renamed without changes.
53 changes: 53 additions & 0 deletions core/data/mission/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.hilt.android)
alias(libs.plugins.kotlin.ksp)
}

android {
namespace = "com.goalpanzi.mission_mate.core.data.mission"
compileSdk = 34

defaultConfig {
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}

dependencies {

implementation(libs.bundles.test)
implementation(libs.bundles.coroutines)
implementation(libs.retrofit)

ksp(libs.hilt.compiler)
implementation(libs.hilt.android)

implementation(project(":core:data:common"))
implementation(project(":core:domain:common"))
implementation(project(":core:domain:mission"))
implementation(project(":core:network"))
implementation(project(":core:datastore"))
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,4 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class * { *; }
-keep interface * { *; }

# Keep Dependency Injection Framework related classes and methods
-keep class dagger.hilt.** { *; }
-keep class javax.inject.** { *; }
-keep class javax.annotation.** { *; }
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.goalpanzi.mission_mate.core.board.di

import com.goalpanzi.mission_mate.core.board.repository.MissionRepositoryImpl
import com.goalpanzi.mission_mate.core.domain.mission.repository.MissionRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
internal abstract class MissionDataModule {

@Binds
abstract fun bindMissionRepository(impl: MissionRepositoryImpl): MissionRepository

}
Loading

0 comments on commit 445ad36

Please sign in to comment.