Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Alexis Leboeuf
2026-01-07 10:02:45 +01:00
10 changed files with 69 additions and 197 deletions

View File

@@ -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());

View File

@@ -7,12 +7,15 @@ 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.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/coach")
public class CoachResource {
@Autowired
private CoachDAO coachDAO;
@@ -49,7 +52,8 @@ public class CoachResource {
public ResponseEntity<CoachDTO> update(@PathVariable Integer id, @RequestBody CoachDTO dto) {
Coach coach = coachDAO.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
if (dto.getName() != null) coach.setName(dto.getName());
if (dto.getName() != null)
coach.setName(dto.getName());
coachDAO.save(coach);
CoachDTO updatedDto = mapToDTO(coach);
return ResponseEntity.ok(updatedDto);
@@ -78,4 +82,3 @@ public class CoachResource {
return coach;
}
}

View File

@@ -13,13 +13,14 @@ 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.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.ArrayList;
import java.util.List;
@RestController
@Controller
@RequestMapping("/session")
public class SessionResource {
@@ -87,7 +88,7 @@ public class SessionResource {
@PreAuthorize("hasRole('Coach')")
public ResponseEntity<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
HttpStatus.NOT_FOUND, "Session not found with id " + id));
HttpStatus.NOT_FOUND, "Session not found with id " + id));
if (dto.getDuree() != null) {
session.setDuree(dto.getDuree());

View File

@@ -6,4 +6,6 @@ spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
server.port=8081
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8080/realms/Frisbyee_realm
spring.security.oauth2.resourceserver.jwt.jwk-set-uri: http://localhost:8080/realms/Frisbyee_realm/protocol/openid-connect/certs