correction id coach bug
This commit is contained in:
@@ -43,11 +43,8 @@ public class SessionResource {
|
||||
@PreAuthorize("hasRole('coach')")
|
||||
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
||||
try {
|
||||
System.out.println("ALLEZ ZYWOO TOP 1");
|
||||
Session session = maptoEntity(dto);
|
||||
System.out.println("ID COACH: " + dto.getCoachId());
|
||||
Coach c = coachDAO.findById(dto.getCoachId()).orElse(null);
|
||||
System.out.println("IS COACH FOUND ? " + (c != null));
|
||||
session.setCoach(c);
|
||||
sessionDAO.save(session);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(maptoDTO(session));
|
||||
@@ -149,22 +146,7 @@ public class SessionResource {
|
||||
session.setCreneau(dto.getCreneau());
|
||||
session.setDuree(dto.getDuree());
|
||||
session.setGroupe(dto.getGroupe());
|
||||
// Coach
|
||||
if (dto.getCoachId() != null) {
|
||||
Coach coach = new Coach();
|
||||
coach.setId(dto.getCoachId());
|
||||
session.setCoach(coach);
|
||||
}
|
||||
// Athletes
|
||||
if (dto.getAthleteIds() != null) {
|
||||
List<Athlete> athletes = athleteDAO.findAllById(dto.getAthleteIds());
|
||||
session.setAthletes(athletes);
|
||||
}
|
||||
// Activites
|
||||
if (dto.getActiviteIds() != null) {
|
||||
List<Activite> activites = activiteDAO.findAllById(dto.getActiviteIds());
|
||||
session.setActivites(activites);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ export const CreateSession = () => {
|
||||
|
||||
async function handleCreateSession() {
|
||||
if(user instanceof Coach){
|
||||
session.name = name;
|
||||
session.groupe = groupe;
|
||||
session.creneau = creneau;
|
||||
session.duree = duree;
|
||||
|
||||
@@ -22,12 +22,14 @@ export async function loginOrRegister(keycloak:Keycloak): Promise<User|null>{
|
||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||
if(roles!=null){
|
||||
if(roles.includes("admin")){
|
||||
const id = keycloak.tokenParsed?.sub;
|
||||
if(id!=null){
|
||||
const response = await athleteService.create(id);
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
const newAdmin: Admin = new Admin();
|
||||
newAdmin.keycloakId = keycloak.tokenParsed.sub || "";
|
||||
newAdmin.email = keycloak.tokenParsed.email || "";
|
||||
newAdmin.nom = keycloak.tokenParsed.family_name || "";
|
||||
newAdmin.prenom = keycloak.tokenParsed.given_name || "";
|
||||
const response = await athleteService.create(newAdmin.toDTO());
|
||||
const admin = new Admin(response.data);
|
||||
return admin;
|
||||
}
|
||||
else if(roles.includes("coach")){
|
||||
const newCoach: Coach = new Coach();
|
||||
|
||||
Reference in New Issue
Block a user