Resolved errors in AthleteResource

This commit is contained in:
Alexis Leboeuf
2026-01-06 11:02:24 +01:00
parent 8b240b8b60
commit 0afb619d40

View File

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -43,10 +44,10 @@ public class AthleteResource {
@PostMapping("/create")
@PreAuthorize("hasRole('Admin')") // Only admin can create??
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
Athlete ahtlete = new Athlete();
ahtlete.setName(dto.getName());
ahtlete.setCategorie(dto.getCategorie());
ahtlete.setNiveau(dto.getNiveau());
Athlete athlete = new Athlete();
athlete.setName(dto.getName());
athlete.setCategorie(dto.getCategorie());
athlete.setNiveau(dto.getNiveau());
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(athlete));
}
@@ -78,16 +79,15 @@ public class AthleteResource {
athlete.setCategorie(dto.getCategorie());
athlete.setNiveau(dto.getNiveau());
// List
if (dto.getDataActivite() != null) {
athlete.setDataActivite(dto.getDataActivite());
}
// Relationship: sessionId → session
if (dto.getSessionId() != null) {
Session session = sessionDAO.findById(dto.getSessionId())
.orElseThrow(() -> new RuntimeException("Session not found"));
athlete.setSessions(new ArrayList<>(List.of(session)));
if (dto.getSessionIds() != null) {
List<Session> sessions = new ArrayList<>();
for (Integer sessionId : dto.getSessionIds()) {
Session session = sessionDAO.findById(sessionId)
.orElseThrow(() -> new RuntimeException("Session not found"));
sessions.add(session);
}
athlete.setSessions(sessions);
}
athleteDAO.save(athlete);