Skip to content

Commit 91613b7

Browse files
authored
Merge pull request #137 from YAPP-Github/refactor/#136-routine-logic
[Refactor/#136] 홈화면 루틴 완료 로직을 리펙토링 합니다.
2 parents 67de431 + 2e44846 commit 91613b7

File tree

33 files changed

+473
-572
lines changed

33 files changed

+473
-572
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.threegap.bitnagil.data.routine.model.response
22

3-
import com.threegap.bitnagil.domain.routine.model.DayRoutines
3+
import com.threegap.bitnagil.domain.routine.model.DailyRoutines
44
import kotlinx.serialization.SerialName
55
import kotlinx.serialization.Serializable
66

@@ -12,8 +12,8 @@ data class DayRoutinesDto(
1212
val allCompleted: Boolean,
1313
)
1414

15-
fun DayRoutinesDto.toDomain(): DayRoutines =
16-
DayRoutines(
17-
routineList = routineList.map { it.toDomain() },
18-
allCompleted = allCompleted,
15+
fun DayRoutinesDto.toDomain(): DailyRoutines =
16+
DailyRoutines(
17+
routines = routineList.map { it.toDomain() },
18+
isAllCompleted = allCompleted,
1919
)

data/src/main/java/com/threegap/bitnagil/data/routine/model/response/RoutineDto.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ data class RoutineDto(
3636

3737
fun RoutineDto.toDomain(): Routine =
3838
Routine(
39-
routineId = this.routineId,
40-
routineName = this.routineName,
41-
repeatDay = this.repeatDay.map { DayOfWeek.fromString(it) },
39+
id = this.routineId,
40+
name = this.routineName,
41+
repeatDays = this.repeatDay.map { DayOfWeek.fromString(it) },
4242
executionTime = this.executionTime,
4343
routineDate = this.routineDate,
44-
routineCompleteYn = this.routineCompleteYn,
44+
isCompleted = this.routineCompleteYn,
4545
subRoutineNames = this.subRoutineNames,
46-
subRoutineCompleteYn = this.subRoutineCompleteYn,
46+
subRoutineCompletionStates = this.subRoutineCompleteYn,
4747
recommendedRoutineType = RecommendedRoutineType.fromString(this.recommendedRoutineType),
48-
routineDeletedYn = routineDeletedYn,
48+
isDeleted = routineDeletedYn,
4949
startDate = this.routineStartDate,
5050
endDate = this.routineEndDate,
5151
)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.threegap.bitnagil.data.routine.model.response
22

3-
import com.threegap.bitnagil.domain.routine.model.Routines
3+
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
44
import kotlinx.serialization.SerialName
55
import kotlinx.serialization.Serializable
66

@@ -11,8 +11,8 @@ data class RoutinesResponseDto(
1111
)
1212

1313
fun RoutinesResponseDto.toDomain() =
14-
Routines(
15-
routines = this.routines.mapValues { (_, dayRoutinesDto) ->
14+
RoutineSchedule(
15+
dailyRoutines = this.routines.mapValues { (_, dayRoutinesDto) ->
1616
dayRoutinesDto.toDomain()
1717
},
1818
)

data/src/main/java/com/threegap/bitnagil/data/routine/repositoryImpl/RoutineRepositoryImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import com.threegap.bitnagil.data.routine.model.request.toDto
55
import com.threegap.bitnagil.data.routine.model.response.toDomain
66
import com.threegap.bitnagil.domain.routine.model.Routine
77
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos
8-
import com.threegap.bitnagil.domain.routine.model.Routines
8+
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
99
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
1010
import javax.inject.Inject
1111

1212
class RoutineRepositoryImpl @Inject constructor(
1313
private val routineRemoteDataSource: RoutineRemoteDataSource,
1414
) : RoutineRepository {
15-
override suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<Routines> =
15+
override suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<RoutineSchedule> =
1616
routineRemoteDataSource.fetchWeeklyRoutines(startDate, endDate)
1717
.map { it.toDomain() }
1818

domain/src/main/java/com/threegap/bitnagil/domain/emotion/usecase/FetchTodayEmotionUseCase.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ package com.threegap.bitnagil.domain.emotion.usecase
22

33
import com.threegap.bitnagil.domain.emotion.model.TodayEmotion
44
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
5+
import java.time.LocalDate
56
import javax.inject.Inject
67

78
class FetchTodayEmotionUseCase @Inject constructor(
89
private val emotionRepository: EmotionRepository,
910
) {
10-
suspend operator fun invoke(currentDate: String): Result<TodayEmotion?> =
11-
emotionRepository.fetchTodayEmotion(currentDate)
11+
suspend operator fun invoke(): Result<TodayEmotion?> {
12+
val currentDate = LocalDate.now().toString()
13+
return emotionRepository.fetchTodayEmotion(currentDate)
14+
}
1215
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.threegap.bitnagil.domain.routine.model
2+
3+
/**
4+
* 특정 하루("일간")의 루틴 정보.
5+
* [RoutineSchedule] Map의 '값(value)'으로 사용됩니다.
6+
*
7+
* @property routines 해당 날짜에 포함된 [Routine](개별 루틴)의 목록.
8+
* @property isAllCompleted 해당 날짜의 모든 루틴이 완료되었는지 여부.
9+
*/
10+
data class DailyRoutines(
11+
val routines: List<Routine>,
12+
val isAllCompleted: Boolean,
13+
)

domain/src/main/java/com/threegap/bitnagil/domain/routine/model/DayRoutines.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.threegap.bitnagil.domain.routine.model
22

33
data class Routine(
4-
val routineId: String,
5-
val routineName: String,
6-
val repeatDay: List<DayOfWeek>,
4+
val id: String,
5+
val name: String,
6+
val repeatDays: List<DayOfWeek>,
77
val executionTime: String,
88
val startDate: String,
99
val endDate: String,
1010
val routineDate: String,
11-
val routineCompleteYn: Boolean,
12-
val routineDeletedYn: Boolean,
11+
val isCompleted: Boolean,
12+
val isDeleted: Boolean,
1313
val subRoutineNames: List<String>,
14-
val subRoutineCompleteYn: List<Boolean>,
14+
val subRoutineCompletionStates: List<Boolean>,
1515
val recommendedRoutineType: RecommendedRoutineType?,
1616
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.threegap.bitnagil.domain.routine.model
2+
3+
/**
4+
* 특정 기간(예: 주간, 월간) 동안의 루틴 일정표.
5+
*
6+
* @property dailyRoutines 날짜(String, "YYYY-MM-DD")를 key로,
7+
* 해당 날짜의 루틴 정보([DailyRoutines])를 value로 가지는 Map.
8+
*/
9+
data class RoutineSchedule(
10+
val dailyRoutines: Map<String, DailyRoutines>,
11+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.threegap.bitnagil.domain.routine.model
2+
3+
data class RoutineToggleState(
4+
val isCompleted: Boolean,
5+
val subRoutinesIsCompleted: List<Boolean>,
6+
)

0 commit comments

Comments
 (0)