From 0621c6fe68de47d83edbc9861a0fccf952e9287e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 21 Apr 2024 09:46:46 +0200 Subject: [PATCH] finish --- .../Clyde/EndPoints/CourseController.java | 11 ++-- .../Clyde/EndPoints/Msg/ForumController.java | 3 - .../Clyde/Services/ProtectionService.java | 2 +- .../ovh/herisson/Clyde/Tables/Course.java | 34 ++--------- .../herisson/Clyde/Tables/UserCurriculum.java | 57 +++++-------------- frontend/src/Apps/Forums.vue | 8 +-- frontend/src/rest/courses.js | 6 +- 7 files changed, 31 insertions(+), 90 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java index 3dd81fd..c021e0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/CourseController.java @@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.UserCurriculum; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; @RestController @@ -149,13 +150,13 @@ public class CourseController { //Get all the courses followed by an user - @GetMapping("/usercourses/{userId}") - public ResponseEntity> getAllUserCourses(@PathVariable long userId){ - User u = userService.getUserById(userId); + @GetMapping("/usercourses") + public ResponseEntity> getAllUserCourses(@RequestHeader("Authorization") String token){ + User u = authServ.getUserFromToken(token); //We get all the actual curriculums of the user - ArrayList userCurricula = userCurriculumService.findByStudentAndActual(u, true); - ArrayList toReturn = new ArrayList<>(); + List userCurricula = userCurriculumService.findByStudentAndActual(u, true); + List toReturn = new ArrayList<>(); //We iterate through all the curriculums and we extract the courses for (int i = 0; i < userCurricula.size(); i++){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java index 2186129..a0c74f5 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java @@ -110,7 +110,4 @@ public class ForumController { forumServ.answerTopic(t, data, u); return new ResponseEntity<>(HttpStatus.ACCEPTED); } - - - // TODO: Check if authorization to view a post/forum/... } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java index 1c9b944..8c3d847 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/ProtectionService.java @@ -51,7 +51,7 @@ public class ProtectionService { HashMap toReturn = new HashMap<>(); - toReturn.put("courseId",course.getCourseID()); + toReturn.put("courseID",course.getCourseID()); toReturn.put("credits",course.getCredits()); toReturn.put("title", course.getTitle()); toReturn.put("owner", userWithoutPassword(course.getOwner())); 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 0534b0e..369a8bc 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,7 +1,9 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import ovh.herisson.Clyde.Tables.Msg.Forum; import java.util.List; @@ -11,6 +13,8 @@ import org.hibernate.annotations.OnDeleteAction; @Entity @Data +@NoArgsConstructor +@AllArgsConstructor public class Course { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -37,34 +41,4 @@ public class Course { this.title = title; this.owner = owner; } - - public Course() {} - - public int getCourseID() { - return courseID; - } - - public int getCredits() { - return credits; - } - - public void setCredits(int credits){ - this.credits = credits; - } - - public String getTitle() { - return title; - } - - 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/UserCurriculum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java index 395eca7..34caf26 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java @@ -1,10 +1,17 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @Entity +@Data +@AllArgsConstructor +@NoArgsConstructor public class UserCurriculum { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -26,48 +33,10 @@ public class UserCurriculum { //True if the user has that curriculum at the moment false if not private boolean actual; - public UserCurriculum(User user, Curriculum curriculum, int year, boolean actual){ - this.user = user; - this.curriculum = curriculum; - this.year = year; - this.actual = actual; - } - - public UserCurriculum() {} - - public int getId() { - return id; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public Curriculum getCurriculum() { - return curriculum; - } - - public void setCurriculum(Curriculum curriculum) { - this.curriculum = curriculum; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - - public void setActual(boolean actual) { - this.actual = actual; - } - - public boolean isActual() { - return actual; - } + public UserCurriculum(User u, Curriculum cu, int year, boolean actual){ + this.user = u; + this.curriculum = cu; + this.year = year; + this.actual = actual; + } } diff --git a/frontend/src/Apps/Forums.vue b/frontend/src/Apps/Forums.vue index a39da43..d2004c5 100644 --- a/frontend/src/Apps/Forums.vue +++ b/frontend/src/Apps/Forums.vue @@ -8,16 +8,16 @@