diff --git a/back_end/src/main/java/hackathon/FrisbYEE/jpa/metier/Athlete.java b/back_end/src/main/java/hackathon/FrisbYEE/jpa/metier/Athlete.java index bec731d..c424329 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/jpa/metier/Athlete.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/jpa/metier/Athlete.java @@ -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; diff --git a/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java index d56c2ff..a2c9073 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java @@ -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 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> all() { + public ResponseEntity> all() { List athletes = athleteDAO.findAll(); List 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);