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