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);
|
||||
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
||||
Activite activite = mapToEntity(dto);
|
||||
activite.setId(null);
|
||||
activite.setSession(session);
|
||||
activiteDAO.save(activite);
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class AdminResource {
|
||||
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
||||
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
||||
Admin admin = mapToEntity(dto);
|
||||
admin.setId(null);
|
||||
if(adminDAO.findByKeycloakId(admin.getKeycloakId()).isPresent()) {
|
||||
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')")
|
||||
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||
Athlete athlete = mapToEntity(dto);
|
||||
athlete.setId(null);
|
||||
if(athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
||||
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
|
||||
public ResponseEntity<CoachDTO> create(@RequestBody CoachDTO dto) {
|
||||
Coach coach = mapToEntity(dto);
|
||||
coach.setId(null);
|
||||
if(coachDAO.existsByKeycloakId(coach.getKeycloakId())) {
|
||||
return ResponseEntity.status(200).body(mapToDTO(coachDAO.findByKeycloakId(coach.getKeycloakId()).get()));
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ public class SessionResource {
|
||||
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
||||
try {
|
||||
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);
|
||||
session.setCoach(c);
|
||||
sessionDAO.save(session);
|
||||
|
||||
Reference in New Issue
Block a user