PMT-43: die Projekt Daten aktualisieren #16
2 changed files with 54 additions and 0 deletions
|
@ -74,6 +74,48 @@ public class ApiController implements DefaultApi {
|
|||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> updateProject(Long id, UpdateProjectDTO body) {
|
||||
Optional<Project> optionalProject = projectRepository.findById(id);
|
||||
if (optionalProject.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
Project project = optionalProject.get();
|
||||
|
||||
if (project.getName().equals(body.getName()) && projectRepository.existsByName(body.getName())) {
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
if (project.getAdministratorId().equals(body.getAdministratorId())) {
|
||||
HttpStatus status = apiTools.checkEmployeeExists(body.getAdministratorId()).status();
|
||||
if (status != HttpStatus.OK) {
|
||||
return new ResponseEntity<>(status);
|
||||
}
|
||||
}
|
||||
|
||||
Project finalProject = mapper.map(project, body);
|
||||
if (!validator.isValidProject(project)) {
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
if (validator.areAllocationTimeRangesOverlapping(
|
||||
project.getStart(),
|
||||
project.getPlannedEnd(),
|
||||
allocationRepository
|
||||
.findAllByProjectId(finalProject.getId())
|
||||
.stream()
|
||||
.map(Allocation::getEmployeeId)
|
||||
.flatMap(employeeId -> allocationRepository.findAllByEmployeeId(employeeId).stream())
|
||||
.filter(employeeAllocation -> employeeAllocation.getProjectId().equals(finalProject.getId()))
|
||||
.toList()
|
||||
)){
|
||||
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
projectRepository.save(project);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
||||
if (projectRepository.existsByName(body.getName())) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import de.hmmh.pmt.dtos.Employee;
|
|||
import de.hmmh.pmt.dtos.Qualification ;
|
||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
|
||||
import de.hmmh.pmt.dtos.UpdateProjectDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -61,4 +62,15 @@ public class Mapper {
|
|||
return dto;
|
||||
}
|
||||
|
||||
|
||||
public Project map(Project project, UpdateProjectDTO dto) {
|
||||
project.setName(dto.getName());
|
||||
project.setGoal(dto.getGoal());
|
||||
project.setCustomerId(dto.getCustomerId());
|
||||
project.setAdministratorId(dto.getAdministratorId());
|
||||
project.setStart(dto.getStart());
|
||||
project.setPlannedEnd(dto.getPlannedEnd());
|
||||
project.setRealEnd(dto.getEnd());
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue