|
|
|
|
@@ -9,13 +9,13 @@ 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.stereotype.Controller;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import hackathon.FrisbYEE.jpa.dto.ActiviteDTO;
|
|
|
|
|
@@ -32,19 +32,16 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/athletes")
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping("/athlete")
|
|
|
|
|
public class AthleteResource {
|
|
|
|
|
@Autowired
|
|
|
|
|
private AthleteDAO athleteDAO;
|
|
|
|
|
private SessionDAO sessionDAO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Crée un Athlète avec les informations fournies")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@PostMapping("/create")
|
|
|
|
|
@PreAuthorize("hasRole('Admin')") // Only admin can create??
|
|
|
|
|
@@ -56,9 +53,7 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère tous les athlètes")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupère tous les athlètes",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = List.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupère tous les athlètes", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/all")
|
|
|
|
|
@PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')")
|
|
|
|
|
@@ -73,9 +68,7 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère l'athlète ayant l'identifiant correspondant")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
|
@PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')")
|
|
|
|
|
@@ -87,13 +80,11 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@PutMapping("/{id}")
|
|
|
|
|
@PreAuthorize("hasRole('ADMIN') or #id == principal.id")
|
|
|
|
|
public ResponseEntity<AthleteDTO> update(@PathVariable Integer id,@RequestBody AthleteDTO dto) {
|
|
|
|
|
public ResponseEntity<AthleteDTO> update(@PathVariable Integer id, @RequestBody AthleteDTO dto) {
|
|
|
|
|
try {
|
|
|
|
|
Athlete athlete = athleteDAO.findById(id).get();
|
|
|
|
|
athlete.setName(dto.getName());
|
|
|
|
|
@@ -113,16 +104,14 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
athleteDAO.save(athlete);
|
|
|
|
|
return ResponseEntity.ok(mapToDTO(athlete));
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
return ResponseEntity.noContent().build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Supprime l'athlète ayant l'identifiant correspondant")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Suppression effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Suppression effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
@PreAuthorize("hasRole('Admin')")
|
|
|
|
|
@@ -154,19 +143,17 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère les sessions correspondant à l'athlète donné")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/athlete/{id}/session")
|
|
|
|
|
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
|
|
|
|
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
|
|
|
|
// return pet
|
|
|
|
|
System.out.println("ID A CHERCHER" + athleteId);
|
|
|
|
|
java.util.Optional<Athlete> j = athleteDAO.findById(athleteId);
|
|
|
|
|
List<Session> sessions = sessionDAO.findAll();
|
|
|
|
|
List<SessionDTO> athleteSessions = new ArrayList<>();
|
|
|
|
|
for(Session s : sessions){
|
|
|
|
|
if(s.getAthletes().contains(j.get())){
|
|
|
|
|
for (Session s : sessions) {
|
|
|
|
|
if (s.getAthletes().contains(j.get())) {
|
|
|
|
|
SessionDTO dto = new SessionDTO();
|
|
|
|
|
dto.setId(s.getId());
|
|
|
|
|
dto.setName(s.getName());
|
|
|
|
|
@@ -177,15 +164,13 @@ public class AthleteResource {
|
|
|
|
|
System.out.println(j);
|
|
|
|
|
return athleteSessions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère toutes les sessions")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/athletes/session")
|
|
|
|
|
public List<SessionDTO> getAllSessions() {
|
|
|
|
|
public List<SessionDTO> getAllSessions() {
|
|
|
|
|
List<Session> sessions = sessionDAO.findAll();
|
|
|
|
|
System.out.println(sessions);
|
|
|
|
|
List<SessionDTO> sessionDTOs = new ArrayList<>();
|
|
|
|
|
@@ -201,9 +186,7 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère les activités correspondant à la session donnée")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = ActiviteDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ActiviteDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/athletes/session/{id}/activities")
|
|
|
|
|
public List<ActiviteDTO> getActivitiesForSession(@PathVariable Integer id) {
|
|
|
|
|
@@ -227,9 +210,7 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère toutes les sessions après une date donnée")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/athletes/{id}/session/after/{date}")
|
|
|
|
|
public List<SessionDTO> getSessionsAfterDate(@PathVariable Integer id, @PathVariable String date) {
|
|
|
|
|
@@ -241,7 +222,11 @@ public class AthleteResource {
|
|
|
|
|
List<Session> sessions = sessionDAO.findAll();
|
|
|
|
|
List<SessionDTO> filteredSessions = new ArrayList<>();
|
|
|
|
|
for (Session session : sessions) {
|
|
|
|
|
if (session.getAthletes().contains(athlete) && session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(date)))) { //WTF toujours sympa les dates
|
|
|
|
|
if (session.getAthletes().contains(athlete)
|
|
|
|
|
&& session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(date)))) { // WTF
|
|
|
|
|
// toujours
|
|
|
|
|
// sympa les
|
|
|
|
|
// dates
|
|
|
|
|
SessionDTO dto = new SessionDTO();
|
|
|
|
|
dto.setId(session.getId());
|
|
|
|
|
dto.setName(session.getName());
|
|
|
|
|
@@ -256,12 +241,11 @@ public class AthleteResource {
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "Récupère les sessions entre deux dates")
|
|
|
|
|
@ApiResponses(value = {
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée",
|
|
|
|
|
content = @Content(mediaType = "application/json",
|
|
|
|
|
schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
|
|
|
|
})
|
|
|
|
|
@GetMapping("/athletes/{id}/session/between/{startDate}/{endDate}")
|
|
|
|
|
public List<SessionDTO> getSessionsBetweenDates(@PathVariable Integer id, @PathVariable String startDate, @PathVariable String endDate) {
|
|
|
|
|
public List<SessionDTO> getSessionsBetweenDates(@PathVariable Integer id, @PathVariable String startDate,
|
|
|
|
|
@PathVariable String endDate) {
|
|
|
|
|
// Récupérer l'athlète par ID
|
|
|
|
|
java.util.Optional<Athlete> athleteOpt = athleteDAO.findById(id);
|
|
|
|
|
if (athleteOpt.isPresent()) {
|
|
|
|
|
@@ -270,7 +254,9 @@ public class AthleteResource {
|
|
|
|
|
List<Session> sessions = sessionDAO.findAll();
|
|
|
|
|
List<SessionDTO> filteredSessions = new ArrayList<>();
|
|
|
|
|
for (Session session : sessions) {
|
|
|
|
|
if (session.getAthletes().contains(athlete) && session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(startDate))) && session.getCreneau().isBefore(ChronoLocalDateTime.from(LocalDate.parse(endDate)))) {
|
|
|
|
|
if (session.getAthletes().contains(athlete)
|
|
|
|
|
&& session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(startDate)))
|
|
|
|
|
&& session.getCreneau().isBefore(ChronoLocalDateTime.from(LocalDate.parse(endDate)))) {
|
|
|
|
|
SessionDTO dto = new SessionDTO();
|
|
|
|
|
dto.setId(session.getId());
|
|
|
|
|
dto.setName(session.getName());
|
|
|
|
|
|