schedule-refactor #45

Merged
sebastian merged 18 commits from schedule-refactor into master 2023-11-11 18:56:16 +01:00
Showing only changes of commit c5311fbe58 - Show all commits

View File

@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -195,4 +196,25 @@ public class ScheduleController {
List<AbstractSchedule> missedSchedules = taskScheduleService.getAllMissedSchedulesOfUser(SecurityContextHolder.getContext().getAuthentication().getName()); List<AbstractSchedule> missedSchedules = taskScheduleService.getAllMissedSchedulesOfUser(SecurityContextHolder.getContext().getAuthentication().getName());
return ResponseEntity.ok(missedSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList()); return ResponseEntity.ok(missedSchedules.stream().map(AbstractSchedule::toScheduleInfo).toList());
} }
@DeleteMapping("/schedules/{scheduleIDs}/all")
public ResponseEntity<?> deleteSchedules(@PathVariable long[] scheduleIDs) {
List<PermissionResult<AbstractSchedule>> permissionResults = new ArrayList<>();
for(long scheduleID: scheduleIDs) {
PermissionResult<AbstractSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
if(permissionResult.isHasPermissions()) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
}
if(permissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
}
permissionResults.add(permissionResult);
}
for(PermissionResult<AbstractSchedule> permissionResult : permissionResults) {
taskScheduleService.deleteSchedule(permissionResult.getResult());
}
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
} }