Skip to content

Commit

Permalink
#18 [FEAT] 선택된 시간 엔티티로 내보내는 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
gaeulzzang committed Jan 9, 2025
1 parent 68b9f55 commit c46440e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AvailableTimeEntity>) -> Unit
) {
val days = availablePeriods.dates.size
val timeSlots =
Expand Down Expand Up @@ -124,6 +126,12 @@ fun NoostakEditableTimeTable(
} else {
selectedCells.add(cell)
}
onSelectedTimesChanged(
TimeTable().getSelectedTimes(
selectedCells,
availablePeriods
)
)
}
},
contentAlignment = Alignment.Center
Expand Down Expand Up @@ -157,7 +165,8 @@ fun NoostakEditableTimeTable1Preview() {
) {
NoostakEditableTimeTable(
availablePeriods = mockAvailablePeriods,
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onSelectedTimesChanged = { }
)
}
}
Expand Down
33 changes: 27 additions & 6 deletions core/src/main/java/com/sopt/core/util/timetable/TimeTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ 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
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))
Expand Down Expand Up @@ -91,7 +92,6 @@ class TimeTable {
columnIndex: Int,
data: PeriodEntity
): String {
// 셀 텍스트 결정 로직
val startHour = extractHour(extractTime(data.startTime))

return when (cellType) {
Expand All @@ -109,7 +109,31 @@ class TimeTable {
}
}

fun formatDateTimeToCustomFormat(dateTime: String): String {
fun getSelectedTimes(
selectedCells: List<Pair<Int, Int>>,
availablePeriods: PeriodEntity
): List<AvailableTimeEntity> {
val selectedTimes = mutableListOf<AvailableTimeEntity>()
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)
Expand All @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -122,7 +123,9 @@ fun AppointmentCheckScreen(
end.linkTo(parent.end)
height = Dimension.fillToConstraints
}
)
) {
Timber.d("selectedData: $it")
}

// 버튼 (항상 하단 고정)
NoostakBottomButton(
Expand Down

0 comments on commit c46440e

Please sign in to comment.