PMT-43: Implement Endpoint
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m34s
Quality Check / Validate OAS (pull_request) Successful in 59s
Quality Check / Testing (push) Successful in 1m56s
Quality Check / Static Analysis (push) Successful in 2m6s
Quality Check / Linting (pull_request) Successful in 1m46s
Quality Check / Testing (pull_request) Successful in 1m46s
Quality Check / Static Analysis (pull_request) Successful in 1m50s
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m34s
Quality Check / Validate OAS (pull_request) Successful in 59s
Quality Check / Testing (push) Successful in 1m56s
Quality Check / Static Analysis (push) Successful in 2m6s
Quality Check / Linting (pull_request) Successful in 1m46s
Quality Check / Testing (pull_request) Successful in 1m46s
Quality Check / Static Analysis (pull_request) Successful in 1m50s
This commit is contained in:
parent
95ff26473a
commit
c2a93e5a75
3 changed files with 55 additions and 0 deletions
|
@ -71,6 +71,48 @@ public class ApiController implements DefaultApi {
|
||||||
return ResponseEntity.ok(response);
|
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
|
@Override
|
||||||
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
public ResponseEntity<CreatedProjectDTO> createProject(CreateProjectDTO body) {
|
||||||
if (projectRepository.existsByName(body.getName())) {
|
if (projectRepository.existsByName(body.getName())) {
|
||||||
|
|
|
@ -7,4 +7,5 @@ import java.util.List;
|
||||||
public interface AllocationRepository extends JpaRepository<Allocation, AllocationId> {
|
public interface AllocationRepository extends JpaRepository<Allocation, AllocationId> {
|
||||||
|
|
||||||
List<Allocation> findAllByEmployeeId(Long employeeId);
|
List<Allocation> findAllByEmployeeId(Long employeeId);
|
||||||
|
List<Allocation> findAllByProjectId(Long projectId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.hmmh.pmt.util;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
||||||
|
import de.hmmh.pmt.dtos.UpdateProjectDTO;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -29,4 +30,15 @@ public class Mapper {
|
||||||
dto.setPlannedEnd(project.getPlannedEnd());
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
return dto;
|
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