Insert
Service
public DepartmentDTO insert(DepartmentDTO dto) {
Department department = new Department();
department.setId(UUID.randomUUID());
department.setName(dto.getName());
departmentRepository.save(department);
return new DepartmentDTO(department);
}
Controller
@PostMapping
public ResponseEntity<DepartmentDTO> insert(@RequestBody DepartmentDTO dto) {
dto = departmentService.insert(dto);
URI uri = URI.create("/departments/" + dto.getId());
return ResponseEntity.created(uri).body(dto);
}
Atualizado