Delete multiple schedules
All checks were successful
Java CI with Maven / build (push) Successful in 46s

This commit is contained in:
Sebastian Böckelmann 2023-11-11 18:53:31 +01:00
parent 311edbb6fc
commit c5311fbe58

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"));
}
} }