PMT-4: Fix Repository

This commit is contained in:
Dominik Säume 2024-10-21 14:25:51 +02:00
parent 1b036ca6f0
commit 9009c7c79e
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
3 changed files with 8 additions and 7 deletions

View file

@ -124,12 +124,12 @@ public class ApiController implements DefaultApi {
long start = project.getStart().toEpochSecond(ZoneOffset.UTC);
long plannedEnd = project.getPlannedEnd().toEpochSecond(ZoneOffset.UTC);
List<Allocation> allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId());
List<Allocation> allocations = allocationRepository.findAllByEmployeeId(body.getEmployeeId());
if (allocations.stream()
.map(Allocation::getProject)
.anyMatch(allocatedProject -> {
long allocatedStart = allocatedProject.getStart().toEpochSecond(null);
long allocatedPlannedEnd = allocatedProject.getPlannedEnd().toEpochSecond(null);
long allocatedStart = allocatedProject.getStart().toEpochSecond(ZoneOffset.UTC);
long allocatedPlannedEnd = allocatedProject.getPlannedEnd().toEpochSecond(ZoneOffset.UTC);
return Math.max(start, allocatedStart) <= Math.min(plannedEnd, allocatedPlannedEnd);
})) {
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);

View file

@ -14,11 +14,12 @@ import lombok.*;
public class Allocation {
@Id
@Column(name = "project_id")
@Setter(AccessLevel.NONE)
private Long projectId;
@ManyToOne
@JoinColumn(name = "allocation_project", referencedColumnName = "id", insertable = false, updatable = false)
@JoinColumn(name = "project_id", referencedColumnName = "id", insertable = false, updatable = false)
private Project project;
@Id

View file

@ -1,10 +1,10 @@
package de.hmmh.pmt.db;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface AllocationRepository extends CrudRepository<Allocation, AllocationId> {
public interface AllocationRepository extends JpaRepository<Allocation, AllocationId> {
List<Allocation> findAllocationsByEmployeeId(Long employeeId);
List<Allocation> findAllByEmployeeId(Long employeeId);
}