From 5693412b5961d1ceddb9281ea14daea2a14f56e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Mon, 21 Oct 2024 14:25:51 +0200 Subject: [PATCH] PMT-4: Fix Repository --- src/main/java/de/hmmh/pmt/ApiController.java | 6 +++--- src/main/java/de/hmmh/pmt/db/Allocation.java | 3 ++- src/main/java/de/hmmh/pmt/db/AllocationRepository.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 36761f9..44205b5 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -124,12 +124,12 @@ public class ApiController implements DefaultApi { long start = project.getStart().toEpochSecond(ZoneOffset.UTC); long plannedEnd = project.getPlannedEnd().toEpochSecond(ZoneOffset.UTC); - List allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId()); + List 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); diff --git a/src/main/java/de/hmmh/pmt/db/Allocation.java b/src/main/java/de/hmmh/pmt/db/Allocation.java index 3f2ae9b..78f41e8 100644 --- a/src/main/java/de/hmmh/pmt/db/Allocation.java +++ b/src/main/java/de/hmmh/pmt/db/Allocation.java @@ -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 diff --git a/src/main/java/de/hmmh/pmt/db/AllocationRepository.java b/src/main/java/de/hmmh/pmt/db/AllocationRepository.java index 5d4bc07..dcbc9d3 100644 --- a/src/main/java/de/hmmh/pmt/db/AllocationRepository.java +++ b/src/main/java/de/hmmh/pmt/db/AllocationRepository.java @@ -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 { +public interface AllocationRepository extends JpaRepository { - List findAllocationsByEmployeeId(Long employeeId); + List findAllByEmployeeId(Long employeeId); }