From 0e39bc1b28ee0d5af618f0c7a4c18f68084bcf2c Mon Sep 17 00:00:00 2001 From: murjune Date: Wed, 23 Aug 2023 21:28:33 +0900 Subject: [PATCH 1/5] =?UTF-8?q?#305=20[add(domain)]=20RepresentationRule?= =?UTF-8?q?=20domain=20model=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/rule/RepresentativeRule.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt diff --git a/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt new file mode 100644 index 00000000..09c9a9d0 --- /dev/null +++ b/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt @@ -0,0 +1,15 @@ +package hous.release.domain.entity.rule + +import hous.release.domain.entity.Rule + +data class RepresentativeRule( + override val id: Int = NO_ID, + override val name: String = NO_NAME, + val isRepresent: Boolean = false +) : Rule(id, name) { + + private companion object { + private const val NO_NAME = "제목없음" + private const val NO_ID = -1 + } +} From 431c93f319bc00612a28ad25568a8c9d8d87178d Mon Sep 17 00:00:00 2001 From: murjune Date: Wed, 23 Aug 2023 21:32:15 +0900 Subject: [PATCH 2/5] #305 [feat(domain)] GetRepresentativeRulesUseCase --- .../usecase/rule/GetRepresentativeRule.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt diff --git a/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt b/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt new file mode 100644 index 00000000..6c470dca --- /dev/null +++ b/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt @@ -0,0 +1,17 @@ +package hous.release.domain.usecase.rule + +import hous.release.domain.entity.rule.RepresentativeRule +import hous.release.domain.repository.RuleRepository +import javax.inject.Inject + +class GetRepresentativeRulesUseCase @Inject constructor(private val repository: RuleRepository) { + + suspend operator fun invoke(): List = + repository.fetchMainRules().map { mainRule -> + RepresentativeRule( + id = mainRule.id, + name = mainRule.name, + isRepresent = mainRule.isRepresent + ) + } +} From 99b87771c9ed94f279a89050d980fbd5b6a84df0 Mon Sep 17 00:00:00 2001 From: murjune Date: Wed, 23 Aug 2023 21:52:50 +0900 Subject: [PATCH 3/5] =?UTF-8?q?#305=20[refactor(domain)]=20Rule=20->=20Bas?= =?UTF-8?q?eRule=EB=A1=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../release/domain/entity/{Rule.kt => BaseRule.kt} | 2 +- .../hous/release/domain/entity/rule/DetailRule.kt | 4 ++-- .../hous/release/domain/entity/rule/MainRule.kt | 4 ++-- .../domain/entity/rule/RepresentativeRule.kt | 4 ++-- .../hous/release/domain/entity/todo/TodoWithNew.kt | 4 ++-- .../domain/usecase/search/SearchRuleUseCase.kt | 4 ++-- .../domain/usecase/SearchRuleUseCaseTest.kt | 14 +++++++------- 7 files changed, 18 insertions(+), 18 deletions(-) rename domain/src/main/java/hous/release/domain/entity/{Rule.kt => BaseRule.kt} (77%) diff --git a/domain/src/main/java/hous/release/domain/entity/Rule.kt b/domain/src/main/java/hous/release/domain/entity/BaseRule.kt similarity index 77% rename from domain/src/main/java/hous/release/domain/entity/Rule.kt rename to domain/src/main/java/hous/release/domain/entity/BaseRule.kt index 323bdd26..6642b1ec 100644 --- a/domain/src/main/java/hous/release/domain/entity/Rule.kt +++ b/domain/src/main/java/hous/release/domain/entity/BaseRule.kt @@ -1,6 +1,6 @@ package hous.release.domain.entity -abstract class Rule( +abstract class BaseRule( open val id: Int, open val name: String ) diff --git a/domain/src/main/java/hous/release/domain/entity/rule/DetailRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/DetailRule.kt index ccc00779..bf17e277 100644 --- a/domain/src/main/java/hous/release/domain/entity/rule/DetailRule.kt +++ b/domain/src/main/java/hous/release/domain/entity/rule/DetailRule.kt @@ -1,7 +1,7 @@ package hous.release.domain.entity.rule import hous.release.domain.entity.Photo -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule data class DetailRule( override val id: Int = NO_ID, @@ -9,7 +9,7 @@ data class DetailRule( val description: String = NO_DESCRIPTION, val images: List = emptyList(), val updatedAt: String = "" -) : Rule(id, name) { +) : BaseRule(id, name) { companion object { private const val NO_NAME = "제목 없음" private const val NO_DESCRIPTION = "설명 없음" diff --git a/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt index b0a0a867..f1796f20 100644 --- a/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt +++ b/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt @@ -1,6 +1,6 @@ package hous.release.domain.entity.rule -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule data class MainRule( override val id: Int = NO_ID, @@ -8,7 +8,7 @@ data class MainRule( val isRepresent: Boolean = false, val createdAt: String = "", val isNew: Boolean = false -) : Rule(id, name) { +) : BaseRule(id, name) { companion object { private const val NO_NAME = "다른 Rule도 추가해보세요!" private const val NO_ID = -1 diff --git a/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt index 09c9a9d0..2807414d 100644 --- a/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt +++ b/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt @@ -1,12 +1,12 @@ package hous.release.domain.entity.rule -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule data class RepresentativeRule( override val id: Int = NO_ID, override val name: String = NO_NAME, val isRepresent: Boolean = false -) : Rule(id, name) { +) : BaseRule(id, name) { private companion object { private const val NO_NAME = "제목없음" diff --git a/domain/src/main/java/hous/release/domain/entity/todo/TodoWithNew.kt b/domain/src/main/java/hous/release/domain/entity/todo/TodoWithNew.kt index dc1dca5c..8193dd24 100644 --- a/domain/src/main/java/hous/release/domain/entity/todo/TodoWithNew.kt +++ b/domain/src/main/java/hous/release/domain/entity/todo/TodoWithNew.kt @@ -1,9 +1,9 @@ package hous.release.domain.entity.todo -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule data class TodoWithNew( val isNew: Boolean, override val id: Int, override val name: String -) : Rule(id, name) +) : BaseRule(id, name) diff --git a/domain/src/main/java/hous/release/domain/usecase/search/SearchRuleUseCase.kt b/domain/src/main/java/hous/release/domain/usecase/search/SearchRuleUseCase.kt index b3379883..82f4c979 100644 --- a/domain/src/main/java/hous/release/domain/usecase/search/SearchRuleUseCase.kt +++ b/domain/src/main/java/hous/release/domain/usecase/search/SearchRuleUseCase.kt @@ -1,13 +1,13 @@ package hous.release.domain.usecase.search -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule import hous.release.domain.usecase.search.matcher.StringMatcher import javax.inject.Inject class SearchRuleUseCase @Inject constructor( private val matcher: StringMatcher ) { - operator fun invoke(search: String, rules: List): List { + operator fun invoke(search: String, rules: List): List { return rules.filter { rule -> matcher.isMatched(search, rule.name) } diff --git a/domain/src/test/java/hous/release/domain/usecase/SearchRuleUseCaseTest.kt b/domain/src/test/java/hous/release/domain/usecase/SearchRuleUseCaseTest.kt index eb4fe2ad..80e6fad7 100644 --- a/domain/src/test/java/hous/release/domain/usecase/SearchRuleUseCaseTest.kt +++ b/domain/src/test/java/hous/release/domain/usecase/SearchRuleUseCaseTest.kt @@ -1,7 +1,7 @@ package hous.release.domain.usecase import com.google.common.truth.Truth.assertThat -import hous.release.domain.entity.Rule +import hous.release.domain.entity.BaseRule import hous.release.domain.usecase.search.SearchRuleUseCase import hous.release.domain.usecase.search.matcher.RuleNameMatcher import hous.release.domain.usecase.search.strategy.MixedEnKrMatchStrategy @@ -14,14 +14,14 @@ internal class SearchRuleUseCaseTest { val isNew: Boolean = false, override val id: Int = 0, override val name: String = "" - ) : Rule(id, name) + ) : BaseRule(id, name) @Test fun `rule의 name에 검색값이 매칭되는 rule을 반환한다`() { // given val searchUseCase = SearchRuleUseCase(RuleNameMatcher(MixedEnKrMatchStrategy())) - val rules: List = + val rules: List = listOf( MainTodo(name = "이준원"), MainTodo(name = " 이준원MURJUNE "), @@ -29,12 +29,12 @@ internal class SearchRuleUseCaseTest { MainTodo(name = "이#준@원") ) // when - val res: List = searchUseCase("ㄱㄱ", rules) - val res2: List = searchUseCase("ㅇㅈㅇ", rules) - val res3: List = searchUseCase("muㅕrj&une", rules) + val res: List = searchUseCase("ㄱㄱ", rules) + val res2: List = searchUseCase("ㅇㅈㅇ", rules) + val res3: List = searchUseCase("muㅕrj&une", rules) // then assertAll( - { assertThat(res).isEqualTo(emptyList()) }, + { assertThat(res).isEqualTo(emptyList()) }, { assertThat(res2).isEqualTo(rules) }, { assertThat(res3).isEqualTo( From 3ddb91ce401ee6327bf90065c8b9a36fac0f60df Mon Sep 17 00:00:00 2001 From: murjune Date: Wed, 23 Aug 2023 21:57:27 +0900 Subject: [PATCH 4/5] =?UTF-8?q?#305=20[refactor(domain,=20data)]=20MainRul?= =?UTF-8?q?e=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20->=20Rule=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/main/MainRuleContent.kt | 12 +++++------ .../our_rules/component/main/MainRuleList.kt | 16 +++++++-------- .../our_rules/screen/MainRuleScreen.kt | 12 +++++------ .../our_rules/viewmodel/MainRuleViewModel.kt | 16 +++++++-------- .../release/data/datasource/RuleDataSource.kt | 6 +++--- ...{MainRulesResponse.kt => RulesResponse.kt} | 10 +++++----- .../data/repository/RuleRepositoryImpl.kt | 6 +++--- .../hous/release/data/service/RuleService.kt | 4 ++-- .../data/repository/RuleRepositoryImplTest.kt | 20 +++++++++---------- .../release/data/service/RuleServiceTest.kt | 12 +++++------ .../domain/entity/rule/OurRulesContent.kt | 15 -------------- .../entity/rule/{MainRule.kt => Rule.kt} | 2 +- .../domain/repository/RuleRepository.kt | 4 ++-- .../usecase/rule/GetMainRulesUseCase.kt | 10 ---------- .../usecase/rule/GetRepresentativeRule.kt | 2 +- .../domain/usecase/rule/GetRulesUseCase.kt | 10 ++++++++++ 16 files changed, 71 insertions(+), 86 deletions(-) rename data/src/main/java/hous/release/data/entity/response/rule/{MainRulesResponse.kt => RulesResponse.kt} (66%) delete mode 100644 domain/src/main/java/hous/release/domain/entity/rule/OurRulesContent.kt rename domain/src/main/java/hous/release/domain/entity/rule/{MainRule.kt => Rule.kt} (95%) delete mode 100644 domain/src/main/java/hous/release/domain/usecase/rule/GetMainRulesUseCase.kt create mode 100644 domain/src/main/java/hous/release/domain/usecase/rule/GetRulesUseCase.kt diff --git a/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleContent.kt b/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleContent.kt index 56e97923..9103f18c 100644 --- a/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleContent.kt +++ b/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleContent.kt @@ -20,12 +20,12 @@ import hous.release.designsystem.component.FabScreenSlot import hous.release.designsystem.component.HousTextField import hous.release.designsystem.component.HousTextFieldMode import hous.release.designsystem.theme.HousTheme -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule import hous.release.feature.todo.R @Composable fun MainRuleContent( - mainRules: List = emptyList(), + mainRules: List = emptyList(), searchQuery: String = "", onSearch: (String) -> Unit = {}, onOpenDetailRule: (Int) -> Unit = {}, @@ -83,10 +83,10 @@ private fun MainRuleScreenPreView2() { HousTheme { MainRuleContent( mainRules = listOf( - MainRule().copy(id = 1, name = "test1", isNew = true), - MainRule().copy(id = 2, name = "test2", isNew = false), - MainRule().copy(id = 3, name = "test3", isNew = true), - MainRule().copy(id = 4, name = "test4", isNew = false) + Rule().copy(id = 1, name = "test1", isNew = true), + Rule().copy(id = 2, name = "test2", isNew = false), + Rule().copy(id = 3, name = "test3", isNew = true), + Rule().copy(id = 4, name = "test4", isNew = false) ) ) } diff --git a/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleList.kt b/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleList.kt index 48bcf25c..327bd6ad 100644 --- a/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleList.kt +++ b/app/src/main/java/hous/release/android/presentation/our_rules/component/main/MainRuleList.kt @@ -24,12 +24,12 @@ import hous.release.designsystem.component.HousRuleSlot import hous.release.designsystem.theme.HousBlue import hous.release.designsystem.theme.HousG5 import hous.release.designsystem.theme.HousTheme -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule @Composable fun MainRuleList( onNavigateToDetailRule: (Int) -> Unit = {}, - mainRules: List = emptyList() + mainRules: List = emptyList() ) { if (mainRules.isEmpty()) { MainRuleEmptyContent() @@ -63,7 +63,7 @@ private fun MainRuleEmptyContent() { @Composable private fun MainRuleItem( onClick: () -> Unit = {}, - mainRule: MainRule = MainRule() + mainRule: Rule = Rule() ) { val focusManager = LocalFocusManager.current HousRuleSlot( @@ -106,10 +106,10 @@ private fun MainRuleContentPreview() { HousTheme { MainRuleList( mainRules = listOf( - MainRule().copy(id = 1, name = "test1", isNew = true), - MainRule().copy(id = 2, name = "test2", isNew = false), - MainRule().copy(id = 3, name = "test3", isNew = true), - MainRule().copy(id = 4, name = "test4", isNew = false) + Rule().copy(id = 1, name = "test1", isNew = true), + Rule().copy(id = 2, name = "test2", isNew = false), + Rule().copy(id = 3, name = "test3", isNew = true), + Rule().copy(id = 4, name = "test4", isNew = false) ) ) } @@ -131,7 +131,7 @@ private fun NewMainRulePreview() { HousTheme { Surface { MainRuleItem( - mainRule = MainRule().copy(isNew = true) + mainRule = Rule().copy(isNew = true) ) } } diff --git a/app/src/main/java/hous/release/android/presentation/our_rules/screen/MainRuleScreen.kt b/app/src/main/java/hous/release/android/presentation/our_rules/screen/MainRuleScreen.kt index 46f874d0..d2d0b907 100644 --- a/app/src/main/java/hous/release/android/presentation/our_rules/screen/MainRuleScreen.kt +++ b/app/src/main/java/hous/release/android/presentation/our_rules/screen/MainRuleScreen.kt @@ -19,14 +19,14 @@ import hous.release.android.presentation.our_rules.component.main.MainRuleConten import hous.release.android.presentation.our_rules.model.DetailRuleUiModel import hous.release.designsystem.theme.HousTheme import hous.release.designsystem.theme.HousWhite -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule import kotlinx.coroutines.launch @OptIn(ExperimentalMaterialApi::class) @Composable fun MainRuleScreen( detailRule: DetailRuleUiModel = DetailRuleUiModel(), - mainRules: List = emptyList(), + mainRules: List = emptyList(), searchQuery: String = "", fetchDetailRuleById: (Int) -> Unit = {}, onSearch: (String) -> Unit = {}, @@ -99,10 +99,10 @@ private fun MainRuleScreenPreView2() { HousTheme { MainRuleScreen( mainRules = listOf( - MainRule().copy(id = 1, name = "test1", isNew = true), - MainRule().copy(id = 2, name = "test2", isNew = false), - MainRule().copy(id = 3, name = "test3", isNew = true), - MainRule().copy(id = 4, name = "test4", isNew = false) + Rule().copy(id = 1, name = "test1", isNew = true), + Rule().copy(id = 2, name = "test2", isNew = false), + Rule().copy(id = 3, name = "test3", isNew = true), + Rule().copy(id = 4, name = "test4", isNew = false) ) ) } diff --git a/app/src/main/java/hous/release/android/presentation/our_rules/viewmodel/MainRuleViewModel.kt b/app/src/main/java/hous/release/android/presentation/our_rules/viewmodel/MainRuleViewModel.kt index 5e577309..f274f8fd 100644 --- a/app/src/main/java/hous/release/android/presentation/our_rules/viewmodel/MainRuleViewModel.kt +++ b/app/src/main/java/hous/release/android/presentation/our_rules/viewmodel/MainRuleViewModel.kt @@ -8,11 +8,11 @@ import hous.release.android.presentation.our_rules.model.DetailRuleUiModel import hous.release.android.util.event.Reducer import hous.release.domain.entity.Photo import hous.release.domain.entity.rule.DetailRule -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule import hous.release.domain.repository.PhotoRepository import hous.release.domain.usecase.rule.CanAddRuleUseCase import hous.release.domain.usecase.rule.GetDetailRuleUseCase -import hous.release.domain.usecase.rule.GetMainRulesUseCase +import hous.release.domain.usecase.rule.GetRulesUseCase import hous.release.domain.usecase.search.SearchRuleUseCase import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.SharingStarted @@ -27,7 +27,7 @@ import javax.inject.Inject @HiltViewModel class MainRuleViewModel @Inject constructor( private val photoSaver: PhotoRepository, - private val getMainRulesUseCase: GetMainRulesUseCase, + private val getMainRulesUseCase: GetRulesUseCase, private val getDetailRuleUseCase: GetDetailRuleUseCase, private val canAddRuleUseCase: CanAddRuleUseCase, private val searcher: SearchRuleUseCase, @@ -102,10 +102,10 @@ sealed class MainRuleSideEffect { sealed class MainRulesEvent { data class LoadedImage(val photos: List) : MainRulesEvent() - data class Refresh(val rules: List) : MainRulesEvent() - data class FetchMainRules(val rules: List) : MainRulesEvent() + data class Refresh(val rules: List) : MainRulesEvent() + data class FetchMainRules(val rules: List) : MainRulesEvent() data class FetchDetailRule(val rule: DetailRule) : MainRulesEvent() - data class SearchRule(val searchQuery: String, val filteredRules: List) : + data class SearchRule(val searchQuery: String, val filteredRules: List) : MainRulesEvent() object DeleteAllFile : MainRulesEvent() @@ -113,7 +113,7 @@ sealed class MainRulesEvent { data class MainRulesState( val detailRule: DetailRuleUiModel = DetailRuleUiModel(), - val originRules: List = emptyList(), - val filteredRules: List = emptyList(), + val originRules: List = emptyList(), + val filteredRules: List = emptyList(), val searchQuery: String = "" ) diff --git a/data/src/main/java/hous/release/data/datasource/RuleDataSource.kt b/data/src/main/java/hous/release/data/datasource/RuleDataSource.kt index 3763273e..d87c3493 100644 --- a/data/src/main/java/hous/release/data/datasource/RuleDataSource.kt +++ b/data/src/main/java/hous/release/data/datasource/RuleDataSource.kt @@ -5,15 +5,15 @@ import hous.release.data.entity.request.rule.AddRulesRequest import hous.release.data.entity.request.rule.UpdateRuleRequest import hous.release.data.entity.response.NoDataResponse import hous.release.data.entity.response.rule.DetailRuleResponse -import hous.release.data.entity.response.rule.MainRulesResponse +import hous.release.data.entity.response.rule.RulesResponse import hous.release.data.service.RuleService import hous.release.data.util.multipart.toImagePart import javax.inject.Inject class RuleDataSource @Inject constructor(private val ruleService: RuleService) { - suspend fun fetchMainRules(): MainRulesResponse = - ruleService.getMainRules().data + suspend fun fetchRules(): RulesResponse = + ruleService.getRules().data suspend fun fetchDetailRuleBy(id: Int): DetailRuleResponse = ruleService.getDetailRuleBy(id).data diff --git a/data/src/main/java/hous/release/data/entity/response/rule/MainRulesResponse.kt b/data/src/main/java/hous/release/data/entity/response/rule/RulesResponse.kt similarity index 66% rename from data/src/main/java/hous/release/data/entity/response/rule/MainRulesResponse.kt rename to data/src/main/java/hous/release/data/entity/response/rule/RulesResponse.kt index 1ca2137b..ccc1bbec 100644 --- a/data/src/main/java/hous/release/data/entity/response/rule/MainRulesResponse.kt +++ b/data/src/main/java/hous/release/data/entity/response/rule/RulesResponse.kt @@ -1,19 +1,19 @@ package hous.release.data.entity.response.rule -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule -data class MainRulesResponse( - val rules: List = emptyList() +data class RulesResponse( + val rules: List = emptyList() ) -data class MainRuleResponse( +data class RuleResponse( val id: Int = -1, val name: String = "", val isRepresent: Boolean = false, val createdAt: String = "", val isNew: Boolean = false ) { - fun toMainRule() = MainRule( + fun toRule() = Rule( id = id, name = name, isRepresent = isRepresent, diff --git a/data/src/main/java/hous/release/data/repository/RuleRepositoryImpl.kt b/data/src/main/java/hous/release/data/repository/RuleRepositoryImpl.kt index 68ecc8d2..830daae0 100644 --- a/data/src/main/java/hous/release/data/repository/RuleRepositoryImpl.kt +++ b/data/src/main/java/hous/release/data/repository/RuleRepositoryImpl.kt @@ -4,7 +4,7 @@ import hous.release.data.datasource.RuleDataSource import hous.release.data.entity.request.rule.AddRulesRequest import hous.release.data.entity.request.rule.UpdateRuleRequest import hous.release.domain.entity.rule.DetailRule -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule import hous.release.domain.repository.RuleRepository import hous.release.domain.util.ApiResult import kotlinx.coroutines.CoroutineDispatcher @@ -21,8 +21,8 @@ class RuleRepositoryImpl @Inject constructor( private val ioDispatcher: CoroutineDispatcher ) : RuleRepository { - override suspend fun fetchMainRules(): List = - ruleDataSource.fetchMainRules().rules.map { it.toMainRule() } + override suspend fun fetchRules(): List = + ruleDataSource.fetchRules().rules.map { it.toRule() } override suspend fun fetchDetailRule(id: Int): DetailRule = ruleDataSource.fetchDetailRuleBy(id).toDetailRule() diff --git a/data/src/main/java/hous/release/data/service/RuleService.kt b/data/src/main/java/hous/release/data/service/RuleService.kt index f094acb7..52fde058 100644 --- a/data/src/main/java/hous/release/data/service/RuleService.kt +++ b/data/src/main/java/hous/release/data/service/RuleService.kt @@ -5,7 +5,7 @@ import hous.release.data.entity.response.BaseResponse import hous.release.data.entity.response.NoDataResponse import hous.release.data.entity.response.rule.CanAddRuleResponse import hous.release.data.entity.response.rule.DetailRuleResponse -import hous.release.data.entity.response.rule.MainRulesResponse +import hous.release.data.entity.response.rule.RulesResponse import okhttp3.MultipartBody import retrofit2.http.Body import retrofit2.http.GET @@ -19,7 +19,7 @@ import retrofit2.http.Query interface RuleService { @GET("/v1/rules") - suspend fun getMainRules(): BaseResponse + suspend fun getRules(): BaseResponse @GET("/v2/rule/{id}") suspend fun getDetailRuleBy(@Path("id") id: Int): BaseResponse diff --git a/data/src/test/java/hous/release/data/repository/RuleRepositoryImplTest.kt b/data/src/test/java/hous/release/data/repository/RuleRepositoryImplTest.kt index 210999f1..a1b90e6d 100644 --- a/data/src/test/java/hous/release/data/repository/RuleRepositoryImplTest.kt +++ b/data/src/test/java/hous/release/data/repository/RuleRepositoryImplTest.kt @@ -2,9 +2,9 @@ package hous.release.data.repository import com.google.common.truth.Truth.assertThat import hous.release.data.datasource.RuleDataSource -import hous.release.data.entity.response.rule.MainRuleResponse -import hous.release.data.entity.response.rule.MainRulesResponse -import hous.release.domain.entity.rule.MainRule +import hous.release.data.entity.response.rule.RuleResponse +import hous.release.data.entity.response.rule.RulesResponse +import hous.release.domain.entity.rule.Rule import io.mockk.coEvery import io.mockk.impl.annotations.RelaxedMockK import io.mockk.junit5.MockKExtension @@ -32,14 +32,14 @@ internal class RuleRepositoryImplTest { fun `MainRulesResponse 객체 에서 MainRule로 변환 하여 규칙들을 불러 온다`() = runTest { // given val expectedMainRules = listOf( - MainRule( + Rule( 34, "dd123xd", true, "2023.03.16", true ), - MainRule( + Rule( 35, "ㄷ슏슛ㄷ", true, @@ -48,17 +48,17 @@ internal class RuleRepositoryImplTest { ) ) coEvery { - ruleDataSource.fetchMainRules() - } returns MainRulesResponse( + ruleDataSource.fetchRules() + } returns RulesResponse( rules = listOf( - MainRuleResponse( + RuleResponse( 34, "dd123xd", true, "2023-03-16T17:19:42.158498", true ), - MainRuleResponse( + RuleResponse( 35, "ㄷ슏슛ㄷ", true, @@ -69,7 +69,7 @@ internal class RuleRepositoryImplTest { ) // when - val actualRules = defaultRuleRepository.fetchMainRules() + val actualRules = defaultRuleRepository.fetchRules() // then assertThat(actualRules).isEqualTo(expectedMainRules) } diff --git a/data/src/test/java/hous/release/data/service/RuleServiceTest.kt b/data/src/test/java/hous/release/data/service/RuleServiceTest.kt index bf9bf242..ded5bc24 100644 --- a/data/src/test/java/hous/release/data/service/RuleServiceTest.kt +++ b/data/src/test/java/hous/release/data/service/RuleServiceTest.kt @@ -4,8 +4,8 @@ import com.google.common.truth.Truth.assertThat import com.google.gson.GsonBuilder import hous.release.data.entity.response.BaseResponse import hous.release.data.entity.response.rule.DetailRuleResponse -import hous.release.data.entity.response.rule.MainRuleResponse -import hous.release.data.entity.response.rule.MainRulesResponse +import hous.release.data.entity.response.rule.RuleResponse +import hous.release.data.entity.response.rule.RulesResponse import io.mockk.junit5.MockKExtension import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest @@ -43,16 +43,16 @@ internal class RuleServiceTest { status = 200, success = true, message = "규칙 메인 페이지 조회 성공입니다.", - data = MainRulesResponse( + data = RulesResponse( rules = listOf( - MainRuleResponse( + RuleResponse( 34, "dd123xd", true, "2023-03-16T17:19:42.158498", true ), - MainRuleResponse( + RuleResponse( 35, "ㄷ슏슛ㄷ", false, @@ -63,7 +63,7 @@ internal class RuleServiceTest { ) ) // when - val actualResponse = ruleService.getMainRules() + val actualResponse = ruleService.getRules() // then assertThat(actualResponse).isEqualTo(expectedResponse) } diff --git a/domain/src/main/java/hous/release/domain/entity/rule/OurRulesContent.kt b/domain/src/main/java/hous/release/domain/entity/rule/OurRulesContent.kt deleted file mode 100644 index 3e28311c..00000000 --- a/domain/src/main/java/hous/release/domain/entity/rule/OurRulesContent.kt +++ /dev/null @@ -1,15 +0,0 @@ -package hous.release.domain.entity.rule - -data class OurRulesContent( - val ourRuleList: List = defaultRuleList, - val isEmptyRepresentativeRuleList: Boolean = true, - val isEmptyGeneralRuleList: Boolean = true -) { - companion object { - val defaultRuleList = listOf( - MainRule(), - MainRule(), - MainRule() - ) - } -} diff --git a/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/Rule.kt similarity index 95% rename from domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt rename to domain/src/main/java/hous/release/domain/entity/rule/Rule.kt index f1796f20..7a850472 100644 --- a/domain/src/main/java/hous/release/domain/entity/rule/MainRule.kt +++ b/domain/src/main/java/hous/release/domain/entity/rule/Rule.kt @@ -2,7 +2,7 @@ package hous.release.domain.entity.rule import hous.release.domain.entity.BaseRule -data class MainRule( +data class Rule( override val id: Int = NO_ID, override val name: String = NO_NAME, val isRepresent: Boolean = false, diff --git a/domain/src/main/java/hous/release/domain/repository/RuleRepository.kt b/domain/src/main/java/hous/release/domain/repository/RuleRepository.kt index 6e3e428b..57fb6e71 100644 --- a/domain/src/main/java/hous/release/domain/repository/RuleRepository.kt +++ b/domain/src/main/java/hous/release/domain/repository/RuleRepository.kt @@ -1,13 +1,13 @@ package hous.release.domain.repository import hous.release.domain.entity.rule.DetailRule -import hous.release.domain.entity.rule.MainRule +import hous.release.domain.entity.rule.Rule import hous.release.domain.util.ApiResult import kotlinx.coroutines.flow.Flow import java.io.File interface RuleRepository { - suspend fun fetchMainRules(): List + suspend fun fetchRules(): List suspend fun fetchDetailRule(id: Int): DetailRule suspend fun canAddRule(): Boolean diff --git a/domain/src/main/java/hous/release/domain/usecase/rule/GetMainRulesUseCase.kt b/domain/src/main/java/hous/release/domain/usecase/rule/GetMainRulesUseCase.kt deleted file mode 100644 index cf5fcefc..00000000 --- a/domain/src/main/java/hous/release/domain/usecase/rule/GetMainRulesUseCase.kt +++ /dev/null @@ -1,10 +0,0 @@ -package hous.release.domain.usecase.rule - -import hous.release.domain.entity.rule.MainRule -import hous.release.domain.repository.RuleRepository -import javax.inject.Inject - -class GetMainRulesUseCase @Inject constructor(private val repository: RuleRepository) { - - suspend operator fun invoke(): List = repository.fetchMainRules() -} diff --git a/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt b/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt index 6c470dca..dc1f432c 100644 --- a/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt +++ b/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt @@ -7,7 +7,7 @@ import javax.inject.Inject class GetRepresentativeRulesUseCase @Inject constructor(private val repository: RuleRepository) { suspend operator fun invoke(): List = - repository.fetchMainRules().map { mainRule -> + repository.fetchRules().map { mainRule -> RepresentativeRule( id = mainRule.id, name = mainRule.name, diff --git a/domain/src/main/java/hous/release/domain/usecase/rule/GetRulesUseCase.kt b/domain/src/main/java/hous/release/domain/usecase/rule/GetRulesUseCase.kt new file mode 100644 index 00000000..151bbdb5 --- /dev/null +++ b/domain/src/main/java/hous/release/domain/usecase/rule/GetRulesUseCase.kt @@ -0,0 +1,10 @@ +package hous.release.domain.usecase.rule + +import hous.release.domain.entity.rule.Rule +import hous.release.domain.repository.RuleRepository +import javax.inject.Inject + +class GetRulesUseCase @Inject constructor(private val repository: RuleRepository) { + + suspend operator fun invoke(): List = repository.fetchRules() +} From 982355ff88554722b7a706ce317c58617468912d Mon Sep 17 00:00:00 2001 From: murjune Date: Wed, 23 Aug 2023 22:07:05 +0900 Subject: [PATCH 5/5] =?UTF-8?q?#305=20[delete]=20=EB=8C=80=ED=91=9C?= =?UTF-8?q?=EB=A3=B0=20model,=20usecase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/entity/rule/RepresentativeRule.kt | 15 --------------- .../usecase/rule/GetRepresentativeRule.kt | 17 ----------------- 2 files changed, 32 deletions(-) delete mode 100644 domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt delete mode 100644 domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt diff --git a/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt b/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt deleted file mode 100644 index 2807414d..00000000 --- a/domain/src/main/java/hous/release/domain/entity/rule/RepresentativeRule.kt +++ /dev/null @@ -1,15 +0,0 @@ -package hous.release.domain.entity.rule - -import hous.release.domain.entity.BaseRule - -data class RepresentativeRule( - override val id: Int = NO_ID, - override val name: String = NO_NAME, - val isRepresent: Boolean = false -) : BaseRule(id, name) { - - private companion object { - private const val NO_NAME = "제목없음" - private const val NO_ID = -1 - } -} diff --git a/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt b/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt deleted file mode 100644 index dc1f432c..00000000 --- a/domain/src/main/java/hous/release/domain/usecase/rule/GetRepresentativeRule.kt +++ /dev/null @@ -1,17 +0,0 @@ -package hous.release.domain.usecase.rule - -import hous.release.domain.entity.rule.RepresentativeRule -import hous.release.domain.repository.RuleRepository -import javax.inject.Inject - -class GetRepresentativeRulesUseCase @Inject constructor(private val repository: RuleRepository) { - - suspend operator fun invoke(): List = - repository.fetchRules().map { mainRule -> - RepresentativeRule( - id = mainRule.id, - name = mainRule.name, - isRepresent = mainRule.isRepresent - ) - } -}