From c46440e4c6a5c64b099e46d17ca5fb8b86746088 Mon Sep 17 00:00:00 2001 From: gaeulzzang Date: Fri, 10 Jan 2025 02:58:04 +0900 Subject: [PATCH] =?UTF-8?q?#18=20[FEAT]=20=EC=84=A0=ED=83=9D=EB=90=9C=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EC=97=94=ED=8B=B0=ED=8B=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=82=B4=EB=B3=B4=EB=82=B4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timetable/NoostakEditableTimeTable.kt | 13 ++++++-- .../com/sopt/core/util/timetable/TimeTable.kt | 33 +++++++++++++++---- ...ilableTimeEntity.kt => TimeTableEntity.kt} | 0 .../appointmentCheck/AppointmentCheckRoute.kt | 5 ++- 4 files changed, 42 insertions(+), 9 deletions(-) rename domain/src/main/java/com/sopt/domain/entity/{AvailableTimeEntity.kt => TimeTableEntity.kt} (100%) diff --git a/core/src/main/java/com/sopt/core/designsystem/component/timetable/NoostakEditableTimeTable.kt b/core/src/main/java/com/sopt/core/designsystem/component/timetable/NoostakEditableTimeTable.kt index d4c2ea82..b58be53d 100644 --- a/core/src/main/java/com/sopt/core/designsystem/component/timetable/NoostakEditableTimeTable.kt +++ b/core/src/main/java/com/sopt/core/designsystem/component/timetable/NoostakEditableTimeTable.kt @@ -29,12 +29,14 @@ import com.sopt.core.designsystem.theme.NoostakTheme import com.sopt.core.extension.noRippleClickable import com.sopt.core.type.CellType import com.sopt.core.util.timetable.TimeTable +import com.sopt.domain.entity.AvailableTimeEntity import com.sopt.domain.entity.PeriodEntity @Composable fun NoostakEditableTimeTable( availablePeriods: PeriodEntity, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, + onSelectedTimesChanged: (List) -> Unit ) { val days = availablePeriods.dates.size val timeSlots = @@ -124,6 +126,12 @@ fun NoostakEditableTimeTable( } else { selectedCells.add(cell) } + onSelectedTimesChanged( + TimeTable().getSelectedTimes( + selectedCells, + availablePeriods + ) + ) } }, contentAlignment = Alignment.Center @@ -157,7 +165,8 @@ fun NoostakEditableTimeTable1Preview() { ) { NoostakEditableTimeTable( availablePeriods = mockAvailablePeriods, - modifier = Modifier.fillMaxWidth() + modifier = Modifier.fillMaxWidth(), + onSelectedTimesChanged = { } ) } } diff --git a/core/src/main/java/com/sopt/core/util/timetable/TimeTable.kt b/core/src/main/java/com/sopt/core/util/timetable/TimeTable.kt index e8e9cf3c..eb46cdd8 100644 --- a/core/src/main/java/com/sopt/core/util/timetable/TimeTable.kt +++ b/core/src/main/java/com/sopt/core/util/timetable/TimeTable.kt @@ -5,7 +5,9 @@ import androidx.compose.ui.graphics.Color import com.sopt.core.designsystem.theme.NoostakTheme import com.sopt.core.type.AvailabilityLevel import com.sopt.core.type.CellType +import com.sopt.domain.entity.AvailableTimeEntity import com.sopt.domain.entity.PeriodEntity +import com.sopt.domain.entity.TimeEntity import com.sopt.domain.entity.TimeTableEntity import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -13,7 +15,6 @@ import java.time.format.TextStyle import java.util.Locale class TimeTable { - // 시간 차이를 계산 (24시간 형식 기준) fun calculateTimeSlots(startTime: String, endTime: String): Int { val startHour = extractHour(extractTime(startTime)) val endHour = extractHour(extractTime(endTime)) @@ -91,7 +92,6 @@ class TimeTable { columnIndex: Int, data: PeriodEntity ): String { - // 셀 텍스트 결정 로직 val startHour = extractHour(extractTime(data.startTime)) return when (cellType) { @@ -109,7 +109,31 @@ class TimeTable { } } - fun formatDateTimeToCustomFormat(dateTime: String): String { + fun getSelectedTimes( + selectedCells: List>, + availablePeriods: PeriodEntity + ): List { + val selectedTimes = mutableListOf() + val selectedCellsByDate = selectedCells.groupBy { it.second } + selectedCellsByDate.forEach { (dateColumnIndex, cells) -> + val date = availablePeriods.dates.getOrNull(dateColumnIndex - 1) ?: return@forEach + val times = cells.map { (rowIndex, _) -> + val startHour = extractHour(extractTime(availablePeriods.startTime)) + (rowIndex - 1) + val endHour = startHour + 1 + TimeEntity( + memberStartTime = "${extractDate(date)}T${String.format("%02d", startHour)}:00:00", + memberEndTime = "${extractDate(date)}T${String.format("%02d", endHour)}:00:00" + ) + } + if (times.isNotEmpty()) { + selectedTimes.add(AvailableTimeEntity(date = date, times = times)) + } + } + + return selectedTimes + } + + private fun formatDateTimeToCustomFormat(dateTime: String): String { val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss") val parsedDate = LocalDateTime.parse(dateTime, formatter) val dayOfWeek = parsedDate.dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN) @@ -119,12 +143,9 @@ class TimeTable { return "$dayOfWeek\n$month/$day" } - // 공통적으로 사용하는 시간 추출 로직 private fun extractTime(dateTime: String): String = dateTime.substringAfter('T') - // 공통적으로 사용하는 날짜 추출 로직 private fun extractDate(dateTime: String): String = dateTime.substringBefore('T') - // 공통적으로 사용하는 시간만 숫자로 변환 private fun extractHour(time: String): Int = time.substringBefore(':').toInt() } diff --git a/domain/src/main/java/com/sopt/domain/entity/AvailableTimeEntity.kt b/domain/src/main/java/com/sopt/domain/entity/TimeTableEntity.kt similarity index 100% rename from domain/src/main/java/com/sopt/domain/entity/AvailableTimeEntity.kt rename to domain/src/main/java/com/sopt/domain/entity/TimeTableEntity.kt diff --git a/presentation/src/main/java/com/sopt/presentation/appointment/appointmentCheck/AppointmentCheckRoute.kt b/presentation/src/main/java/com/sopt/presentation/appointment/appointmentCheck/AppointmentCheckRoute.kt index 7ec7387d..89bb152c 100644 --- a/presentation/src/main/java/com/sopt/presentation/appointment/appointmentCheck/AppointmentCheckRoute.kt +++ b/presentation/src/main/java/com/sopt/presentation/appointment/appointmentCheck/AppointmentCheckRoute.kt @@ -29,6 +29,7 @@ import com.sopt.core.designsystem.theme.NoostakTheme import com.sopt.domain.entity.PeriodEntity import com.sopt.domain.entity.TimeEntity import com.sopt.presentation.R +import timber.log.Timber @Composable fun AppointmentCheckRoute( @@ -122,7 +123,9 @@ fun AppointmentCheckScreen( end.linkTo(parent.end) height = Dimension.fillToConstraints } - ) + ) { + Timber.d("selectedData: $it") + } // 버튼 (항상 하단 고정) NoostakBottomButton(