Ajout prénom (et allez zywoo)
This commit is contained in:
@@ -6,12 +6,16 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.dto.AdminDTO;
|
||||
import hackathon.FrisbYEE.jpa.dto.CoachDTO;
|
||||
import hackathon.FrisbYEE.jpa.metier.Admin;
|
||||
import hackathon.FrisbYEE.jpa.metier.Coach;
|
||||
import hackathon.FrisbYEE.jpa.service.AdminDAO;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin")
|
||||
@@ -21,6 +25,18 @@ public class AdminResource {
|
||||
@Autowired
|
||||
private AdminDAO adminDAO;
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
||||
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
||||
Admin admin = mapToEntity(dto);
|
||||
if(adminDAO.findByKeycloakId(admin.getKeycloakId()).isPresent()) {
|
||||
return ResponseEntity.status(200).body(mapToDTO(adminDAO.findByKeycloakId(admin.getKeycloakId()).get()));
|
||||
}
|
||||
adminDAO.save(admin);
|
||||
return ResponseEntity.status(201).body(mapToDTO(admin));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('admin')")
|
||||
public ResponseEntity<AdminDTO> getAdmin(@PathVariable Integer id) {
|
||||
@@ -45,4 +61,15 @@ public class AdminResource {
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Admin mapToEntity(AdminDTO dto) {
|
||||
Admin admin = new Admin();
|
||||
admin.setId(dto.getId());
|
||||
admin.setKeycloakId(dto.getId_keycloak());
|
||||
admin.setName(dto.getName());
|
||||
admin.setPrenom(dto.getPrenom());
|
||||
admin.setRole(dto.getRole());
|
||||
|
||||
return admin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,14 +93,15 @@ public class CoachResource {
|
||||
dto.setId(coach.getId());
|
||||
dto.setId_keycloak(coach.getKeycloakId());
|
||||
dto.setName(coach.getName());
|
||||
dto.setPrenom(coach.getPrenom());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Coach mapToEntity(CoachDTO dto) {
|
||||
Coach coach = new Coach();
|
||||
//coach.setId(dto.getId());
|
||||
coach.setKeycloakId(dto.getId_keycloak());
|
||||
coach.setName(dto.getName());
|
||||
coach.setPrenom(dto.getPrenom());
|
||||
return coach;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user