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.common

import com.threegap.bitnagil.domain.error.model.BitnagilError
import com.threegap.bitnagil.domain.common.model.BitnagilError
import com.threegap.bitnagil.network.model.BaseResponse
import com.threegap.bitnagil.network.model.ErrorResponse
import kotlinx.serialization.json.Json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.threegap.bitnagil.data.writeroutine.repositoryImpl
import com.threegap.bitnagil.data.writeroutine.datasource.WriteRoutineDataSource
import com.threegap.bitnagil.data.writeroutine.model.request.EditRoutineRequest
import com.threegap.bitnagil.data.writeroutine.model.request.RegisterRoutineRequest
import com.threegap.bitnagil.domain.writeroutine.model.Date
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
import com.threegap.bitnagil.domain.writeroutine.model.RoutineUpdateType
import com.threegap.bitnagil.domain.writeroutine.model.Time
import com.threegap.bitnagil.domain.writeroutine.model.WriteRoutineEvent
import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import java.time.LocalDate
import java.time.LocalTime
import javax.inject.Inject

class WriteRoutineRepositoryImpl @Inject constructor(
Expand All @@ -20,18 +20,18 @@ class WriteRoutineRepositoryImpl @Inject constructor(
override suspend fun registerRoutine(
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
recommendedRoutineType: String?,
): Result<Unit> {
val request = RegisterRoutineRequest(
routineName = name,
repeatDay = repeatDay.map { it.fullName },
executionTime = startTime.toFormattedString(),
routineStartDate = startDate.toFormattedString(),
routineEndDate = endDate.toFormattedString(),
executionTime = startTime.toString(),
routineStartDate = startDate.toString(),
routineEndDate = endDate.toString(),
subRoutineName = subRoutines,
recommendedRoutineType = recommendedRoutineType,
)
Expand All @@ -47,19 +47,19 @@ class WriteRoutineRepositoryImpl @Inject constructor(
routineUpdateType: RoutineUpdateType,
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
): Result<Unit> {
val request = EditRoutineRequest(
routineId = routineId,
updateApplyDate = routineUpdateType.value,
routineName = name,
repeatDay = repeatDay.map { it.fullName },
executionTime = startTime.toFormattedString(),
routineStartDate = startDate.toFormattedString(),
routineEndDate = endDate.toFormattedString(),
executionTime = startTime.toString(),
routineStartDate = startDate.toString(),
routineEndDate = endDate.toString(),
subRoutineName = subRoutines,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.threegap.bitnagil.domain.error.model
package com.threegap.bitnagil.domain.common.model

data class BitnagilError(
val code: String,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.threegap.bitnagil.domain.writeroutine.repository

import com.threegap.bitnagil.domain.writeroutine.model.Date
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
import com.threegap.bitnagil.domain.writeroutine.model.RoutineUpdateType
import com.threegap.bitnagil.domain.writeroutine.model.Time
import com.threegap.bitnagil.domain.writeroutine.model.WriteRoutineEvent
import kotlinx.coroutines.flow.Flow
import java.time.LocalDate
import java.time.LocalTime

interface WriteRoutineRepository {
suspend fun registerRoutine(
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
recommendedRoutineType: String?,
): Result<Unit>
Expand All @@ -23,9 +23,9 @@ interface WriteRoutineRepository {
routineUpdateType: RoutineUpdateType,
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
): Result<Unit>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.threegap.bitnagil.domain.writeroutine.usecase

import com.threegap.bitnagil.domain.writeroutine.model.Date
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
import com.threegap.bitnagil.domain.writeroutine.model.RoutineUpdateType
import com.threegap.bitnagil.domain.writeroutine.model.Time
import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
import java.time.LocalDate
import java.time.LocalTime
import javax.inject.Inject

class EditRoutineUseCase @Inject constructor(
Expand All @@ -15,9 +15,9 @@ class EditRoutineUseCase @Inject constructor(
routineUpdateType: RoutineUpdateType,
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
): Result<Unit> {
return writeRoutineRepository.editRoutine(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.threegap.bitnagil.domain.writeroutine.usecase

import com.threegap.bitnagil.domain.writeroutine.model.Date
import com.threegap.bitnagil.domain.writeroutine.model.RepeatDay
import com.threegap.bitnagil.domain.writeroutine.model.Time
import com.threegap.bitnagil.domain.writeroutine.repository.WriteRoutineRepository
import java.time.LocalDate
import java.time.LocalTime
import javax.inject.Inject

class RegisterRoutineUseCase @Inject constructor(
Expand All @@ -12,9 +12,9 @@ class RegisterRoutineUseCase @Inject constructor(
suspend operator fun invoke(
name: String,
repeatDay: List<RepeatDay>,
startTime: Time,
startDate: Date,
endDate: Date,
startTime: LocalTime,
startDate: LocalDate,
endDate: LocalDate,
subRoutines: List<String>,
recommendedRoutineType: String?,
): Result<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class WriteRoutineViewModel @AssistedInject constructor(
routineName = routine.name,
repeatDays = repeatDays,
repeatType = repeatType,
startTime = Time.fromDomainTimeString(routine.executionTime),
startTime = Time.fromString(routine.executionTime),
startDate = Date.fromString(routine.startDate),
endDate = Date.fromString(routine.endDate),
subRoutineNames = listOf(
Expand Down Expand Up @@ -137,7 +137,7 @@ class WriteRoutineViewModel @AssistedInject constructor(
routineName = routine.name,
repeatDays = SelectableDay.defaultList,
repeatType = null,
startTime = Time.fromDomainTimeString(routine.executionTime),
startTime = Time.fromString(routine.executionTime),
startDate = Date.now(),
endDate = Date.now(),
subRoutineNames = listOf(
Expand Down Expand Up @@ -372,9 +372,9 @@ class WriteRoutineViewModel @AssistedInject constructor(
val registerRoutineResult = registerRoutineUseCase(
name = currentState.routineName,
repeatDay = repeatDay,
startTime = startTime.toDomainTime(),
startDate = if (noRepeatRoutine) Date.now().toDomainDate() else currentState.startDate.toDomainDate(),
endDate = if (noRepeatRoutine) Date.now().toDomainDate() else currentState.endDate.toDomainDate(),
startTime = startTime.toLocalTime(),
startDate = if (noRepeatRoutine) Date.now().toLocalDate() else currentState.startDate.toLocalDate(),
endDate = if (noRepeatRoutine) Date.now().toLocalDate() else currentState.endDate.toLocalDate(),
subRoutines = subRoutines,
recommendedRoutineType = currentState.recommendedRoutineType,
)
Expand Down Expand Up @@ -409,9 +409,9 @@ class WriteRoutineViewModel @AssistedInject constructor(
routineUpdateType = routineUpdateType,
name = currentState.routineName,
repeatDay = repeatDay,
startTime = startTime.toDomainTime(),
startDate = currentState.startDate.toDomainDate(),
endDate = currentState.endDate.toDomainDate(),
startTime = startTime.toLocalTime(),
startDate = currentState.startDate.toLocalDate(),
endDate = currentState.endDate.toLocalDate(),
subRoutines = subRoutines,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.threegap.bitnagil.presentation.writeroutine.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import com.threegap.bitnagil.domain.writeroutine.model.Date as DomainDate
import java.time.LocalDate

@Parcelize
data class Date(
Expand All @@ -11,11 +11,14 @@ data class Date(
val day: Int,
) : Parcelable {
companion object {
fun now() = Date(
year = java.time.LocalDate.now().year,
month = java.time.LocalDate.now().monthValue,
day = java.time.LocalDate.now().dayOfMonth,
)
fun now(): Date {
val currentDate = LocalDate.now()
return Date(
year = currentDate.year,
month = currentDate.monthValue,
day = currentDate.dayOfMonth,
)
}

fun min(d1: Date, d2: Date): Date {
if (d1.year < d2.year) return d1
Expand Down Expand Up @@ -51,21 +54,14 @@ data class Date(
fun toYearShrinkageFormattedString(): String = "%02d.%02d.%02d".format((year % 100), month, day)

fun checkInRange(startDate: Date?, endDate: Date?): Boolean {
val appliedStartDate = startDate ?: Date(year = 2000, month = 1, day = 1)
val appliedEndDate = endDate ?: Date(year = 2999, month = 12, day = 31)

val startValue = appliedStartDate.year * 10000 + appliedStartDate.month * 100 + appliedStartDate.day
val endValue = appliedEndDate.year * 10000 + appliedEndDate.month * 100 + appliedEndDate.day
val targetValue = year * 10000 + month * 100 + day
val current = toLocalDate()
val start = startDate?.toLocalDate() ?: LocalDate.of(2000, 1, 1)
val end = endDate?.toLocalDate() ?: LocalDate.of(2999, 12, 31)

return targetValue in startValue..endValue
return !current.isBefore(start) && !current.isAfter(end)
}

fun toDomainDate(): DomainDate {
return DomainDate(
year = year,
month = month,
day = day,
)
fun toLocalDate(): LocalDate {
return LocalDate.of(year, month, day)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.threegap.bitnagil.presentation.writeroutine.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import java.time.LocalTime
import kotlin.text.format
import com.threegap.bitnagil.domain.writeroutine.model.Time as DomainTime

@Parcelize
data class Time(
Expand All @@ -19,18 +19,18 @@ data class Time(
val Init = Time(hour = 12, minute = 0)
val AllDay = Time(hour = 0, minute = 0)

fun fromDomainTimeString(timeString: String): Time {
try {
fun fromString(timeString: String): Time {
return try {
val (hour, minute) = timeString.split(":").map { it.toInt() }
return Time(hour = hour, minute = minute)
Time(hour = hour, minute = minute)
} catch (_: Exception) {
return Time(hour = 12, minute = 0)
Init
}
}
}

fun toDomainTime(): DomainTime {
return DomainTime(hour = hour, minute = minute)
fun toLocalTime(): LocalTime {
return LocalTime.of(hour, minute)
}

fun toAmPmFormattedString(): String {
Expand Down