diff --git a/core/src/main/java/com/terning/core/type/ColorType.kt b/core/src/main/java/com/terning/core/type/ColorType.kt index 7d35c8f65..b2ea4fe52 100644 --- a/core/src/main/java/com/terning/core/type/ColorType.kt +++ b/core/src/main/java/com/terning/core/type/ColorType.kt @@ -21,16 +21,17 @@ import com.terning.core.designsystem.theme.CalRedBc import com.terning.core.designsystem.theme.CalRedLi enum class ColorType( + val typeName: String, val main: Color, val border: Color, val sub: Color ) { - RED(main = CalRed, border = CalRedLi, sub = CalRedBc), - ORANGE(main = CalOrange2, border = CalOrangeLi, sub = CalOrangeBc), - GREEN(main = CalGreen2, border = CalGreenLi, sub = CalGreenBc), - BLUE(main = CalBlue2, border = CalBlueLi, sub = CalBlueBc), - PURPLE(main = CalPurple, border = CalPurpleLi, sub = CalPurpleBc), - PINK(main = CalPink, border = CalPinkLi, sub = CalPinkBc); + RED(typeName = "red", main = CalRed, border = CalRedLi, sub = CalRedBc), + ORANGE(typeName = "orange", main = CalOrange2, border = CalOrangeLi, sub = CalOrangeBc), + GREEN(typeName = "green", main = CalGreen2, border = CalGreenLi, sub = CalGreenBc), + BLUE(typeName = "blue", main = CalBlue2, border = CalBlueLi, sub = CalBlueBc), + PURPLE(typeName = "purple", main = CalPurple, border = CalPurpleLi, sub = CalPurpleBc), + PINK(typeName = "pink", main = CalPink, border = CalPinkLi, sub = CalPinkBc); companion object { fun findColorType(mainColor: Color): ColorType? = entries.find { it.main == mainColor } diff --git a/data/src/main/java/com/terning/data/dto/request/ScrapColorRequestDto.kt b/data/src/main/java/com/terning/data/dto/request/ScrapColorRequestDto.kt index b6d626dbe..c6d96ce50 100644 --- a/data/src/main/java/com/terning/data/dto/request/ScrapColorRequestDto.kt +++ b/data/src/main/java/com/terning/data/dto/request/ScrapColorRequestDto.kt @@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable @Serializable data class ScrapColorRequestDto( @SerialName("color") - val color: Int? = null, + val color: String? = null, ) \ No newline at end of file diff --git a/domain/src/main/java/com/terning/domain/entity/calendar/CalendarScrapRequest.kt b/domain/src/main/java/com/terning/domain/entity/calendar/CalendarScrapRequest.kt index 8b4d047d2..05019d644 100644 --- a/domain/src/main/java/com/terning/domain/entity/calendar/CalendarScrapRequest.kt +++ b/domain/src/main/java/com/terning/domain/entity/calendar/CalendarScrapRequest.kt @@ -2,5 +2,5 @@ package com.terning.domain.entity.calendar data class CalendarScrapRequest( val id: Long, - val color: Int? = 0, + val color: String? = "red", ) \ No newline at end of file diff --git a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt index 57ab067dc..7d6df6fe3 100644 --- a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt +++ b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialog.kt @@ -64,9 +64,10 @@ fun ScrapDialog( internshipAnnouncementId: Long, companyImage: String, isScrapped: Boolean, - onDismissRequest: () -> Unit, - onClickChangeColor: () -> Unit, - onClickNavigateButton: (Long) -> Unit, + onDismissRequest: () -> Unit = {}, + onScrapAnnouncement: () -> Unit = {}, + onClickChangeColor: () -> Unit = {}, + onClickNavigateButton: (Long) -> Unit = {}, viewModel: ScrapDialogViewModel = hiltViewModel() ) { val context = LocalContext.current @@ -79,6 +80,7 @@ fun ScrapDialog( is ScrapDialogSideEffect.ShowToast -> { context.toast(sideEffect.message) } + is ScrapDialogSideEffect.DismissDialog -> { viewModel.initUiState() onDismissRequest() @@ -90,6 +92,8 @@ fun ScrapDialog( ) is ScrapDialogSideEffect.ScrappedAnnouncement -> { + onScrapAnnouncement() + onDismissRequest() } } } @@ -115,8 +119,11 @@ fun ScrapDialog( isColorChangedOnce = uiState.isColorChangedOnce, onClickColorButton = viewModel::changeSelectedColor, onClickColorChangeButton = { - if(uiState.isColorChanged) - viewModel.patchScrap(scrapId = internshipAnnouncementId, color = uiState.selectedColorType) + if (uiState.isColorChanged) + viewModel.patchScrap( + scrapId = internshipAnnouncementId, + color = uiState.selectedColorType + ) }, onClickNavigateButton = viewModel::navigateToDetail, onClickScrapButton = { diff --git a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialogViewModel.kt b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialogViewModel.kt index b74b3e27c..6a72a30f7 100644 --- a/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialogViewModel.kt +++ b/feature/src/main/java/com/terning/feature/dialog/detail/ScrapDialogViewModel.kt @@ -1,18 +1,7 @@ package com.terning.feature.dialog.detail -import androidx.compose.ui.graphics.Color import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.terning.core.designsystem.theme.CalBlue1 -import com.terning.core.designsystem.theme.CalBlue2 -import com.terning.core.designsystem.theme.CalGreen1 -import com.terning.core.designsystem.theme.CalGreen2 -import com.terning.core.designsystem.theme.CalOrange1 -import com.terning.core.designsystem.theme.CalOrange2 -import com.terning.core.designsystem.theme.CalPink -import com.terning.core.designsystem.theme.CalPurple -import com.terning.core.designsystem.theme.CalRed -import com.terning.core.designsystem.theme.CalYellow import com.terning.core.type.ColorType import com.terning.domain.entity.calendar.CalendarScrapRequest import com.terning.domain.repository.ScrapRepository @@ -76,9 +65,8 @@ class ScrapDialogViewModel @Inject constructor( } fun postScrap(id: Long, color: ColorType) { - val colorIndex = getColorIndex(color.main) viewModelScope.launch { - scrapRepository.postScrap(CalendarScrapRequest(id, colorIndex)) + scrapRepository.postScrap(CalendarScrapRequest(id, color.typeName)) .onSuccess { with(_sideEffect) { emit(ScrapDialogSideEffect.ShowToast(R.string.dialog_scrap_scrapped)) @@ -91,8 +79,7 @@ class ScrapDialogViewModel @Inject constructor( } fun patchScrap(scrapId: Long, color: ColorType) = viewModelScope.launch { - val colorIndex = getColorIndex(color.main) - scrapRepository.patchScrap(CalendarScrapRequest(scrapId, colorIndex)) + scrapRepository.patchScrap(CalendarScrapRequest(scrapId, color.typeName)) .onSuccess { _sideEffect.emit(ScrapDialogSideEffect.PatchedScrap) _uiState.update { currentState -> @@ -106,17 +93,4 @@ class ScrapDialogViewModel @Inject constructor( _sideEffect.emit(ScrapDialogSideEffect.ShowToast(R.string.server_failure)) } } - - private fun getColorIndex(color: Color): Int = listOf( - CalRed, - CalOrange1, - CalOrange2, - CalYellow, - CalGreen1, - CalGreen2, - CalBlue1, - CalBlue2, - CalPurple, - CalPink - ).indexOf(color) } \ No newline at end of file