Skip to content

Commit 5ddc796

Browse files
authored
Merge: SIMT-92 홈화면 예외처리
2 parents 680a5da + 772d455 commit 5ddc796

File tree

10 files changed

+110
-33
lines changed

10 files changed

+110
-33
lines changed

feature/feature-home/src/main/java/com/comit/feature_home/mvi/CloseDayContract.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ sealed class CloseDaySideEffect {
1515

1616
object TokenException : CloseDaySideEffect()
1717

18-
object DayOffExcess : CloseDaySideEffect()
18+
object AlreadyHoliday : CloseDaySideEffect()
1919

20-
object AnnualDayChangeFail : CloseDaySideEffect()
20+
object TooManyHoliday : CloseDaySideEffect()
21+
22+
object TooManyAnnualDay : CloseDaySideEffect()
23+
24+
object AlreadyAnnualDay : CloseDaySideEffect()
2125

2226
object AlreadyWork : CloseDaySideEffect()
27+
28+
object CannotChangeWorkState : CloseDaySideEffect()
2329
}

feature/feature-home/src/main/java/com/comit/feature_home/mvi/FetchScheduleContract.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ fun ScheduleList.Schedule.toStateSchedule() = FetchScheduleState.Schedule(
2828

2929
sealed class FetchScheduleSideEffect {
3030

31-
object FetchScheduleFail : FetchScheduleSideEffect()
31+
object DeleteScheduleDateError : FetchScheduleSideEffect()
32+
33+
object DeleteScheduleCannotFound : FetchScheduleSideEffect()
3234

3335
object DeleteScheduleSuccess : FetchScheduleSideEffect()
3436

35-
object DeleteScheduleFail : FetchScheduleSideEffect()
37+
object TokenError : FetchScheduleSideEffect()
3638
}

feature/feature-home/src/main/java/com/comit/feature_home/navigation/HomeNavigation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import androidx.navigation.navArgument
1010
import androidx.navigation.navigation
1111
import com.comit.feature_home.screen.HomeScreen
1212
import com.comit.feature_home.screen.SalaryWebViewScreen
13+
import com.comit.feature_home.screen.WriteClosedDayScreen
1314
import com.comit.feature_home.screen.alarm.AlarmScreen
1415
import com.comit.feature_home.screen.schedule.ShowScheduleScreen
1516
import com.comit.feature_home.screen.schedule.WriteScheduleScreen
16-
import com.comit.feature_home.vm.WriteClosedDayScreen
1717
import com.comit.navigator.SimTongScreen
1818

1919
fun NavGraphBuilder.homeNavigation(

feature/feature-home/src/main/java/com/comit/feature_home/screen/HomeScreen.kt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:OptIn(ExperimentalMaterialApi::class, InternalCoroutinesApi::class,)
1+
@file:OptIn(ExperimentalMaterialApi::class, InternalCoroutinesApi::class)
22

33
package com.comit.feature_home.screen
44

@@ -28,13 +28,15 @@ import androidx.compose.ui.Modifier
2828
import androidx.compose.ui.graphics.painter.Painter
2929
import androidx.compose.ui.res.painterResource
3030
import androidx.compose.ui.res.stringResource
31+
import androidx.compose.ui.text.buildAnnotatedString
3132
import androidx.compose.ui.tooling.preview.Preview
3233
import androidx.compose.ui.unit.Dp
3334
import androidx.compose.ui.unit.dp
3435
import androidx.hilt.navigation.compose.hiltViewModel
3536
import androidx.navigation.NavController
3637
import androidx.navigation.compose.rememberNavController
3738
import com.comit.common.rememberToast
39+
import com.comit.common.utils.string
3840
import com.comit.core.observeWithLifecycle
3941
import com.comit.core_design_system.color.SimTongColor
4042
import com.comit.core_design_system.component.Header
@@ -84,23 +86,35 @@ fun HomeScreen(
8486
today.get(Calendar.MONTH),
8587
today.get(Calendar.DATE) + StartDateAdd
8688
)
87-
val startYear = startAt.get(Calendar.YEAR).toString()
88-
val startMonth = (startAt.get(Calendar.MONTH) + 1).toString()
89-
val startDay = startAt.get(Calendar.DATE).toString()
89+
val startYear = startAt.get(Calendar.YEAR)
90+
val startMonth = (startAt.get(Calendar.MONTH) + 1)
91+
val startDay = startAt.get(Calendar.DATE)
9092

9193
val endAt = GregorianCalendar(
9294
today.get(Calendar.YEAR),
9395
today.get(Calendar.MONTH),
9496
today.get(Calendar.DATE) + EndDateAdd
9597
)
96-
val endYear = endAt.get(Calendar.YEAR).toString()
97-
val endMonth = (endAt.get(Calendar.MONTH) + 1).toString()
98-
val endDay = endAt.get(Calendar.DATE).toString()
98+
val endYear = endAt.get(Calendar.YEAR)
99+
val endMonth = (endAt.get(Calendar.MONTH) + 1)
100+
val endDay = endAt.get(Calendar.DATE)
99101

100102
LaunchedEffect(key1 = homeViewModel) {
101103
homeViewModel.fetchMenu(
102-
startAt = "$startYear-$startMonth-$startDay",
103-
endAt = "$endYear-$endMonth-$endDay",
104+
startAt = buildAnnotatedString {
105+
append(startYear.toString())
106+
append("-")
107+
append(string.format("%02d", startMonth))
108+
append("-")
109+
append(string.format("%02d", startDay))
110+
}.toString(),
111+
endAt = buildAnnotatedString {
112+
append(endYear.toString())
113+
append("-")
114+
append(string.format("%02d", endMonth))
115+
append("-")
116+
append(string.format("%02d", endDay))
117+
}.toString()
104118
)
105119
}
106120

feature/feature-home/src/main/java/com/comit/feature_home/vm/WriteClosedDayScreen.kt renamed to feature/feature-home/src/main/java/com/comit/feature_home/screen/WriteClosedDayScreen.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
)
55
@file:Suppress("OPT_IN_IS_NOT_ENABLED")
66

7-
package com.comit.feature_home.vm
7+
package com.comit.feature_home.screen
88

99
import androidx.compose.foundation.background
1010
import androidx.compose.foundation.layout.Box
@@ -62,6 +62,7 @@ import com.comit.feature_home.calendar.SimTongCalendar
6262
import com.comit.feature_home.calendar.SimTongCalendarStatus
6363
import com.comit.feature_home.mvi.CloseDaySideEffect
6464
import com.comit.feature_home.string
65+
import com.comit.feature_home.vm.CloseDayViewModel
6566
import com.example.feature_home.R
6667
import kotlinx.coroutines.InternalCoroutinesApi
6768
import kotlinx.coroutines.launch
@@ -78,8 +79,12 @@ private val CalendarPadding = PaddingValues(
7879

7980
private const val DateInputWrongMessage = "잘못된 날짜 입력입니다"
8081
private const val TokenExceptionMessage = "토큰 만료. 다시 로그인해주세요"
81-
private const val DayOffExcessMessage = "일주일에 휴무일은 최대 2회입니다"
82+
private const val AlreadyHoliday = "이미 휴무일입니다"
83+
private const val TooManyHoliday = "휴무일은 일주일에 2번만 가능합니다"
84+
private const val AlreadyAnnualDay = "이미 연차입니다"
85+
private const val TooManyAnnualDay = "연차 개수가 부족합니다"
8286
private const val AlreadyWorkMessage = "이미 근무일입니다"
87+
private const val CannotChangeWorkState = "더 이상 변경할 수 없는 일정입니다"
8388

8489
@Composable
8590
fun WriteClosedDayScreen(
@@ -122,15 +127,24 @@ fun WriteClosedDayScreen(
122127
CloseDaySideEffect.TokenException -> {
123128
toast(message = TokenExceptionMessage)
124129
}
125-
CloseDaySideEffect.DayOffExcess -> {
126-
toast(message = DayOffExcessMessage)
130+
CloseDaySideEffect.AlreadyHoliday -> {
131+
toast(message = AlreadyHoliday)
127132
}
128-
CloseDaySideEffect.AnnualDayChangeFail -> {
129-
toast(message = "서비스 준비중입니다")
133+
CloseDaySideEffect.TooManyHoliday -> {
134+
toast(message = TooManyHoliday)
135+
}
136+
CloseDaySideEffect.AlreadyAnnualDay -> {
137+
toast(message = AlreadyAnnualDay)
138+
}
139+
CloseDaySideEffect.TooManyAnnualDay -> {
140+
toast(message = TooManyAnnualDay)
130141
}
131142
CloseDaySideEffect.AlreadyWork -> {
132143
toast(message = AlreadyWorkMessage)
133144
}
145+
CloseDaySideEffect.CannotChangeWorkState -> {
146+
toast(message = CannotChangeWorkState)
147+
}
134148
}
135149
}
136150

feature/feature-home/src/main/java/com/comit/feature_home/screen/schedule/ShowScheduleScreen.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ fun ShowScheduleScreen(
133133

134134
showScheduleSideEffect.observeWithLifecycle() {
135135
when (it) {
136-
FetchScheduleSideEffect.FetchScheduleFail -> {
137-
toast(message = "일정을 불러오는데 실패했습니다.")
138-
}
139136
FetchScheduleSideEffect.DeleteScheduleSuccess -> {
140137
coroutineScope.launch {
141138
bottomSheetState.hide()
@@ -145,8 +142,14 @@ fun ShowScheduleScreen(
145142
endAt = getEndAt(checkMonth)
146143
)
147144
}
148-
FetchScheduleSideEffect.DeleteScheduleFail -> {
149-
toast(message = "일정 삭제를 실패했습니다.")
145+
FetchScheduleSideEffect.DeleteScheduleDateError -> {
146+
toast(message = "삭제할 일정을 찾지 못했습니다")
147+
}
148+
FetchScheduleSideEffect.DeleteScheduleCannotFound -> {
149+
toast(message = "일정이 존재하지 않습니다")
150+
}
151+
FetchScheduleSideEffect.TokenError -> {
152+
toast(message = "토큰 만료. 다시 로그인해주세요")
150153
}
151154
}
152155
}

feature/feature-home/src/main/java/com/comit/feature_home/vm/CloseDayViewModel.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
55
import com.comit.domain.exception.BadRequestException
66
import com.comit.domain.exception.ConflictException
77
import com.comit.domain.exception.NotFoundException
8+
import com.comit.domain.exception.TooManyRequestsException
89
import com.comit.domain.exception.UnAuthorizedException
910
import com.comit.domain.exception.throwUnknownException
1011
import com.comit.domain.usecase.holiday.CheckLeftHolidayUseCase
@@ -43,7 +44,8 @@ class CloseDayViewModel @Inject constructor(
4344
when (it) {
4445
is BadRequestException -> postSideEffect(CloseDaySideEffect.DateInputWrong)
4546
is UnAuthorizedException -> postSideEffect(CloseDaySideEffect.TokenException)
46-
is ConflictException -> postSideEffect(CloseDaySideEffect.DayOffExcess)
47+
is ConflictException -> postSideEffect(CloseDaySideEffect.AlreadyHoliday)
48+
is TooManyRequestsException -> postSideEffect(CloseDaySideEffect.TooManyHoliday)
4749
else -> throwUnknownException(it)
4850
}
4951
}
@@ -57,7 +59,13 @@ class CloseDayViewModel @Inject constructor(
5759
).onSuccess {
5860
postSideEffect(CloseDaySideEffect.CloseDayChangeSuccess)
5961
}.onFailure {
60-
postSideEffect(CloseDaySideEffect.AnnualDayChangeFail)
62+
when (it) {
63+
is BadRequestException -> postSideEffect(CloseDaySideEffect.DateInputWrong)
64+
is UnAuthorizedException -> postSideEffect(CloseDaySideEffect.TokenException)
65+
is ConflictException -> postSideEffect(CloseDaySideEffect.AlreadyAnnualDay)
66+
is TooManyRequestsException -> postSideEffect(CloseDaySideEffect.TooManyAnnualDay)
67+
else -> throwUnknownException(it)
68+
}
6169
}
6270
}
6371
}
@@ -73,6 +81,7 @@ class CloseDayViewModel @Inject constructor(
7381
is BadRequestException -> postSideEffect(CloseDaySideEffect.DateInputWrong)
7482
is UnAuthorizedException -> postSideEffect(CloseDaySideEffect.TokenException)
7583
is NotFoundException -> postSideEffect(CloseDaySideEffect.AlreadyWork)
84+
is ConflictException -> postSideEffect(CloseDaySideEffect.CannotChangeWorkState)
7685
else -> throwUnknownException(it)
7786
}
7887
}
@@ -87,6 +96,11 @@ class CloseDayViewModel @Inject constructor(
8796
reduce {
8897
state.copy(leftHoliday = it.result)
8998
}
99+
}.onFailure {
100+
when (it) {
101+
is UnAuthorizedException -> postSideEffect(CloseDaySideEffect.TokenException)
102+
else -> throwUnknownException(it)
103+
}
90104
}
91105
}
92106
}

feature/feature-home/src/main/java/com/comit/feature_home/vm/GetHolidayViewModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import androidx.lifecycle.LiveData
44
import androidx.lifecycle.MutableLiveData
55
import androidx.lifecycle.ViewModel
66
import androidx.lifecycle.viewModelScope
7+
import com.comit.domain.exception.BadRequestException
8+
import com.comit.domain.exception.UnAuthorizedException
9+
import com.comit.domain.exception.throwUnknownException
710
import com.comit.domain.usecase.holiday.FetchHolidaysUseCase
811
import com.comit.feature_home.mvi.FetchHolidayState
912
import com.comit.feature_home.mvi.toState
@@ -32,7 +35,11 @@ class GetHolidayViewModel @Inject constructor(
3235
).onSuccess {
3336
_holidayList.value = it.toState().holidayList
3437
}.onFailure {
35-
_holidayList.value = listOf()
38+
when (it) {
39+
is BadRequestException -> _holidayList.value = listOf()
40+
is UnAuthorizedException -> _holidayList.value = listOf()
41+
else -> throwUnknownException(it)
42+
}
3643
}
3744
}
3845
}

