Skip to content

Commit

Permalink
Merge pull request #177 from TeamHous/feature/#176-add-domain-module
Browse files Browse the repository at this point in the history
#176 [refact] domain 모듈 추가
  • Loading branch information
murjune authored Aug 11, 2022
2 parents 3eab7be + 8b8ad1d commit cf4eb1d
Show file tree
Hide file tree
Showing 35 changed files with 240 additions and 87 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ android {

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

KotlinDependencies.run {
implementation(kotlin)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/hous/hous_aos/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hous.hous_aos.di

import com.hous.data.repository.HomeRepository
import com.hous.data.repository.HomeRepositoryImpl
import com.hous.data.repository.NewRulesRepository
import com.hous.domain.repository.NewRulesRepository
import com.hous.data.repository.NewRulesRepositoryImpl
import com.hous.data.repository.ProfileRepository
import com.hous.data.repository.ProfileRepositoryImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.hous.domain.model.Homie
import com.hous.hous_aos.R
import com.hous.hous_aos.ui.newrules.component.CategoryItem
import com.hous.hous_aos.ui.newrules.component.ManagerItem
Expand Down Expand Up @@ -176,7 +177,7 @@ fun NewRulesScreen(
}

fun isAddDay(
homies: List<com.hous.data.entity.Homie>,
homies: List<Homie>,
homieState: HashMap<String, Boolean>
): Boolean {
var temp = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ package com.hous.hous_aos.ui.newrules
import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hous.data.entity.DayData
import com.hous.data.entity.Manager
import com.hous.data.entity.State
import com.hous.data.repository.NewRulesRepository
import com.hous.domain.model.Category
import com.hous.domain.model.DayData
import com.hous.domain.model.Homie
import com.hous.domain.model.Manager
import com.hous.domain.model.State
import com.hous.domain.usecase.AddNewRuleUseCase
import com.hous.domain.usecase.GetNewRuleInfoUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class NewRulesViewModel @Inject constructor(
private val newRulesRepository: NewRulesRepository
private val addNewRuleUseCase: AddNewRuleUseCase,
private val getNewRuleInfoUseCase: GetNewRuleInfoUseCase
) : ViewModel() {
private val _uiState = MutableStateFlow(NewRulesUiState())
val uiState = _uiState.asStateFlow()
Expand All @@ -32,12 +36,11 @@ class NewRulesViewModel @Inject constructor(

init {
viewModelScope.launch {
newRulesRepository.getNewRuleList("")
getNewRuleInfoUseCase("")
.onSuccess {
Log.d("NewRulesViewModel", "getNewRuleList success : ${it.message}")
_uiState.value = _uiState.value.copy(
ruleCategory = it.data!!.ruleCategories,
homies = it.data!!.homies
ruleCategory = it.ruleCategories,
homies = it.homies
)
setUserMapping()
}
Expand Down Expand Up @@ -147,7 +150,7 @@ class NewRulesViewModel @Inject constructor(
}
}

fun choiceManager(managerIndex: Int, homie: com.hous.data.entity.Homie) {
fun choiceManager(managerIndex: Int, homie: Homie) {
if (uiState.value.ManagerList[managerIndex].managerHomie.userName != "담당자 없음") {
_uiState.value.homieState[uiState.value.ManagerList[managerIndex].managerHomie.userName] =
true
Expand Down Expand Up @@ -188,25 +191,22 @@ class NewRulesViewModel @Inject constructor(
}

fun addNewRule() {
Log.d("NewRulesViewModel", "data : ${uiState.value}")
viewModelScope.launch {
newRulesRepository.addNewRule(
addNewRuleUseCase(
ruleName = uiState.value.ruleName,
categoryId = uiState.value.categoryId,
notificationState = uiState.value.notificationState,
checkBoxState = uiState.value.checkBoxState,
managerList = uiState.value.ManagerList
)
.onSuccess { Log.d("NewRulesViewModel", "addNewRule success : ${it.message}") }
.onFailure { Log.d("NewRulesViewModel", "addNewRule fail : ${it.message}") }
}
}

private fun nextManager(): com.hous.data.entity.Homie {
var tempHomie = com.hous.data.entity.Homie("", "담당자 없음", typeColor = "NULL")
private fun nextManager(): Homie {
var tempHomie = Homie("", "담당자 없음", typeColor = "NULL")
for (i in uiState.value.homies) {
if (uiState.value.homieState[i.userName]!!) {
tempHomie = com.hous.data.entity.Homie(
tempHomie = Homie(
id = i.id,
userName = i.userName,
typeColor = i.typeColor
Expand Down Expand Up @@ -252,20 +252,20 @@ data class NewRulesUiState(
val categoryId: String = "",
val notificationState: Boolean = false,
val checkBoxState: State = State.UNSELECT,
val ruleCategory: List<com.hous.data.entity.Category> =
val ruleCategory: List<Category> =
listOf(
com.hous.data.entity.Category("1", "청소기"),
com.hous.data.entity.Category("2", "분리수거"),
com.hous.data.entity.Category("3", "세탁기"),
com.hous.data.entity.Category("4", "물 주기")
Category("1", "청소기"),
Category("2", "분리수거"),
Category("3", "세탁기"),
Category("4", "물 주기")
),
val homies: List<com.hous.data.entity.Homie> =
val homies: List<Homie> =
listOf(
com.hous.data.entity.Homie("1", "강원용", typeColor = "RED"),
com.hous.data.entity.Homie("2", "이영주", typeColor = "BLUE"),
com.hous.data.entity.Homie("3", "이준원", typeColor = "YELLOW"),
com.hous.data.entity.Homie("4", "최인영", typeColor = "GREEN"),
com.hous.data.entity.Homie("5", "최소현", typeColor = "PURPLE")
Homie("1", "강원용", typeColor = "RED"),
Homie("2", "이영주", typeColor = "BLUE"),
Homie("3", "이준원", typeColor = "YELLOW"),
Homie("4", "최인영", typeColor = "GREEN"),
Homie("5", "최소현", typeColor = "PURPLE")
),
val homieState: HashMap<String, Boolean> = hashMapOf(
"강원용" to true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import com.hous.hous_aos.R
import com.hous.data.entity.Category
import com.hous.domain.model.Category

@Composable
fun CategoryDropDownMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.hous.hous_aos.R
import com.hous.data.entity.Category
import com.hous.domain.model.Category

@Composable
fun CategoryItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import com.hous.data.entity.State
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import com.hous.data.entity.DayData
import com.hous.data.entity.State
import com.hous.domain.model.DayData
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.hous.data.entity.DayData
import com.hous.data.entity.Manager
import com.hous.domain.model.DayData
import com.hous.domain.model.Manager

@Composable
fun NewRulesDayList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.foundation.clickable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import com.hous.data.entity.State
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.hous.domain.model.Homie
import com.hous.hous_aos.R
import com.hous.data.entity.Homie
import com.hous.hous_aos.ui.newrules.isAddDay

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.hous.data.entity.Homie
import com.hous.data.entity.Manager
import com.hous.data.entity.State
import com.hous.domain.model.Homie
import com.hous.domain.model.Manager
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
Expand All @@ -41,7 +41,7 @@ fun ManagerBox(
.size(36.dp)
.clip(shape = RoundedCornerShape(radius))
.background(colorResource(id = R.color.white))
.padding(horizontal = 12.dp),
.padding(horizontal = 12.dp)
) {
val color = when (manager.managerHomie.typeColor) {
"RED" -> colorResource(id = R.color.hous_red)
Expand All @@ -54,7 +54,7 @@ fun ManagerBox(
}
Row(
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = Alignment.CenterVertically
) {
if (color != null) {
Box(
Expand All @@ -79,7 +79,7 @@ fun ManagerBox(

Box(
modifier = Modifier
.fillMaxSize(),
.fillMaxSize()
) {
ManagerDropDownMenu(
managerIndex = managerIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import com.hous.hous_aos.R
import com.hous.data.entity.Homie
import com.hous.data.entity.State
import com.hous.domain.model.Homie
import com.hous.domain.model.State
import com.hous.hous_aos.ui.newrules.isAddDay

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.hous.data.entity.DayData
import com.hous.data.entity.Homie
import com.hous.data.entity.Manager
import com.hous.data.entity.State
import com.hous.domain.model.DayData
import com.hous.domain.model.Homie
import com.hous.domain.model.Manager
import com.hous.domain.model.State

@Composable
fun ManagerItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import com.hous.data.entity.State
import com.hous.domain.model.State
import com.hous.hous_aos.R

@Composable
Expand Down
1 change: 1 addition & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
}

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

KotlinDependencies.run {
implementation(kotlin)
Expand Down
6 changes: 3 additions & 3 deletions data/src/main/java/com/hous/data/api/NewRulesApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface NewRulesApi {
@POST("room/{roomId}/rule")
suspend fun addNewRule(
@Path("roomId") roomId: String,
@Body newRulesRequest: com.hous.data.model.request.NewRulesRequest
): com.hous.data.model.WrapperClass<Any>
@Body newRulesRequest: NewRulesRequest
)

@GET("room/{roomId}/rule/new")
suspend fun getNewRuleList(
@Path("roomId") roomId: String
): com.hous.data.model.WrapperClass<com.hous.data.model.response.NewRulesListResponse>
): WrapperClass<NewRulesListResponse>
}
5 changes: 4 additions & 1 deletion data/src/main/java/com/hous/data/entity/Category.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.hous.data.entity

import com.google.gson.annotations.SerializedName
import com.hous.domain.model.Category

data class Category(
@SerializedName("_id") val id: String = "",
val categoryName: String = "",
val categoryIcon: String = "",
val ruleName: String = "",
var isChecked: Boolean = false
)
) {
fun toCategory() = Category(id, categoryName, categoryIcon, ruleName, isChecked)
}
17 changes: 16 additions & 1 deletion data/src/main/java/com/hous/data/entity/Homie.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hous.data.entity

import com.google.gson.annotations.SerializedName
import com.hous.domain.model.Homie

data class Homie(
@SerializedName("_id") val id: String? = null,
Expand All @@ -14,4 +15,18 @@ data class Homie(
val typeScore: List<Int> = emptyList(),
var isChecked: Boolean = false,
val notificationState: Boolean = false
)
) {
fun toHomie(): Homie = Homie(
id,
userName,
typeName,
typeId,
typeColor,
job,
introduction,
hashTag,
typeScore,
isChecked,
notificationState
)
}
17 changes: 0 additions & 17 deletions data/src/main/java/com/hous/data/repository/NewRulesRepository.kt

This file was deleted.

Loading

0 comments on commit cf4eb1d

Please sign in to comment.