Skip to content

Commit 7a5a11e

Browse files
authored
Refactor vacation scheduling logic in WorkdayService to streamline input validation and improve time resolution (#46)
1 parent c91118a commit 7a5a11e

1 file changed

Lines changed: 8 additions & 19 deletions

File tree

src/main/kotlin/com/moa/service/WorkdayService.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class WorkdayService(
166166
DailyWorkScheduleType.VACATION -> {
167167
val policy = resolveMonthlyRepresentativePolicyOrNull(memberId, date.year, date.monthValue)
168168
?: throw NotFoundException()
169-
validateVacationInput(date, existingSchedule, policy)
170-
resolveVacationTimes(req, policy)
169+
resolveVacationTimes(date, req, existingSchedule, policy)
171170
}
172171

173172
DailyWorkScheduleType.NONE -> null to null
@@ -313,25 +312,10 @@ class WorkdayService(
313312
}
314313
}
315314

316-
private fun validateVacationInput(
317-
date: LocalDate,
318-
savedSchedule: DailyWorkSchedule?,
319-
policy: WorkPolicyVersion,
320-
) {
321-
if (savedSchedule?.type == DailyWorkScheduleType.VACATION) return
322-
323-
val schedule = resolveSchedule(savedSchedule, policy, date)
324-
val isDefaultWorkSchedule = schedule.type == DailyWorkScheduleType.WORK &&
325-
schedule.clockIn == policy.clockInTime &&
326-
schedule.clockOut == policy.clockOutTime
327-
328-
if (!isDefaultWorkSchedule) {
329-
throw BadRequestException(ErrorCode.INVALID_WORKDAY_INPUT)
330-
}
331-
}
332-
333315
private fun resolveVacationTimes(
316+
date: LocalDate,
334317
req: WorkdayUpsertRequest,
318+
savedSchedule: DailyWorkSchedule?,
335319
policy: WorkPolicyVersion,
336320
): Pair<LocalTime, LocalTime> {
337321
if (req.clockInTime != null && req.clockOutTime != null) {
@@ -340,6 +324,11 @@ class WorkdayService(
340324
return clockIn to clockOut
341325
}
342326

327+
val schedule = resolveSchedule(savedSchedule, policy, date)
328+
if (schedule.clockIn != null && schedule.clockOut != null) {
329+
return schedule.clockIn to schedule.clockOut
330+
}
331+
343332
return policy.clockInTime to policy.clockOutTime
344333
}
345334

0 commit comments

Comments
 (0)