Skip to content

Commit

Permalink
Merge pull request #307 from Hous-Release/feature/#305-fetch-represen…
Browse files Browse the repository at this point in the history
…tation-rule-api-usecase

#305 [Refactor] 기존 domain에 있는 Rule -> BaseRule, MainRule -> Rule 로 네이밍 변경
  • Loading branch information
murjune authored Sep 4, 2023
2 parents a0b9101 + 2eb07d8 commit bb3e1ca
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainRule> = emptyList(),
mainRules: List<Rule> = emptyList(),
searchQuery: String = "",
onSearch: (String) -> Unit = {},
onOpenDetailRule: (Int) -> Unit = {},
Expand Down Expand Up @@ -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)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainRule> = emptyList()
mainRules: List<Rule> = emptyList()
) {
if (mainRules.isEmpty()) {
MainRuleEmptyContent()
Expand Down Expand Up @@ -63,7 +63,7 @@ private fun MainRuleEmptyContent() {
@Composable
private fun MainRuleItem(
onClick: () -> Unit = {},
mainRule: MainRule = MainRule()
mainRule: Rule = Rule()
) {
val focusManager = LocalFocusManager.current
HousRuleSlot(
Expand Down Expand Up @@ -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)
)
)
}
Expand All @@ -131,7 +131,7 @@ private fun NewMainRulePreview() {
HousTheme {
Surface {
MainRuleItem(
mainRule = MainRule().copy(isNew = true)
mainRule = Rule().copy(isNew = true)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,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<MainRule> = emptyList(),
mainRules: List<Rule> = emptyList(),
searchQuery: String = "",
fetchDetailRuleById: (Int) -> Unit = {},
deleteRule: () -> Unit = {},
Expand Down Expand Up @@ -119,10 +119,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)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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.DeleteRuleUseCase
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
Expand All @@ -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 deleteRuleUseCase: DeleteRuleUseCase,
Expand Down Expand Up @@ -120,18 +120,18 @@ sealed class MainRuleSideEffect {
sealed class MainRulesEvent {
data class LoadedImage(val photos: List<Photo?>) : MainRulesEvent()

data class Refresh(val rules: List<MainRule>) : MainRulesEvent()
data class FetchMainRules(val rules: List<MainRule>) : MainRulesEvent()
data class Refresh(val rules: List<Rule>) : MainRulesEvent()
data class FetchMainRules(val rules: List<Rule>) : MainRulesEvent()
data class FetchDetailRule(val rule: DetailRule) : MainRulesEvent()
data class SearchRule(val searchQuery: String, val filteredRules: List<MainRule>) :
data class SearchRule(val searchQuery: String, val filteredRules: List<Rule>) :
MainRulesEvent()

object DeleteAllFile : MainRulesEvent()
}

data class MainRulesState(
val detailRule: DetailRuleUiModel = DetailRuleUiModel(),
val originRules: List<MainRule> = emptyList(),
val filteredRules: List<MainRule> = emptyList(),
val originRules: List<Rule> = emptyList(),
val filteredRules: List<Rule> = emptyList(),
val searchQuery: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MainRuleResponse> = emptyList()
data class RulesResponse(
val rules: List<RuleResponse> = 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 kotlinx.coroutines.CoroutineDispatcher
import java.io.File
Expand All @@ -15,8 +15,8 @@ class RuleRepositoryImpl @Inject constructor(
private val ioDispatcher: CoroutineDispatcher
) : RuleRepository {

override suspend fun fetchMainRules(): List<MainRule> =
ruleDataSource.fetchMainRules().rules.map { it.toMainRule() }
override suspend fun fetchRules(): List<Rule> =
ruleDataSource.fetchRules().rules.map { it.toRule() }

override suspend fun fetchDetailRule(id: Int): DetailRule =
ruleDataSource.fetchDetailRuleBy(id).toDetailRule()
Expand Down
4 changes: 2 additions & 2 deletions data/src/main/java/hous/release/data/service/RuleService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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.GET
import retrofit2.http.HTTP
Expand All @@ -17,7 +17,7 @@ import retrofit2.http.Query

interface RuleService {
@GET("/v1/rules")
suspend fun getMainRules(): BaseResponse<MainRulesResponse>
suspend fun getRules(): BaseResponse<RulesResponse>

@GET("/v2/rule/{id}")
suspend fun getDetailRuleBy(@Path("id") id: Int): BaseResponse<DetailRuleResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -69,7 +69,7 @@ internal class RuleRepositoryImplTest {
)

// when
val actualRules = defaultRuleRepository.fetchMainRules()
val actualRules = defaultRuleRepository.fetchRules()
// then
assertThat(actualRules).isEqualTo(expectedMainRules)
}
Expand Down
12 changes: 6 additions & 6 deletions data/src/test/java/hous/release/data/service/RuleServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -63,7 +63,7 @@ internal class RuleServiceTest {
)
)
// when
val actualResponse = ruleService.getMainRules()
val actualResponse = ruleService.getRules()
// then
assertThat(actualResponse).isEqualTo(expectedResponse)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hous.release.domain.entity

abstract class Rule(
abstract class BaseRule(
open val id: Int,
open val name: String
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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,
override val name: String = NO_NAME,
val description: String = NO_DESCRIPTION,
val images: List<Photo> = emptyList(),
val updatedAt: String = ""
) : Rule(id, name) {
) : BaseRule(id, name) {
companion object {
private const val NO_NAME = "제목 없음"
private const val NO_DESCRIPTION = "설명 없음"
Expand Down

This file was deleted.

Loading

0 comments on commit bb3e1ca

Please sign in to comment.