session/id/activites

This commit is contained in:
tuanvu
2026-01-09 18:46:39 +01:00
parent f477d94e55
commit aa877339fa
2 changed files with 35 additions and 18 deletions

View File

@@ -44,7 +44,7 @@ public class SessionResource {
@PreAuthorize("hasRole('coach')")
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
try {
if(sessionDAO.findById(dto.getId()).isPresent()) {
if (sessionDAO.findById(dto.getId()).isPresent()) {
return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + dto.getId() + " already exists.");
}
@@ -114,19 +114,41 @@ public class SessionResource {
return ResponseEntity.noContent().build();
}
//Commented because not finished
/*@GetMapping("/activities/add")
@PreAuthorize("hasRole('coach') or hasRole('admin')")
public ResponseEntity<?> addActivity(@RequestBody ActiviteDTO dto) {
@GetMapping("/{id}/activities")
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
public ResponseEntity<?> getActivitiesBySessionId(@PathVariable Integer id) {
try {
Activite activite = maptoEntity(dto);
activiteDAO.save(activite);
return ResponseEntity.status(HttpStatus.CREATED).body(maptoDTO(activite));
Session session = sessionDAO.findById(id).orElseThrow();
List<Activite> activites = session.getActivites();
List<ActiviteDTO> activiteDTOs = new ArrayList<>();
for (Activite activite : activites) {
ActiviteDTO dto = new ActiviteDTO();
dto.setId(activite.getId());
dto.setName(activite.getName());
activiteDTOs.add(dto);
}
return ResponseEntity.ok(activiteDTOs);
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage());
}
}*/
}
// Commented because not finished
/*
* @GetMapping("/activities/add")
*
* @PreAuthorize("hasRole('coach') or hasRole('admin')")
* public ResponseEntity<?> addActivity(@RequestBody ActiviteDTO dto) {
* try {
* Activite activite = maptoEntity(dto);
* activiteDAO.save(activite);
* return ResponseEntity.status(HttpStatus.CREATED).body(maptoDTO(activite));
* } catch (Exception ex) {
* return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage());
* }
* }
*/
private SessionDTO maptoDTO(Session s) {
SessionDTO dto = new SessionDTO();
@@ -161,13 +183,13 @@ public class SessionResource {
private Session maptoEntity(SessionDTO dto) {
Session session = new Session();
System.out.println("ID "+ session.getId());
System.out.println("ID " + session.getId());
session.setName(dto.getName());
session.setIsRecurrent(dto.getIsRecurrent());
session.setCreneau(dto.getCreneau());
session.setDuree(dto.getDuree());
session.setGroupe(dto.getGroupe());
return session;
}
}

View File

@@ -4,17 +4,12 @@ import ObjectSession from "./object/session";
import {calculStatsAthlete, niveauAlerte} from "../utils/athleteUtils";
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
import ObjectActivite from "./object/activite";
type AthleteListProps = { athletes: Athlete[], sessions: Session[]};
type ActiviteListProps = { activites: Activite[] };
type CoachListProps = { coachs: Coach[] };
type SessionListProps = { sessions: Session[]};
type LigneListProps = { lignes: Ligne[], tempsDeJeuParLigne: Map<number, number> };
function AthleteList({ athletes, sessions }: AthleteListProps) {
const [dateDebut, setDateDebut] = React.useState(new Date());
const [dateFin, setDateFin] = React.useState(new Date());