Skip to content
Snippets Groups Projects
Commit 9fbb9d85 authored by Fatima Ezzahra Majidi's avatar Fatima Ezzahra Majidi
Browse files

Modif + Delete candidature

parent 40700f36
No related branches found
No related tags found
1 merge request!3Modif + Delete candidature
...@@ -80,4 +80,37 @@ public class CandidacyController { ...@@ -80,4 +80,37 @@ public class CandidacyController {
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCandidacy(@PathVariable Long id) {
if (!candidacyService.existsById(id)) {
return ResponseEntity.notFound().build();
}
candidacyService.deleteCandidacy(id);
return ResponseEntity.noContent().build();
}
@PutMapping("/{id}")
public ResponseEntity<?> updateCandidacy(@PathVariable Long id, @RequestBody Candidacy updatedCandidacy) {
Optional<Candidacy> existingCandidacy = candidacyService.getCandidacyById(id);
if (existingCandidacy.isEmpty()) {
return ResponseEntity.notFound().build();
}
Candidacy candidacy = existingCandidacy.get();
if (updatedCandidacy.getStudent() != null && updatedCandidacy.getStudent().getId() != null) {
candidacy.setStudent(updatedCandidacy.getStudent());
}
if (updatedCandidacy.getStage() != null && updatedCandidacy.getStage().getId() != null) {
candidacy.setStage(updatedCandidacy.getStage());
}
if (updatedCandidacy.getUnivSupervisor() != null) {
candidacy.setUnivSupervisor(updatedCandidacy.getUnivSupervisor());
}
Candidacy savedCandidacy = candidacyService.saveCandidacy(candidacy);
return ResponseEntity.ok(savedCandidacy);
}
} }
...@@ -35,4 +35,8 @@ public class CandidacyService { ...@@ -35,4 +35,8 @@ public class CandidacyService {
public List<Candidacy> getCandidaciesByStudentId(Long studentId) { public List<Candidacy> getCandidaciesByStudentId(Long studentId) {
return candidacyRepository.findByStudentId(studentId); return candidacyRepository.findByStudentId(studentId);
} }
public boolean existsById(Long id) {
return candidacyRepository.existsById(id);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment