Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,25 @@ public ResponseEntity<?> addStudentToCohort(@PathVariable int id, @RequestBody P

return new ResponseEntity<>(profileRepository.save(profile), HttpStatus.OK);
}

@DeleteMapping("{id}")
public ResponseEntity<?> deleteCohort(@PathVariable int id) {
Cohort cohort = cohortRepository.findById(id).orElse(null);
if (cohort == null) return new ResponseEntity<>("Cohort for id " + Integer.valueOf(id) + " not found.", HttpStatus.NOT_FOUND);
CohortResponse cohortResponse = new CohortResponse();
cohortResponse.set(cohort);

for (Profile profile : cohort.getProfiles()){
profile.setCohort(null);
}
cohort.getProfiles().clear();
cohort.getCourse().getCohorts().remove(cohort);
try {
cohortRepository.delete(cohort);
return ResponseEntity.ok(cohortResponse);
} catch (Exception e) {
return new ResponseEntity<>("Could not delete Cohort", HttpStatus.BAD_REQUEST);
}
}
}

Loading