-
Notifications
You must be signed in to change notification settings - Fork 1
640 시간에서 교시 변환 시 동작하는 알고리즘 버그 수정 #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "640-\uC2DC\uAC04\uC5D0\uC11C-\uAD50\uC2DC-\uBCC0\uD658-\uC2DC-\uB3D9\uC791\uD558\uB294-\uC54C\uACE0\uB9AC\uC998-\uBC84\uADF8-\uC218\uC815"
Changes from all commits
c44aae2
6c2374a
a9f7b75
fc3774c
20dfc92
ca8abf6
abf2875
c01f7bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package dsm.pick2024.domain.attendance.domain.service | |
| import dsm.pick2024.domain.application.enums.ApplicationType | ||
| import dsm.pick2024.domain.attendance.domain.Attendance | ||
| import dsm.pick2024.domain.attendance.enums.AttendanceStatus | ||
| import dsm.pick2024.domain.attendance.exception.InvalidPeriodException | ||
| import org.springframework.stereotype.Component | ||
| import java.time.LocalTime | ||
|
|
||
|
|
@@ -14,7 +15,7 @@ class AttendanceService { | |
| LocalTime.of(8, 40) to LocalTime.of(9, 40), // 1교시 | ||
| LocalTime.of(9, 40) to LocalTime.of(10, 40), // 2교시 | ||
| LocalTime.of(10, 40) to LocalTime.of(11, 40), // 3교시 | ||
| LocalTime.of(12, 40) to LocalTime.of(13, 30), // 4교시 | ||
| LocalTime.of(11, 40) to LocalTime.of(13, 30), // 4교시 | ||
| LocalTime.of(13, 30) to LocalTime.of(14, 40), // 5교시 | ||
| LocalTime.of(14, 30) to LocalTime.of(15, 30), // 6교시 | ||
| LocalTime.of(15, 30) to LocalTime.of(16, 30), // 7교시 | ||
|
|
@@ -29,17 +30,70 @@ class AttendanceService { | |
| } | ||
|
|
||
| // 교시 혹은 시간을 기반으로 교시 목록을 반환하는 함수 | ||
| fun translateApplication(start: String, end: String?, applicationType: ApplicationType): List<String> { | ||
| fun translateApplication(start: String, end: String, applicationType: ApplicationType): Pair<String, String> { | ||
| return when (applicationType) { | ||
| ApplicationType.PERIOD -> listOf(start, end!!) | ||
| ApplicationType.PERIOD -> Pair(start, end) | ||
| ApplicationType.TIME -> { | ||
| val startTime = LocalTime.parse(start) | ||
| val endTime = end?.let { LocalTime.parse(it) } | ||
| val endTime = LocalTime.parse(end) | ||
| getMatchPeriods(startTime, endTime) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun checkApplicationTime(applicationType: ApplicationType, start: String, end: String) { | ||
| when (applicationType) { | ||
| ApplicationType.TIME -> { | ||
| val startTime = LocalTime.parse(start) | ||
| val endTime = LocalTime.parse(end) | ||
| if (startTime > endTime || | ||
| endTime > LocalTime.of(20, 30) || | ||
| startTime < LocalTime.of(8, 30) | ||
| ) { | ||
| throw InvalidPeriodException | ||
| } | ||
| } | ||
| ApplicationType.PERIOD -> { | ||
| val startPeriod = start.replace("교시", "").toIntOrNull() ?: throw InvalidPeriodException | ||
| val endPeriod = end.replace("교시", "").toIntOrNull() ?: throw InvalidPeriodException | ||
| if (startPeriod > endPeriod || startPeriod < 1 || endPeriod > 10) { | ||
| throw InvalidPeriodException | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun checkEarlyReturnTime(applicationType: ApplicationType, start: String) { | ||
| when (applicationType) { | ||
| ApplicationType.TIME -> { | ||
| val startTime = LocalTime.parse(start) | ||
| if (startTime < LocalTime.of(8, 30)) { | ||
| throw InvalidPeriodException | ||
| } | ||
| } | ||
| ApplicationType.PERIOD -> { | ||
| val startPeriod = start.replace("교시", "").toInt() | ||
| if (startPeriod < 1 || startPeriod > 10) { | ||
| throw InvalidPeriodException | ||
| } | ||
| } | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fun translateEarlyReturn(start: String, applicationType: ApplicationType): String { | ||
| return when (applicationType) { | ||
| ApplicationType.PERIOD -> start | ||
| ApplicationType.TIME -> { | ||
| val startTime = LocalTime.parse(start) | ||
| val startIndex = periods.indexOfFirst { (start, endAt) -> | ||
| startTime >= start && startTime < endAt | ||
| } | ||
| if (startIndex == -1) throw InvalidPeriodException | ||
| periodNames[startIndex] | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+83
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 경계 시간 처리 로직이
예를 들어 9:40 (1교시 종료 시간)의 경우:
두 함수의 경계 처리 로직을 통일하는 것이 좋습니다. 🛠️ 제안 수정 (inclusive로 통일) fun translateEarlyReturn(start: String, applicationType: ApplicationType): String {
return when (applicationType) {
ApplicationType.PERIOD -> start
ApplicationType.TIME -> {
val startTime = LocalTime.parse(start)
val startIndex = periods.indexOfFirst { (start, endAt) ->
- startTime >= start && startTime < endAt
+ startTime in start..endAt
}
if (startIndex == -1) throw InvalidPeriodException
periodNames[startIndex]
}
}
}🤖 Prompt for AI Agents |
||
|
|
||
| // 주어진 교시 혹은 시간에 해당하는 출석 상태를 업데이트하는 함수 | ||
| fun updateAttendanceToApplication( | ||
| start: String, | ||
|
|
@@ -113,27 +167,16 @@ class AttendanceService { | |
| return updateAttendance | ||
| } | ||
|
|
||
| fun translateEarlyReturn(start: String, applicationType: ApplicationType): List<String> { | ||
| return when (applicationType) { | ||
| ApplicationType.PERIOD -> { | ||
| val startIndex = periodNames.indexOf(start).coerceAtLeast(0) | ||
| periodNames.subList(startIndex, periodNames.size) | ||
| } | ||
| ApplicationType.TIME -> { | ||
| val startTime = LocalTime.parse(start) | ||
| getMatchPeriods(startTime, null) | ||
| } | ||
| private fun getMatchPeriods(startTime: LocalTime, endTime: LocalTime): Pair<String, String> { | ||
| val startIndex = periods.indexOfFirst { (start, endAt) -> | ||
| startTime in start..endAt | ||
| } | ||
| val endIndex = periods.indexOfFirst { (start, endAt) -> | ||
| endTime in start..endAt | ||
| } | ||
| } | ||
|
|
||
| private fun getMatchPeriods(startTime: LocalTime, endTime: LocalTime?): List<String> { | ||
| return periods | ||
| .mapIndexed { index, period -> | ||
| if ((startTime < period.second) && (endTime == null || endTime > period.first)) { | ||
| periodNames[index] | ||
| } else { | ||
| null | ||
| } | ||
| }.filterNotNull() | ||
| if (startIndex == -1 || endIndex == -1) throw InvalidPeriodException | ||
|
|
||
| return periodNames[startIndex] to periodNames[endIndex] | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘못된 시간/교시 포맷이 그대로 런타임 예외로 노출될 수 있습니다.
LocalTime.parse(...)와toInt()가 실패하면InvalidPeriodException이 아닌DateTimeParseException/NumberFormatException으로 터져 500이 될 수 있습니다. 입력 검증으로 예외를 통일하는 편이 안전합니다.🛠️ 제안 수정
fun checkApplicationTime(applicationType: ApplicationType, start: String, end: String) { when (applicationType) { ApplicationType.TIME -> { - val startTime = LocalTime.parse(start) - val endTime = LocalTime.parse(end) + val startTime = runCatching { LocalTime.parse(start) } + .getOrElse { throw InvalidPeriodException } + val endTime = runCatching { LocalTime.parse(end) } + .getOrElse { throw InvalidPeriodException } if (startTime > endTime || endTime > LocalTime.of(20, 30) || startTime < LocalTime.of(8, 30) ) { throw InvalidPeriodException } } ApplicationType.PERIOD -> { - val startPeriod = start.replace("교시", "").toInt() - val endPeriod = end.replace("교시", "").toInt() + val startPeriod = start.replace("교시", "").toIntOrNull() + ?: throw InvalidPeriodException + val endPeriod = end.replace("교시", "").toIntOrNull() + ?: throw InvalidPeriodException if (startPeriod > endPeriod || startPeriod < 1 || endPeriod > 10) { throw InvalidPeriodException } } } }📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abf2875
time 변환은 기존에도 저런 형식으로 진행하였기 때문에 괜찮습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ByunDohwi알겠습니다! 기존 코드베이스와의 일관성을 유지하는 것도 중요하니 이해했습니다. 입력 검증은 현재 방식대로 진행하시면 되겠습니다. 👍