Still a few errors to correct
This commit is contained in:
@@ -4,6 +4,7 @@ import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -6,8 +6,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.el.stream.Optional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -33,19 +44,19 @@ public class AthleteResource {
|
||||
@PreAuthorize("hasRole('Admin')") // Only admin can create??
|
||||
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||
Athlete ahtlete = new Athlete();
|
||||
athlete.setName(dto.getName())
|
||||
athlete.setCategorie(dto.getCategorie())
|
||||
athlete.setNiveau(dto.getNiveau())
|
||||
ahtlete.setName(dto.getName());
|
||||
ahtlete.setCategorie(dto.getCategorie());
|
||||
ahtlete.setNiveau(dto.getNiveau());
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(athlete));
|
||||
}
|
||||
|
||||
@PostMapping("/all")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')")
|
||||
public ReponseEntity<List<AthleteDTO>> all() {
|
||||
public ResponseEntity<List<AthleteDTO>> all() {
|
||||
List<Athlete> athletes = athleteDAO.findAll();
|
||||
List<AthleteDTO> dtos = new ArrayList<>();
|
||||
for (Athlete athlete : athletes) {
|
||||
dtos.add(maptoDTO(athlete));
|
||||
dtos.add(mapToDTO(athlete));
|
||||
}
|
||||
return ResponseEntity.ok(dtos);
|
||||
}
|
||||
@@ -67,10 +78,6 @@ public class AthleteResource {
|
||||
athlete.setCategorie(dto.getCategorie());
|
||||
athlete.setNiveau(dto.getNiveau());
|
||||
|
||||
// Optional
|
||||
athlete.setDuree(dto.getDuree());
|
||||
athlete.setTheme(dto.getTheme());
|
||||
|
||||
// List
|
||||
if (dto.getDataActivite() != null) {
|
||||
athlete.setDataActivite(dto.getDataActivite());
|
||||
@@ -80,7 +87,7 @@ public class AthleteResource {
|
||||
if (dto.getSessionId() != null) {
|
||||
Session session = sessionDAO.findById(dto.getSessionId())
|
||||
.orElseThrow(() -> new RuntimeException("Session not found"));
|
||||
athlete.setSession(session);
|
||||
athlete.setSessions(new ArrayList<>(List.of(session)));
|
||||
}
|
||||
|
||||
athleteDAO.save(athlete);
|
||||
|
||||
Reference in New Issue
Block a user