|
|
@@ -43,6 +43,35 @@ class TimesheetsController(private val timesheetsService: TimesheetsService, pri |
|
|
|
return leaveService.saveLeave(parsedEntries) |
|
|
|
} |
|
|
|
|
|
|
|
@PostMapping("saveTimeLeave") |
|
|
|
fun newTimeLeave(@Valid @RequestBody recordTimeLeave: Map<String, List<TimeLeaveEntry>>): Map<String, List<TimeLeaveEntry>> { |
|
|
|
val parsedEntries = kotlin.runCatching { |
|
|
|
recordTimeLeave.mapKeys { (dateString) -> LocalDate.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE) } |
|
|
|
}.getOrElse { throw BadRequestException() } |
|
|
|
|
|
|
|
val timesheets = parsedEntries.mapValues { (_, entries) -> entries.mapNotNull { timeLeaveEntry -> timeLeaveEntry.toTimeEntry() } } |
|
|
|
val leaves = parsedEntries.mapValues { (_, entries) -> entries.mapNotNull { timeLeaveEntry -> timeLeaveEntry.toLeaveEntry() } } |
|
|
|
|
|
|
|
val savedTimesheets = timesheetsService.saveTimesheet(timesheets) |
|
|
|
val savedLeaves = leaveService.saveLeave(leaves) |
|
|
|
|
|
|
|
val newMap = mutableMapOf<String, MutableList<TimeLeaveEntry>>() |
|
|
|
savedTimesheets.forEach { (date, entries) -> |
|
|
|
if (!newMap.containsKey(date)) { |
|
|
|
newMap[date] = mutableListOf() |
|
|
|
} |
|
|
|
newMap[date]!!.addAll(entries.map { e -> e.toTimeLeaveEntry() }) |
|
|
|
} |
|
|
|
savedLeaves.forEach { (date, entries) -> |
|
|
|
if (!newMap.containsKey(date)) { |
|
|
|
newMap[date] = mutableListOf() |
|
|
|
} |
|
|
|
newMap[date]!!.addAll(entries.map { e -> e.toTimeLeaveEntry() }) |
|
|
|
} |
|
|
|
|
|
|
|
return newMap |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping |
|
|
|
fun getTimesheetEntry(): Map<String, List<TimeEntry>> { |
|
|
|
return timesheetsService.getTimesheet() |
|
|
|