From 3a4c3fc21c1ffcf6996e7693fc5ae66b4e7677ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Mon, 21 Oct 2024 12:37:25 +0200 Subject: [PATCH] PMT-4: Fix Relation and Functions of Allocations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Säume --- src/main/java/de/hmmh/pmt/ApiController.java | 2 +- src/main/java/de/hmmh/pmt/db/Allocation.java | 23 ++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index e7e702e..26fc2b7 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -137,7 +137,7 @@ public class ApiController implements DefaultApi { Allocation allocation = new Allocation(); allocation.setEmployeeId(employee.getId()); allocation.setRole(body.getQualificationId()); - allocation.setProjectId(project.getId()); + allocation.setProject(project); allocationRepository.save(allocation); return new ResponseEntity<>(HttpStatus.NO_CONTENT); diff --git a/src/main/java/de/hmmh/pmt/db/Allocation.java b/src/main/java/de/hmmh/pmt/db/Allocation.java index 5ed7008..3f2ae9b 100644 --- a/src/main/java/de/hmmh/pmt/db/Allocation.java +++ b/src/main/java/de/hmmh/pmt/db/Allocation.java @@ -2,10 +2,7 @@ package de.hmmh.pmt.db; import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; @NoArgsConstructor @AllArgsConstructor @@ -15,15 +12,23 @@ import lombok.Setter; @IdClass(AllocationId.class) @Table(name = "allocation") public class Allocation { - @Id - private Long projectId; - @ManyToOne - @JoinColumn(name = "projectId", insertable = false, updatable = false) - private Project project; + @Id + @Setter(AccessLevel.NONE) + private Long projectId; + + @ManyToOne + @JoinColumn(name = "allocation_project", referencedColumnName = "id", insertable = false, updatable = false) + private Project project; + @Id private Long employeeId; @NotNull private Long role; // This is a QualificationId + + public void setProject(Project project) { + this.project = project; + this.projectId = project.getId(); + } }