From 8128e4c8f8e428188a496d3afbcc08a453f4956d Mon Sep 17 00:00:00 2001 From: Bartha Maxime <231026@umons.ac.be> Date: Sat, 16 Mar 2024 16:28:34 +0100 Subject: [PATCH] changed Course entity --- .../Clyde/EndPoints/MockController.java | 8 +++---- .../ovh/herisson/Clyde/Tables/Course.java | 20 +++++++++++++----- ...herGivenCourse.java => TeacherCourse.java} | 21 +++++-------------- 3 files changed, 24 insertions(+), 25 deletions(-) rename backend/src/main/java/ovh/herisson/Clyde/Tables/{TeacherGivenCourse.java => TeacherCourse.java} (56%) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 8136331..d05a4db 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -68,10 +68,10 @@ public class MockController { curriculumService.save(psychologyBab1); - Course progra1 = new Course(5,"Programmation et algorithimque 1"); - Course chemistry1 = new Course(12, "Thermochimie"); - Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho"); - Course commun = new Course(2, "cours commun"); + Course progra1 = new Course(5,"Programmation et algorithimque 1",joke); + Course chemistry1 = new Course(12, "Thermochimie",joke); + Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho",joke); + Course commun = new Course(2, "cours commun",joke); courseService.save(progra1); courseService.save(chemistry1); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index 16d8a79..e338d7d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,9 +1,6 @@ package ovh.herisson.Clyde.Tables; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; @Entity public class Course { @@ -13,9 +10,14 @@ public class Course { private int credits; private String title; - public Course(int credits, String title){ + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "Users") + private User owner; + + public Course(int credits, String title, User owner){ this.credits = credits; this.title = title; + this.owner = owner; } public Course() {} @@ -39,4 +41,12 @@ public class Course { public void setTitle(String title){ this.title = title; } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java similarity index 56% rename from backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java rename to backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java index a1ee138..3392c72 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherGivenCourse.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/TeacherCourse.java @@ -3,30 +3,26 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; @Entity -public class TeacherGivenCourse { +public class TeacherCourse { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Users") private User user; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "Course") private Course course; - //This flag helps make the difference between an assistant or a Teacher (who owns the course) - private boolean owned; - - public TeacherGivenCourse(User user, Course course, boolean owned){ + public TeacherCourse(User user, Course course){ this.user = user; this.course = course; - this.owned = owned; } - public TeacherGivenCourse() {} + public TeacherCourse() {} public int getId() { return id; @@ -48,11 +44,4 @@ public class TeacherGivenCourse { this.course = course; } - public boolean isOwned() { - return owned; - } - - public void setOwned(boolean owned) { - this.owned = owned; - } }