feature/feature-home/src/main/java/com/comit/feature_home/vm/GetWorkCountViewModel.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import androidx.lifecycle.LiveData
44
import androidx.lifecycle.MutableLiveData
55
import androidx.lifecycle.ViewModel
66
import androidx.lifecycle.viewModelScope
7+
import com.comit.domain.exception.BadRequestException
8+
import com.comit.domain.exception.UnAuthorizedException
9+
import com.comit.domain.exception.throwUnknownException
710
import com.comit.domain.usecase.schedule.FetchPersonalScheduleUseCase
811
import com.comit.feature_home.mvi.FetchScheduleState
912
import com.comit.feature_home.mvi.toState
@@ -30,7 +33,11 @@ class GetWorkCountViewModel @Inject constructor(
3033
).onSuccess {
3134
_workCountList.value = it.toState().scheduleList
3235
}.onFailure {
33-
_workCountList.value = listOf()
36+
when (it) {
37+
is BadRequestException -> _workCountList.value = listOf()
38+
is UnAuthorizedException -> _workCountList.value = listOf()
39+
else -> throwUnknownException(it)
40+
}
3441
}
3542
}
3643
}

feature/feature-home/src/main/java/com/comit/feature_home/vm/ShowScheduleViewModel.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ package com.comit.feature_home.vm
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.comit.domain.exception.BadRequestException
6+
import com.comit.domain.exception.NotFoundException
7+
import com.comit.domain.exception.UnAuthorizedException
8+
import com.comit.domain.exception.throwUnknownException
59
import com.comit.domain.usecase.schedule.DeletePersonalScheduleUseCase
610
import com.comit.domain.usecase.schedule.FetchPersonalScheduleUseCase
711
import com.comit.feature_home.mvi.FetchScheduleSideEffect
@@ -25,7 +29,6 @@ class ShowScheduleViewModel @Inject constructor(
2529

2630
override val container = container<FetchScheduleState, FetchScheduleSideEffect>(FetchScheduleState())
2731

28-
// TODO(limsaehyun): 예상치 못한 예외 시 throwUnknownException 반환 필요
2932
fun showSchedule(
3033
startAt: String,
3134
endAt: String,
@@ -41,12 +44,14 @@ class ShowScheduleViewModel @Inject constructor(
4144
)
4245
}
4346
}.onFailure {
44-
postSideEffect(FetchScheduleSideEffect.FetchScheduleFail)
47+
when (it) {
48+
is UnAuthorizedException -> postSideEffect(FetchScheduleSideEffect.TokenError)
49+
else -> throwUnknownException(it)
50+
}
4551
}
4652
}
4753
}
4854

49-
// TODO(limsaehyun): 예상치 못한 예외 시 throwUnknownException 반환 필요
5055
fun deleteSchedule(
5156
id: UUID
5257
) = intent {
@@ -56,7 +61,12 @@ class ShowScheduleViewModel @Inject constructor(
5661
).onSuccess {
5762
postSideEffect(FetchScheduleSideEffect.DeleteScheduleSuccess)
5863
}.onFailure {
59-
postSideEffect(FetchScheduleSideEffect.DeleteScheduleFail)
64+
when (it) {
65+
is BadRequestException -> postSideEffect(FetchScheduleSideEffect.DeleteScheduleDateError)
66+
is UnAuthorizedException -> postSideEffect(FetchScheduleSideEffect.TokenError)
67+
is NotFoundException -> postSideEffect(FetchScheduleSideEffect.DeleteScheduleCannotFound)
68+
else -> throwUnknownException(it)
69+
}
6070
}
6171
}
6272
}

0 commit comments

Comments
 (0)