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