schedule-refactor #45
@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -195,4 +196,25 @@ public class ScheduleController {
|
||||
List<AbstractSchedule> missedSchedules = taskScheduleService.getAllMissedSchedulesOfUser(SecurityContextHolder.getContext().getAuthentication().getName());
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user