Setting null to ids before creation to avoir problems
Postgre was using the given id instead of generating one
This commit is contained in:
@@ -53,6 +53,7 @@ public class ActiviteResource {
|
|||||||
System.out.println("ROLE TEST " + hackathon.FrisbYEE.jpa.metier.Role.coach);
|
System.out.println("ROLE TEST " + hackathon.FrisbYEE.jpa.metier.Role.coach);
|
||||||
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
||||||
Activite activite = mapToEntity(dto);
|
Activite activite = mapToEntity(dto);
|
||||||
|
activite.setId(null);
|
||||||
activite.setSession(session);
|
activite.setSession(session);
|
||||||
activiteDAO.save(activite);
|
activiteDAO.save(activite);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class AdminResource {
|
|||||||
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
||||||
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
||||||
Admin admin = mapToEntity(dto);
|
Admin admin = mapToEntity(dto);
|
||||||
|
admin.setId(null);
|
||||||
if(adminDAO.findByKeycloakId(admin.getKeycloakId()).isPresent()) {
|
if(adminDAO.findByKeycloakId(admin.getKeycloakId()).isPresent()) {
|
||||||
return ResponseEntity.status(200).body(mapToDTO(adminDAO.findByKeycloakId(admin.getKeycloakId()).get()));
|
return ResponseEntity.status(200).body(mapToDTO(adminDAO.findByKeycloakId(admin.getKeycloakId()).get()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class AthleteResource {
|
|||||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||||
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||||
Athlete athlete = mapToEntity(dto);
|
Athlete athlete = mapToEntity(dto);
|
||||||
|
athlete.setId(null);
|
||||||
if(athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
if(athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
||||||
return ResponseEntity.status(200).body(mapToDTO(athleteDAO.findByKeycloakId(athlete.getKeycloakId()).get()));
|
return ResponseEntity.status(200).body(mapToDTO(athleteDAO.findByKeycloakId(athlete.getKeycloakId()).get()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class CoachResource {
|
|||||||
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
||||||
public ResponseEntity<CoachDTO> create(@RequestBody CoachDTO dto) {
|
public ResponseEntity<CoachDTO> create(@RequestBody CoachDTO dto) {
|
||||||
Coach coach = mapToEntity(dto);
|
Coach coach = mapToEntity(dto);
|
||||||
|
coach.setId(null);
|
||||||
if(coachDAO.existsByKeycloakId(coach.getKeycloakId())) {
|
if(coachDAO.existsByKeycloakId(coach.getKeycloakId())) {
|
||||||
return ResponseEntity.status(200).body(mapToDTO(coachDAO.findByKeycloakId(coach.getKeycloakId()).get()));
|
return ResponseEntity.status(200).body(mapToDTO(coachDAO.findByKeycloakId(coach.getKeycloakId()).get()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ public class SessionResource {
|
|||||||
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
||||||
try {
|
try {
|
||||||
Session session = maptoEntity(dto);
|
Session session = maptoEntity(dto);
|
||||||
|
session.setId(null);
|
||||||
|
if(sessionDAO.findById(session.getId()).isPresent()) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + session.getId() + " already exists.");
|
||||||
|
|
||||||
|
}
|
||||||
Coach c = coachDAO.findById(dto.getCoachId()).orElse(null);
|
Coach c = coachDAO.findById(dto.getCoachId()).orElse(null);
|
||||||
session.setCoach(c);
|
session.setCoach(c);
|
||||||
sessionDAO.save(session);
|
sessionDAO.save(session);
|
||||||
|
|||||||
Reference in New Issue
Block a user