Skip to content

Commit

Permalink
🔗 :: (#692) 외출 신청 버그
Browse files Browse the repository at this point in the history
🔗 :: (#692) 외출 신청 버그
  • Loading branch information
parkuiery authored Jun 13, 2024
2 parents 42ef6b5 + 09f74c8 commit d3d64bb
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()

versionCode = 13
versionName = "1.3.4"
versionCode = 14
versionName = "1.3.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.UUID

data class OutingApplicationTime(
val id: UUID,
val schoolId: UUID,
val startTime: String,
val endTime: String,
val available: Boolean,
Expand All @@ -21,6 +22,7 @@ fun List<OutingAvailableTimeResponse.AvailableTimeResponse>.toModel(): List<Outi
fun OutingAvailableTimeResponse.AvailableTimeResponse.toModel(): OutingApplicationTime =
OutingApplicationTime(
id = UUID.fromString(this.id),
schoolId = UUID.fromString(this.schoolId),
startTime = this.startTime,
endTime = this.endTime,
available = this.available,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.aliens.dms.android.data.outing.repository
import org.threeten.bp.DayOfWeek
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import org.threeten.bp.LocalTime
import team.aliens.dms.android.data.outing.model.CurrentAppliedOutingApplication
import team.aliens.dms.android.data.outing.model.OutingApplicationId
import team.aliens.dms.android.data.outing.model.OutingApplicationTime
Expand All @@ -13,8 +14,8 @@ abstract class OutingRepository {

abstract suspend fun applyOuting(
date: LocalDate,
startTime: LocalDateTime,
endTime: LocalDateTime,
startTime: LocalTime,
endTime: LocalTime,
type: String,
reason: String?,
companionIds: List<UUID>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package team.aliens.dms.android.data.outing.repository

import org.threeten.bp.DayOfWeek
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import org.threeten.bp.LocalTime
import org.threeten.bp.format.DateTimeFormatter
import team.aliens.dms.android.data.outing.model.CurrentAppliedOutingApplication
import team.aliens.dms.android.data.outing.model.OutingApplicationId
import team.aliens.dms.android.data.outing.model.OutingApplicationTime
import team.aliens.dms.android.data.outing.model.toModel
import team.aliens.dms.android.network.outing.datasource.OutingNetworkDataSource
import team.aliens.dms.android.network.outing.model.ApplyOutingRequest
import java.text.SimpleDateFormat
import java.util.UUID
import javax.inject.Inject

Expand All @@ -22,16 +21,16 @@ class OutingRepositoryImpl @Inject constructor(

override suspend fun applyOuting(
date: LocalDate,
startTime: LocalDateTime,
endTime: LocalDateTime,
startTime: LocalTime,
endTime: LocalTime,
type: String,
reason: String?,
companionIds: List<UUID>
): OutingApplicationId = outingNetworkDataSource.applyOuting(
req = ApplyOutingRequest(
date = date.format(DateTimeFormatter.ISO_LOCAL_DATE),
startTime = startTime.format(DateTimeFormatter.ofPattern("hh:mm:00")),
endTime = endTime.format(DateTimeFormatter.ofPattern("hh:mm:00")),
startTime = startTime.toString(),
endTime = endTime.toString(),
type = type,
reason = reason,
companionIds = companionIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.ramcosta.composedestinations.annotation.Destination
import kotlinx.coroutines.launch
import org.threeten.bp.DayOfWeek
import org.threeten.bp.LocalDateTime
import org.threeten.bp.LocalTime
import team.aliens.dms.android.core.designsystem.AlertDialog
import team.aliens.dms.android.core.designsystem.Button
import team.aliens.dms.android.core.designsystem.DmsTheme
Expand Down Expand Up @@ -107,11 +108,7 @@ fun OutingApplicationScreen(
onClick = {
viewModel.postIntent(
OutingIntent.UpdateOutingStartTime(
value = LocalDateTime.of(
// TODO: 죄송합니다..
2006,
5,
8,
value = LocalTime.of(
startTimePickerState.hour,
startTimePickerState.minute,
),
Expand Down Expand Up @@ -139,14 +136,10 @@ fun OutingApplicationScreen(
onClick = {
viewModel.postIntent(
OutingIntent.UpdateOutingEndTime(
value = LocalDateTime.of(
// TODO: 죄송합니다..
2006,
5,
8,
value = LocalTime.of(
endTimePickerState.hour,
endTimePickerState.minute,
),
)
)
)
onChangeShouldShowEndTimePicker(false)
Expand Down Expand Up @@ -336,10 +329,10 @@ fun OutingApplicationScreen(
modifier = Modifier.endPadding(),
text = stringResource(
id = R.string.format_date_yyyy_mm_dd_day_of_week,
uiState.capturedNow.year,
uiState.capturedNow.month.value,
uiState.capturedNow.dayOfMonth,
uiState.capturedNow.dayOfWeek.text,
uiState.outingDate.year,
uiState.outingDate.month.value,
uiState.outingDate.dayOfMonth,
uiState.outingDate.dayOfWeek.text,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.threeten.bp.LocalDateTime
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalTime
import team.aliens.dms.android.core.ui.mvi.BaseMviViewModel
import team.aliens.dms.android.core.ui.mvi.Intent
import team.aliens.dms.android.core.ui.mvi.SideEffect
Expand All @@ -15,6 +16,7 @@ import team.aliens.dms.android.data.outing.repository.OutingRepository
import team.aliens.dms.android.data.student.model.Student
import team.aliens.dms.android.data.student.repository.StudentRepository
import team.aliens.dms.android.shared.date.util.now
import team.aliens.dms.android.shared.date.util.timeNow
import team.aliens.dms.android.shared.date.util.today
import java.util.UUID
import javax.inject.Inject
Expand All @@ -31,6 +33,7 @@ class OutingViewModel @Inject constructor(
fetchCurrentAppliedOutingApplication()
fetchOutingTypes()
fetchStudents()
fetchOutingDate()
}

override fun processIntent(intent: OutingIntent) {
Expand Down Expand Up @@ -96,6 +99,15 @@ class OutingViewModel @Inject constructor(
}
}

private fun fetchOutingDate() {
val captureOutingDate: LocalDate = stateFlow.value.outingDate
if (now.hour >= 20) {
reduce(
newState = stateFlow.value.copy(outingDate = captureOutingDate.plusDays(1))
)
}
}

private fun fetchOutingTypes() = viewModelScope.launch(Dispatchers.IO) {
runCatching {
outingRepository.fetchOutingTypes(null)
Expand All @@ -120,14 +132,13 @@ class OutingViewModel @Inject constructor(
),
)

private fun updateOutingStartTime(value: LocalDateTime) = reduce(
private fun updateOutingStartTime(value: LocalTime) = reduce(
newState = stateFlow.value.copy(
selectedOutingStartTime = value,
),
)


private fun updateOutingEndTime(value: LocalDateTime) = reduce(
private fun updateOutingEndTime(value: LocalTime) = reduce(
newState = stateFlow.value.copy(
selectedOutingEndTime = value,
),
Expand All @@ -143,7 +154,7 @@ class OutingViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
runCatching {
outingRepository.applyOuting(
date = capturedState.capturedNow.toLocalDate(),
date = capturedState.outingDate,
startTime = capturedState.selectedOutingStartTime,
endTime = capturedState.selectedOutingEndTime,
type = capturedState.selectedOutingType,
Expand All @@ -157,7 +168,7 @@ class OutingViewModel @Inject constructor(
),
)
postSideEffect(OutingSideEffect.OutingApplicationSuccess(applicationId))
}.onSuccess {
}.onFailure {
postSideEffect(OutingSideEffect.OutingApplicationTimeError)
}
}
Expand Down Expand Up @@ -202,27 +213,26 @@ data class OutingUiState(
val outingTypes: List<String>?,
val selectedOutingType: String?,
val reason: String,
val capturedNow: LocalDateTime,
val selectedOutingStartTime: LocalDateTime,
val selectedOutingEndTime: LocalDateTime,
val outingDate: LocalDate,
val selectedOutingStartTime: LocalTime,
val selectedOutingEndTime: LocalTime,
val companionIds: List<UUID>,
val students: List<Student>?,
val selectedStudents: List<Student>,
val applicationId: UUID?,
) : UiState() {
companion object {
fun initial(): OutingUiState {
val capturedNow = now
return OutingUiState(
outingApplicationTime = null,
currentAppliedOutingApplication = null,
outingTypes = null,
selectedOutingType = null,
reason = "",
capturedNow = capturedNow,
outingDate = today,
// TODO: remove hard-coded string resources from viewmodel
selectedOutingEndTime = now,
selectedOutingStartTime = now,
selectedOutingEndTime = timeNow,
selectedOutingStartTime = timeNow,
companionIds = emptyList(),
students = null,
selectedStudents = emptyList(),
Expand All @@ -236,8 +246,8 @@ sealed class OutingIntent : Intent() {
data object CancelCurrentApplication : OutingIntent()
class UpdateSelectedOutingType(val value: String) : OutingIntent()
class UpdateReason(val value: String) : OutingIntent()
class UpdateOutingStartTime(val value: LocalDateTime) : OutingIntent()
class UpdateOutingEndTime(val value: LocalDateTime) : OutingIntent()
class UpdateOutingStartTime(val value: LocalTime) : OutingIntent()
class UpdateOutingEndTime(val value: LocalTime) : OutingIntent()
data object ApplyOuting : OutingIntent()
class SelectStudent(
val student: Student,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ data class OutingAvailableTimeResponse(
@SerializedName("outing_available_times") val availableTimes: List<AvailableTimeResponse>,
) {
data class AvailableTimeResponse(
@SerializedName("outing_available_time_id") val id: String,
@SerializedName("id") val id: String,
@SerializedName("school_id") val schoolId: String,
@SerializedName("outing_time") val startTime: String,
@SerializedName("arrival_time") val endTime: String,
@SerializedName("enabled") val available: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package team.aliens.dms.android.shared.date.util

import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import org.threeten.bp.LocalTime

val today: LocalDate
inline get() = LocalDate.now()

val now: LocalDateTime
inline get() = LocalDateTime.now()

val timeNow: LocalTime
inline get() = LocalTime.now()

0 comments on commit d3d64bb

Please sign in to comment.