Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.threegap.bitnagil.data.routine.model.response

import com.threegap.bitnagil.domain.routine.model.DayRoutines
import com.threegap.bitnagil.domain.routine.model.DailyRoutines
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -12,8 +12,8 @@ data class DayRoutinesDto(
val allCompleted: Boolean,
)

fun DayRoutinesDto.toDomain(): DayRoutines =
DayRoutines(
routineList = routineList.map { it.toDomain() },
allCompleted = allCompleted,
fun DayRoutinesDto.toDomain(): DailyRoutines =
DailyRoutines(
routines = routineList.map { it.toDomain() },
isAllCompleted = allCompleted,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ data class RoutineDto(

fun RoutineDto.toDomain(): Routine =
Routine(
routineId = this.routineId,
routineName = this.routineName,
repeatDay = this.repeatDay.map { DayOfWeek.fromString(it) },
id = this.routineId,
name = this.routineName,
repeatDays = this.repeatDay.map { DayOfWeek.fromString(it) },
executionTime = this.executionTime,
routineDate = this.routineDate,
routineCompleteYn = this.routineCompleteYn,
isCompleted = this.routineCompleteYn,
subRoutineNames = this.subRoutineNames,
subRoutineCompleteYn = this.subRoutineCompleteYn,
subRoutineCompletionStates = this.subRoutineCompleteYn,
recommendedRoutineType = RecommendedRoutineType.fromString(this.recommendedRoutineType),
routineDeletedYn = routineDeletedYn,
isDeleted = routineDeletedYn,
startDate = this.routineStartDate,
endDate = this.routineEndDate,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.threegap.bitnagil.data.routine.model.response

import com.threegap.bitnagil.domain.routine.model.Routines
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

Expand All @@ -11,8 +11,8 @@ data class RoutinesResponseDto(
)

fun RoutinesResponseDto.toDomain() =
Routines(
routines = this.routines.mapValues { (_, dayRoutinesDto) ->
RoutineSchedule(
dailyRoutines = this.routines.mapValues { (_, dayRoutinesDto) ->
dayRoutinesDto.toDomain()
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import com.threegap.bitnagil.data.routine.model.request.toDto
import com.threegap.bitnagil.data.routine.model.response.toDomain
import com.threegap.bitnagil.domain.routine.model.Routine
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos
import com.threegap.bitnagil.domain.routine.model.Routines
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
import javax.inject.Inject

class RoutineRepositoryImpl @Inject constructor(
private val routineRemoteDataSource: RoutineRemoteDataSource,
) : RoutineRepository {
override suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<Routines> =
override suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<RoutineSchedule> =
routineRemoteDataSource.fetchWeeklyRoutines(startDate, endDate)
.map { it.toDomain() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.threegap.bitnagil.domain.emotion.usecase

import com.threegap.bitnagil.domain.emotion.model.TodayEmotion
import com.threegap.bitnagil.domain.emotion.repository.EmotionRepository
import java.time.LocalDate
import javax.inject.Inject

class FetchTodayEmotionUseCase @Inject constructor(
private val emotionRepository: EmotionRepository,
) {
suspend operator fun invoke(currentDate: String): Result<TodayEmotion?> =
emotionRepository.fetchTodayEmotion(currentDate)
suspend operator fun invoke(): Result<TodayEmotion?> {
val currentDate = LocalDate.now().toString()
Comment thread
l5x5l marked this conversation as resolved.
return emotionRepository.fetchTodayEmotion(currentDate)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.threegap.bitnagil.domain.routine.model

/**
* 특정 하루("일간")의 루틴 정보.
* [RoutineSchedule] Map의 '값(value)'으로 사용됩니다.
*
* @property routines 해당 날짜에 포함된 [Routine](개별 루틴)의 목록.
* @property isAllCompleted 해당 날짜의 모든 루틴이 완료되었는지 여부.
*/
data class DailyRoutines(
val routines: List<Routine>,
val isAllCompleted: Boolean,
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.threegap.bitnagil.domain.routine.model

data class Routine(
val routineId: String,
val routineName: String,
val repeatDay: List<DayOfWeek>,
val id: String,
val name: String,
val repeatDays: List<DayOfWeek>,
val executionTime: String,
val startDate: String,
val endDate: String,
val routineDate: String,
val routineCompleteYn: Boolean,
val routineDeletedYn: Boolean,
val isCompleted: Boolean,
val isDeleted: Boolean,
val subRoutineNames: List<String>,
val subRoutineCompleteYn: List<Boolean>,
val subRoutineCompletionStates: List<Boolean>,
val recommendedRoutineType: RecommendedRoutineType?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.threegap.bitnagil.domain.routine.model

/**
* 특정 기간(예: 주간, 월간) 동안의 루틴 일정표.
*
* @property dailyRoutines 날짜(String, "YYYY-MM-DD")를 key로,
* 해당 날짜의 루틴 정보([DailyRoutines])를 value로 가지는 Map.
*/
data class RoutineSchedule(
val dailyRoutines: Map<String, DailyRoutines>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.threegap.bitnagil.domain.routine.model

data class RoutineToggleState(
val isCompleted: Boolean,
val subRoutinesIsCompleted: List<Boolean>,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.threegap.bitnagil.domain.routine.repository

import com.threegap.bitnagil.domain.routine.model.Routine
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos
import com.threegap.bitnagil.domain.routine.model.Routines
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule

interface RoutineRepository {
suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<Routines>
suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<RoutineSchedule>
suspend fun syncRoutineCompletion(routineCompletionInfos: RoutineCompletionInfos): Result<Unit>
suspend fun getRoutine(routineId: String): Result<Routine>
suspend fun deleteRoutine(routineId: String): Result<Unit>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.threegap.bitnagil.domain.routine.usecase

import com.threegap.bitnagil.domain.routine.model.Routines
import com.threegap.bitnagil.domain.routine.model.RoutineSchedule
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
import javax.inject.Inject

class FetchWeeklyRoutinesUseCase @Inject constructor(
private val routineRepository: RoutineRepository,
) {
suspend operator fun invoke(startDate: String, endDate: String): Result<Routines> =
routineRepository.fetchWeeklyRoutines(startDate, endDate)
suspend operator fun invoke(startDate: String, endDate: String): Result<RoutineSchedule> {
return routineRepository.fetchWeeklyRoutines(startDate, endDate)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.threegap.bitnagil.domain.routine.usecase

import com.threegap.bitnagil.domain.routine.model.RoutineToggleState
import javax.inject.Inject

class ToggleRoutineUseCase @Inject constructor() {

/**
* 메인 루틴을 토글합니다.
* 메인 루틴이 토글되면 모든 서브 루틴도 같은 상태로 변경됩니다.
*
* @param isCompleted 현재 메인 루틴 완료 상태
* @param subRoutineStates 현재 서브 루틴 완료 상태 리스트
* @return 토글된 루틴 상태
*/
fun toggleMainRoutine(
isCompleted: Boolean,
subRoutineStates: List<Boolean>,
): RoutineToggleState {
val newIsCompleted = !isCompleted
val newSubRoutineStates = subRoutineStates.map { newIsCompleted }

return RoutineToggleState(
isCompleted = newIsCompleted,
subRoutinesIsCompleted = newSubRoutineStates,
)
}

/**
* 특정 서브 루틴을 토글합니다.
* 모든 서브 루틴이 완료되면 메인 루틴도 자동으로 완료됩니다.
*
* @param index 토글할 서브 루틴의 인덱스
* @param subRoutineStates 현재 서브 루틴 완료 상태 리스트
* @return 토글된 루틴 상태, 잘못된 인덱스인 경우 null
*/
fun toggleSubRoutine(
index: Int,
subRoutineStates: List<Boolean>,
): RoutineToggleState? {
if (index !in subRoutineStates.indices) return null

val newState = !subRoutineStates[index]
val newSubRoutineStates = subRoutineStates.toMutableList().apply {
this[index] = newState
}

val allCompleted = newSubRoutineStates.all { it }

return RoutineToggleState(
isCompleted = allCompleted,
subRoutinesIsCompleted = newSubRoutineStates,
)
}
}
Loading