From cb750b8505f956717eb137a06f161eb89210c446 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 2 Apr 2024 21:40:52 +0200 Subject: [PATCH 01/39] Database creation (Tables) --- backend/build.gradle.kts | 2 ++ .../ovh/herisson/Clyde/Tables/Course.java | 9 ++++++ .../herisson/Clyde/Tables/Msg/Answers.java | 32 +++++++++++++++++++ .../ovh/herisson/Clyde/Tables/Msg/Forum.java | 28 ++++++++++++++++ .../ovh/herisson/Clyde/Tables/Msg/Topic.java | 26 +++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index b7cabcd..794631f 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -16,6 +16,8 @@ repositories { } dependencies { + compileOnly("org.projectlombok:lombok") + annotationProcessor("org.projectlombok:lombok") implementation("org.springframework.boot:spring-boot-starter-jdbc") implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-mail") 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 df0421d..8870618 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,6 +1,10 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import ovh.herisson.Clyde.Tables.Msg.Forum; + +import java.util.List; + import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -17,6 +21,11 @@ public class Course { @JoinColumn(name = "Users") private User owner; + //// Extension Messagerie ///// + @OneToMany + private List forums; + /////////////////////////////// + public Course(int credits, String title, User owner){ this.credits = credits; this.title = title; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java new file mode 100644 index 0000000..2f4d452 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Answers.java @@ -0,0 +1,32 @@ +package ovh.herisson.Clyde.Tables.Msg; + + +import java.util.Date; + +import org.hibernate.annotations.CreationTimestamp; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Answers { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @CreationTimestamp + private Date creation; + + @ManyToOne + private Topic topic; + + private String content; + + @OneToOne + private User author; + + private boolean anonymous; + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java new file mode 100644 index 0000000..e021c18 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java @@ -0,0 +1,28 @@ +package ovh.herisson.Clyde.Tables.Msg; + +import java.util.List; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Forum { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne(cascade = CascadeType.ALL) + private Course course; + + private String name; + + @OneToMany + private List writers; // User who are authorized to create a post + + @OneToMany + private List register; +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java new file mode 100644 index 0000000..d63b3e1 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Topic.java @@ -0,0 +1,26 @@ +package ovh.herisson.Clyde.Tables.Msg; + +import java.util.List; + +import jakarta.persistence.*; +import lombok.Data; +import ovh.herisson.Clyde.Tables.User; + +@Entity +@Data +public class Topic { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + private String subject, content; + + @OneToOne + private User author; + + @OneToMany(mappedBy = "topic", cascade = CascadeType.ALL) + private List answers; + + private boolean locked; // true if new messages can be posted +} From a96609d2efd9d9154bdb06347c0ba3ee8e67d3d2 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Wed, 3 Apr 2024 14:58:04 +0200 Subject: [PATCH 02/39] Page to right size --- frontend/src/App.vue | 13 ++++++------- frontend/src/assets/main.css | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 6dcad67..40fbbc6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -99,20 +99,19 @@ window.addEventListener('hashchange', () => { height: 100%; width: 100%; display:grid; - grid-template-columns:[firstCol-start]70px[firstCol-end secondCol-start]auto[endCol]; - grid-template-rows:[firstRow-start]61px[firstRow-end secondRow-start] auto [endRow]; + + grid-template-columns:[firstCol-start]70px[firstCol-end secondCol-start] auto [endCol]; + grid-template-rows:[firstRow-start] var(--header-size) [firstRow-end secondRow-start] calc(100% - var(--header-size)) [endRow]; grid-template-areas: "topBar topBar" "leftBar page"; - row-gap:0px; - column-gap:0px; + } .page { grid-area:page; height: 100%; width: 100%; - place-self:center; } .topBar{ @@ -155,7 +154,7 @@ window.addEventListener('hashchange', () => { ul.vertical{ list-style-type: none; - margin-top: 61px; + margin-top: var(--header-size); top:0; left:0; padding: 25px 0 0; @@ -203,7 +202,7 @@ window.addEventListener('hashchange', () => { left:0; position: fixed; - height:61px; + height:var(--header-size); width: 100%; background-color: rgb(24, 24, 24); } diff --git a/frontend/src/assets/main.css b/frontend/src/assets/main.css index 54ce8d8..67f454e 100644 --- a/frontend/src/assets/main.css +++ b/frontend/src/assets/main.css @@ -1,3 +1,7 @@ +:root { + --header-size: 61px; +} + body { background-color: rgb(53, 25, 60); margin:0; From 7bd745fd5e4dd1e976a4c086ef3198de0a90b6fd Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Fri, 5 Apr 2024 08:57:19 +0200 Subject: [PATCH 03/39] Adding frontend visual side --- frontend/src/Apps/Forums.vue | 138 +++++++++++++++++++++++++++++++++++ frontend/src/rest/apps.js | 4 +- frontend/src/rest/forum.js | 71 ++++++++++++++++++ 3 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 frontend/src/Apps/Forums.vue create mode 100644 frontend/src/rest/forum.js diff --git a/frontend/src/Apps/Forums.vue b/frontend/src/Apps/Forums.vue new file mode 100644 index 0000000..3e777e2 --- /dev/null +++ b/frontend/src/Apps/Forums.vue @@ -0,0 +1,138 @@ + + + + + + + + diff --git a/frontend/src/rest/apps.js b/frontend/src/rest/apps.js index 99cbc10..344e22a 100644 --- a/frontend/src/rest/apps.js +++ b/frontend/src/rest/apps.js @@ -9,6 +9,7 @@ import Profil from "@/Apps/Profil.vue" import Courses from "@/Apps/ManageCourses.vue" import Users from "@/Apps/UsersList.vue" import Students from "@/Apps/StudentsList.vue" +import Forums from '@/Apps/Forums.vue' const apps = { '/login': LoginPage, @@ -17,12 +18,13 @@ const apps = { '/manage-courses' : Courses, '/users-list' : Users, '/students-list' : Students, + '/forums': Forums, } const appsList = { 'Msg': { path: '#/msg', icon: 'fa-comment', text: i18n("app.messages") }, 'Notification': { path: '#/notifs', icon: 'fa-bell', text: i18n("app.notifications") }, - 'Forum': { path: '#/forum', icon: 'fa-envelope', text: i18n("app.forum") }, + 'Forum': { path: '#/forums', icon: 'fa-envelope', text: i18n("app.forum") }, 'Schedule': { path: '#/schedule', icon: 'fa-calendar-days', text: i18n("app.schedules") }, 'Inscription': { path: '#/inscription', icon: 'fa-users', text: i18n("app.inscription.requests") }, 'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") }, diff --git a/frontend/src/rest/forum.js b/frontend/src/rest/forum.js new file mode 100644 index 0000000..7920a33 --- /dev/null +++ b/frontend/src/rest/forum.js @@ -0,0 +1,71 @@ +import { ref } from 'vue' +import { restGet, restPost, restDelete, restPatch } from './restConsumer.js' + +/** + * List forums of a course + */ +export async function getForumsOfCourse(id){ + ForumsOfCurrentCourse.value = [ + { + id: 1, + name: "forum~1" + }, + { + id: 2, + name: "forum~2" + }, + ] + // ForumsOfCurrentCourse = await restGet("/forums/" + id) +} + +export const ForumsOfCurrentCourse = ref(); + +/** + * List post of a specified forum + */ +export async function getPostsOfForum(id){ + PostsOfCurrentForum.value = [ + { + id: 1, + name: "Post~1" + }, + { + id: 2, + name: "Post~2" + }, + ] + // PostsCurrentForum.value = await restGet("/forum/" + id); +} + +export const PostsOfCurrentForum = ref(); + +/** + * Get a post and its responses + */ +export async function fetchPost(id){ + fetchedPost.value = { + id: 1, + subject: "This is the subject of the post", + content: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.", + messages: [ + { + id: 1, + author: "author~1", + content: "J'ai pas copris le message !" + }, + { + id: 2, + author: "author~2", + content: "tu as fait une faute dans ton message..." + }, + { + id: 3, + author: null, + content: "I'm anonymous noww..." + } + ] + } + // fetchedPost.value = await restGet("/forum/post/" + id); +} + +export const fetchedPost = ref(); From f9bcff6d4f1e98204737fdb9006589fddaaac74f Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 7 Apr 2024 14:46:14 +0200 Subject: [PATCH 04/39] Avoid password leakage The password should never be parsed to json ever so can be safely ignored. --- backend/src/main/java/ovh/herisson/Clyde/Tables/User.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index de958df..2b939ee 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -3,6 +3,8 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; import java.util.Date; +import com.fasterxml.jackson.annotation.JsonIgnore; + @Entity @Table(name = "Users") @@ -18,7 +20,8 @@ public class User { private String country; private Date birthDate; private String profilePictureUrl; - private ovh.herisson.Clyde.Tables.Role role; + private Role role; + @JsonIgnore private String password; public User(String lastName, String firstName, String email, String address, String country, Date birthDate, String profilePictureUrl, Role role, String password) From 5a4d066c4548611f8f9e943a0985cb388c7d2280 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 7 Apr 2024 18:16:05 +0200 Subject: [PATCH 05/39] Forum and topic getter and creator endpoints --- .../Clyde/EndPoints/Msg/ForumController.java | 84 +++++++++++++++++++ .../Repositories/Msg/ForumRepository.java | 9 ++ .../Clyde/Services/Msg/ForumService.java | 29 +++++++ .../ovh/herisson/Clyde/Tables/Course.java | 6 ++ .../ovh/herisson/Clyde/Tables/Msg/Forum.java | 7 ++ 5 files changed, 135 insertions(+) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/ForumRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java 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 new file mode 100644 index 0000000..ef502d6 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java @@ -0,0 +1,84 @@ +package ovh.herisson.Clyde.EndPoints.Msg; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; + +import jakarta.websocket.server.PathParam; +import lombok.AllArgsConstructor; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.Msg.ForumRepository; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Services.AuthenticatorService; +import ovh.herisson.Clyde.Services.CourseService; +import ovh.herisson.Clyde.Services.Msg.ForumService; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.User; +import ovh.herisson.Clyde.Tables.Msg.Forum; +import ovh.herisson.Clyde.Tables.Msg.Topic; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +@AllArgsConstructor +public class ForumController { + + private CourseRepository courseRepo; + private CourseService courseServ; + private AuthenticatorService authServ; + private ForumService forumServ; + private ForumRepository forumRepo; + + //// Endpoints to get and create new forums + + @GetMapping("/forums/{id}") + public ResponseEntity> getForumFromCourseId(@RequestHeader("Authorization") String token, @PathVariable long id){ + User u = authServ.getUserFromToken(token); + if(u != null){ + return new UnauthorizedResponse<>(null); + } + return new ResponseEntity<>(courseRepo.findById(id).getForums(), HttpStatus.OK); + } + + @PostMapping("/forums/{id}") + public ResponseEntity createForumOfCourse(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Forum data){ + User u = authServ.getUserFromToken(token); + Course c = courseRepo.findById(id); + if(!c.getOwner().equals(u)){ + return new UnauthorizedResponse<>(null); + } + forumServ.createForum(c, data); + return new ResponseEntity<>(HttpStatus.ACCEPTED); + } + + //// Endpoints to get and create forum's topic + + @GetMapping("/forum/{id}") + public ResponseEntity> getTopicsFromForumId(@RequestHeader("Authorization") String token, @PathVariable long id){ + User u = authServ.getUserFromToken(token); + if(u != null){ + return new UnauthorizedResponse<>(null); + } + return new ResponseEntity<>(forumRepo.findById(id).orElse(null).getTopics(), HttpStatus.OK); + } + + @PostMapping("/forum/{id}") + public ResponseEntity postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Topic data){ + User u = authServ.getUserFromToken(token); + Forum f = forumRepo.findById(id).orElse(null); + if(!f.getWriters().contains(u)){ + return new UnauthorizedResponse<>(null); + } + forumServ.createTopic(f, data); + return new ResponseEntity<>(HttpStatus.ACCEPTED); + } +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/ForumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/ForumRepository.java new file mode 100644 index 0000000..07afe54 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/ForumRepository.java @@ -0,0 +1,9 @@ +package ovh.herisson.Clyde.Repositories.Msg; + +import org.springframework.data.repository.CrudRepository; + +import ovh.herisson.Clyde.Tables.Msg.Forum; + +public interface ForumRepository extends CrudRepository { + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java new file mode 100644 index 0000000..3fbf0df --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java @@ -0,0 +1,29 @@ +package ovh.herisson.Clyde.Services.Msg; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import lombok.AllArgsConstructor; +import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.Msg.ForumRepository; +import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Msg.Forum; +import ovh.herisson.Clyde.Tables.Msg.Topic; + +@Service +@AllArgsConstructor +public class ForumService { + + private CourseRepository courseRepo; + private ForumRepository forumRepo; + + public void createForum(Course c, Forum f){ + c.addForum(f); + courseRepo.save(c); + } + + public void createTopic(Forum f, Topic data) { + f.addTopic(data); + forumRepo.save(f); + } +} 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 8870618..7fff00f 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -1,6 +1,7 @@ package ovh.herisson.Clyde.Tables; import jakarta.persistence.*; +import lombok.Data; import ovh.herisson.Clyde.Tables.Msg.Forum; import java.util.List; @@ -9,6 +10,7 @@ import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @Entity +@Data public class Course { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -24,6 +26,10 @@ public class Course { //// Extension Messagerie ///// @OneToMany private List forums; + + public void addForum(Forum f){ + forums.add(f); + } /////////////////////////////// public Course(int credits, String title, User owner){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java index e021c18..3baa406 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java @@ -21,6 +21,13 @@ public class Forum { private String name; @OneToMany + private List topics; + + public void addTopic(Topic t) { + topics.add(t); + } + + @OneToMany private List writers; // User who are authorized to create a post @OneToMany From 5f483216b9e6d79a48adef14e2364deb5ecfd1e4 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 8 Apr 2024 10:02:03 +0200 Subject: [PATCH 06/39] indev --- .../Clyde/EndPoints/Msg/ForumController.java | 18 ++++++++++++++++++ .../Repositories/Msg/TopicRepository.java | 10 ++++++++++ 2 files changed, 28 insertions(+) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java 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 ef502d6..47e8670 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 @@ -18,11 +18,13 @@ import jakarta.websocket.server.PathParam; import lombok.AllArgsConstructor; import ovh.herisson.Clyde.Repositories.CourseRepository; import ovh.herisson.Clyde.Repositories.Msg.ForumRepository; +import ovh.herisson.Clyde.Repositories.Msg.TopicRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.CourseService; import ovh.herisson.Clyde.Services.Msg.ForumService; import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.Msg.Forum; import ovh.herisson.Clyde.Tables.Msg.Topic; @@ -37,6 +39,7 @@ public class ForumController { private AuthenticatorService authServ; private ForumService forumServ; private ForumRepository forumRepo; + private TopicRepository topicRepo; //// Endpoints to get and create new forums @@ -81,4 +84,19 @@ public class ForumController { forumServ.createTopic(f, data); return new ResponseEntity<>(HttpStatus.ACCEPTED); } + + //// Endpoints related to topics and messages + + @GetMapping("/forum/post/{id}") + public ResponseEntity getPost(@RequestHeader("Authorization") String token, @PathVariable long id){ + User u = authServ.getUserFromToken(token); + if(u != null){ + return new UnauthorizedResponse<>(null); + } + Topic t = topicRepo.findById(id).orElse(null); + return new ResponseEntity<>(t, HttpStatus.OK); + } + + + // TODO: Create a new post/topic and response to a topic } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java new file mode 100644 index 0000000..bff279c --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java @@ -0,0 +1,10 @@ +package ovh.herisson.Clyde.EndPoints.Msg; + +import org.springframework.data.repository.CrudRepository; + +import ovh.herisson.Clyde.Tables.Msg.Topic; + +public interface TopicRepository extends CrudRepository { + +} + From 61e269eb274f5b8bc7ce323bfb38376194bd236e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 9 Apr 2024 17:27:26 +0200 Subject: [PATCH 07/39] Linking front for forum creation --- .../Clyde/EndPoints/Msg/ForumController.java | 5 ++- .../Repositories/Msg/TopicRepository.java | 2 +- .../Clyde/Services/Msg/ForumService.java | 1 - .../ovh/herisson/Clyde/Tables/Course.java | 2 +- .../ovh/herisson/Clyde/Tables/Msg/Forum.java | 2 +- frontend/src/Apps/Forums.vue | 41 ++++++++++++++++++- frontend/src/rest/forum.js | 16 +++----- 7 files changed, 50 insertions(+), 19 deletions(-) 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 47e8670..8163a69 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 @@ -24,6 +24,7 @@ import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.CourseService; import ovh.herisson.Clyde.Services.Msg.ForumService; import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.Msg.Forum; @@ -46,7 +47,7 @@ public class ForumController { @GetMapping("/forums/{id}") public ResponseEntity> getForumFromCourseId(@RequestHeader("Authorization") String token, @PathVariable long id){ User u = authServ.getUserFromToken(token); - if(u != null){ + if(u == null){ return new UnauthorizedResponse<>(null); } return new ResponseEntity<>(courseRepo.findById(id).getForums(), HttpStatus.OK); @@ -56,7 +57,7 @@ public class ForumController { public ResponseEntity createForumOfCourse(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Forum data){ User u = authServ.getUserFromToken(token); Course c = courseRepo.findById(id); - if(!c.getOwner().equals(u)){ + if(!(c.getOwner().equals(u) || u.getRole() == Role.Admin)){ return new UnauthorizedResponse<>(null); } forumServ.createForum(c, data); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java index bff279c..905cd01 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java @@ -1,4 +1,4 @@ -package ovh.herisson.Clyde.EndPoints.Msg; +package ovh.herisson.Clyde.Repositories.Msg; import org.springframework.data.repository.CrudRepository; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java index 3fbf0df..ddf5be6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java @@ -1,6 +1,5 @@ package ovh.herisson.Clyde.Services.Msg; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import lombok.AllArgsConstructor; 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 7fff00f..0534b0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -24,7 +24,7 @@ public class Course { private User owner; //// Extension Messagerie ///// - @OneToMany + @OneToMany(cascade = CascadeType.ALL) private List forums; public void addForum(Forum f){ diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java index 3baa406..3ca1637 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java @@ -15,7 +15,7 @@ public class Forum { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne private Course course; private String name; diff --git a/frontend/src/Apps/Forums.vue b/frontend/src/Apps/Forums.vue index 3e777e2..5f56704 100644 --- a/frontend/src/Apps/Forums.vue +++ b/frontend/src/Apps/Forums.vue @@ -8,13 +8,18 @@ @@ -28,10 +33,11 @@ const selectedForum = ref(); +
{{ post.name }}
- +
@@ -43,10 +49,41 @@ const selectedForum = ref();
+
+
+ + +
+
\ No newline at end of file diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index e45a1a5..f3a2284 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -4,6 +4,7 @@ import {validateRegister, getAllRegisters } from '@/rest/ServiceInscription.js' import AboutRequest from "@/Apps/Inscription/AboutRequest.vue"; import {getAllExemptionsRequest, getAllScholarShipsRequest} from "@/rest/requests.js"; + import AboutScholarship from "@/Apps/Inscription/AboutScholarship.vue"; const requests = ref(await getAllRegisters()); let targetId = ""; @@ -11,7 +12,7 @@ const requestType = ref("inscription"); const filterType = ref("None"); - //0 = liste, 1 = détails, 2 = sure? + //0 = liste, 1 = détails, 2 = sure?, 3 = manage scholarship let windowsState = ref(0); async function upPage(id,review){ @@ -79,7 +80,7 @@
{{item.user.firstName}}
{{item.user.lastName}}
{{item.state}}
-
+
{{item.date.slice(0,10)}}
@@ -97,6 +98,12 @@
+
+ +
+ +
+
\ No newline at end of file diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index b6a1a50..7869557 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -5,6 +5,7 @@ import AboutRequest from "@/Apps/Inscription/AboutRequest.vue"; import {getAllExemptionsRequest, getAllScholarShipsRequest, getAllUnregisters} from "@/rest/requests.js"; import AboutScholarship from "@/Apps/Inscription/AboutScholarship.vue"; + import AboutUnregister from "@/Apps/Inscription/AboutUnregister.vue"; const requests = ref(await getAllRegisters()); let targetId = ""; @@ -12,7 +13,7 @@ const requestType = ref("inscription"); const filterType = ref("None"); - //0 = liste, 1 = détails, 2 = sure?, 3 = manage scholarship + //0 = liste, 1 = détails, 2 = sure?, 3 = manage scholarship, 4 manage unregister let windowsState = ref(0); async function upPage(id,review){ @@ -101,7 +102,7 @@
{{item.lastName}}
id : {{item.regNo}}
{{item.state}}
-
+
@@ -111,12 +112,15 @@ -
+
+
+ +
+ diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index e45a0e4..f31f5da 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -22,17 +22,12 @@ if(user.role === "Teacher"){ UserCurriculum.value = await getCourses("Teacher"); } - const modif = ref(false); - const curric = ref(false); - const reg = ref(false); - const courseslist = ref(false); - const minerval = ref(false); - const paymentPage = ref(false); - const scholarship = ref(false); - const scholarshipinfos = ref(false); - const uninscr = ref(false); + const sure = ref(0); + //0 base, 1 modif, 2 curriculum, 3 register, 4 courselist, 5 minerval, 6 payment, 7 scholarship, 8 scholarshipinfos, 9 unregister, 10 sure, 11 aboutunregister + const windowState = ref(0); + const pattern = { profilPictureUrl:null, email:null, @@ -82,17 +77,17 @@ async function ChangeInfos(){ for (let element in toModify){ - if (element =="email" && (toModify[element] !== null)){ + if (element ==="email" && (toModify[element] !== null)){ await alterSelf(user.value.regNo,{email : toModify[element]}); } - if (element =="profilPictureUrl" && (toModify[element] !== null)){ + if (element ==="profilPictureUrl" && (toModify[element] !== null)){ await alterSelf(user.value.regNo,{ profilPictureUrl : toModify[element]}); } - else if(element == "address" && (toModify[element] !== null)){ + else if(element === "address" && (toModify[element] !== null)){ await alterSelf(user.value.regNo,{address : toModify[element]}); } - else if(element == "password" && (toModify[element] !== null)){ + else if(element === "password" && (toModify[element] !== null)){ await alterSelf(user.value.regNo,{password : toModify[element]}); } } @@ -159,12 +154,12 @@ diff --git a/frontend/src/rest/apps.js b/frontend/src/rest/apps.js index b414e68..eb13476 100644 --- a/frontend/src/rest/apps.js +++ b/frontend/src/rest/apps.js @@ -4,13 +4,12 @@ import i18n from '@/i18n.js' // Liste des apps import LoginPage from '@/Apps/Login.vue' -import Inscription from "@/Apps/Inscription/ManageRequests.vue" import Profil from "@/Apps/Profil.vue" import Courses from "@/Apps/ManageCourses.vue" import Users from "@/Apps/UsersList.vue" import Students from "@/Apps/StudentsList.vue" -import AboutStudent from "@/Apps/Inscription/AboutStudent.vue"; import Msg from "@/Apps/Msg.vue" +import Payments from "@/Apps/Inscription/PaymentInfo.vue"; import ManageRequests from "@/Apps/Inscription/ManageRequests.vue"; const apps = { @@ -21,6 +20,7 @@ const apps = { '/users-list' : Users, '/students-list' : Students, '/msg' : Msg, + '/payments': Payments } const appsList = { @@ -32,6 +32,7 @@ const appsList = { 'ManageCourses': { path: '#/manage-courses', icon: 'fa-book', text: i18n("app.manage.courses") }, 'StudentsList':{ path: '#/students-list',icon: 'fa-users',text: i18n("app.studentList")}, 'UsersList':{ path: '#/users-list',icon: 'fa-users',text: i18n("app.users")}, + 'Payments':{path: '#/payments', icon:'fa-users', text:i18n("app.payments")} } const currentPath = ref(window.location.hash) diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 05140ae..9d43968 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -34,4 +34,16 @@ export async function getScholarshipReqById(id){ export async function getAllUnregisters(){ return restGet("/unregister") +} + +export async function getUnregisterbyId(id){ + return restGet("/unregister/"+id) +} + +export async function editUnregReq(id, newstate){ + return restPatch("/unregister/"+id+"/"+newstate) +} + +export async function getAllPayments(){ + return restGet("/payment") } \ No newline at end of file From 058c53dbbc6e5c92555666ed4c47155554c3afd7 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 17 Apr 2024 11:55:56 +0200 Subject: [PATCH 15/39] Add the actual in UserCurriculum Rework the unregister procedure Add ChangeCurriculumRequest Add the changeCurriculumRequest submit --- .../Inscription/RequestsController.java | 35 +++++++- .../Clyde/EndPoints/MockController.java | 12 +-- .../ChangeCurriculumRequestRepository.java | 7 ++ .../Inscription/InscriptionService.java | 4 +- .../Clyde/Services/UserCurriculumService.java | 3 +- .../Clyde/Tables/ChangeCurriculumRequest.java | 83 +++++++++++++++++++ .../herisson/Clyde/Tables/UserCurriculum.java | 14 +++- .../src/Apps/Inscription/AboutStudent.vue | 12 +-- frontend/src/Apps/Profil.vue | 37 +++++---- frontend/src/rest/requests.js | 4 + 10 files changed, 179 insertions(+), 32 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java index 934e37c..2b4f9d3 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java @@ -4,9 +4,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.CourseRepository; +import ovh.herisson.Clyde.Repositories.CurriculumRepository; +import ovh.herisson.Clyde.Repositories.Inscription.ChangeCurriculumRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExemptionsRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository; import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository; +import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserRepository; import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; @@ -31,8 +34,12 @@ public class RequestsController { public final UnregisterRequestRepository unregisterRequestRepository; public final CourseRepository courseRepository; public final UserService userService; + public final UserCurriculumRepository userCurriculumRepository; + public final CurriculumRepository curriculumRepository; - public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService) { + public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository; + + public RequestsController(ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) { this.err = err; this.srr = srr; this.userRepository = userRepository; @@ -40,6 +47,9 @@ public class RequestsController { this.unregisterRequestRepository = unregisterRequestRepository; this.courseRepository = courseRepository; this.userService = userService; + this.userCurriculumRepository = userCurriculumRepository; + this.curriculumRepository = curriculumRepository; + this.changeCurriculumRequestRepository = changeCurriculumRequestRepository; } @PostMapping(value="/exemptionreq") @@ -135,14 +145,33 @@ public class RequestsController { @PatchMapping(value = "/unregister/{id}/{newstate}") public ResponseEntity pathUnregReq(@PathVariable long id, @PathVariable RequestState newstate){ UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id); - + User u = userRepository.findById(unregisterRequest.getRegNo()); unregisterRequest.setState(newstate); if (newstate == RequestState.Accepted){ - userService.delete(userRepository.findById(unregisterRequest.getRegNo())); + ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); + for (int i = 0; i < userCurricula.size(); i++){ + userCurricula.get(i).setActual(false); + } + userCurriculumRepository.saveAll(userCurricula); } unregisterRequestRepository.save(unregisterRequest); return new ResponseEntity<>(HttpStatus.OK); } + + @PostMapping("/changecurriculumreq") + public ResponseEntity addChangeCurrReq(@RequestBody Map reqInfos){ + User user = userRepository.findById((Integer) reqInfos.get("userId")); + + Curriculum actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus")); + + Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus")); + + ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending); + + changeCurriculumRequestRepository.save(changeCurriculumRequest); + + return new ResponseEntity<>(HttpStatus.OK); + } } 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 11ca6fd..918a924 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -93,12 +93,12 @@ public class MockController { curriculumService.save(masterinfo1); curriculumService.save(masterinfo2); - ucr.save(new UserCurriculum(joe, infoBab1, 2022)); - ucr.save(new UserCurriculum(joe, chemistryBab1, 2023)); - ucr.save(new UserCurriculum(joe, infoBab1, 2023)); - ucr.save(new UserCurriculum(joe, psychologyBab1, 2020)); - ucr.save(new UserCurriculum(popo, infoBab1, 2022)); - ucr.save(new UserCurriculum(popo, infoBab2, 2023)); + ucr.save(new UserCurriculum(joe, infoBab1, 2022, false)); + ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true)); + ucr.save(new UserCurriculum(joe, infoBab1, 2023, true)); + ucr.save(new UserCurriculum(joe, psychologyBab1, 2020, false)); + ucr.save(new UserCurriculum(popo, infoBab1, 2022, false)); + ucr.save(new UserCurriculum(popo, infoBab2, 2023, true)); Course progra1 = new Course(5,"Programmation et algorithmique 1",joke); Course chemistry1 = new Course(12, "Thermochimie",joke); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java new file mode 100644 index 0000000..414f119 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Inscription/ChangeCurriculumRequestRepository.java @@ -0,0 +1,7 @@ +package ovh.herisson.Clyde.Repositories.Inscription; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.ChangeCurriculumRequest; + +public interface ChangeCurriculumRequestRepository extends CrudRepository { +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java index c80e2d9..a40f537 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java @@ -12,6 +12,7 @@ import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest; import ovh.herisson.Clyde.Tables.Inscription.Minerval; import java.util.ArrayList; +import java.util.Calendar; @Service public class InscriptionService { @@ -85,7 +86,8 @@ public class InscriptionService { ); userRepo.save(userFromRequest); - userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0)); + Calendar c = Calendar.getInstance(); + userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),c.get(Calendar.YEAR), true)); //Create a minerval for the new student Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java index 8b446df..2861a6e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserCurriculumService.java @@ -35,11 +35,12 @@ public class UserCurriculumService { HashMap element = new HashMap<>(); Curriculum c = list.get(i).getCurriculum(); - element.put("curriculumId", c.getCurriculumId()); element.put("year", c.getYear()); element.put("option", c.getOption()); element.put("dateyear", list.get(i).getYear()); + element.put("actual", list.get(i).isActual()); + curriculumlist.add(element); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java new file mode 100644 index 0000000..72feebd --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/ChangeCurriculumRequest.java @@ -0,0 +1,83 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.*; + +import java.util.Date; + +@Entity +public class ChangeCurriculumRequest { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @ManyToOne + @JoinColumn(name="Users") + private User user; + + @ManyToOne + @JoinColumn(name = "ActualCurriculum") + private Curriculum actualCurriculum; + + @ManyToOne + @JoinColumn(name = "DestCurriculum") + private Curriculum destinationCurriculum; + + private Date date; + + private RequestState state; + + public ChangeCurriculumRequest(){} + + public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state){ + this.user = user; + this.actualCurriculum = actualCurriculum; + this.destinationCurriculum = destinationCurriculum; + this.date = date; + this.state = state; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + + public Curriculum getActualCurriculum() { + return actualCurriculum; + } + + public void setActualCurriculum(Curriculum actualCurriculum) { + this.actualCurriculum = actualCurriculum; + } + + public Curriculum getDestinationCurriculum() { + return destinationCurriculum; + } + + public void setDestinationCurriculum(Curriculum destinationCurriculum) { + this.destinationCurriculum = destinationCurriculum; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getDate() { + return date; + } + + public RequestState getState() { + return state; + } + + public void setState(RequestState state) { + this.state = state; + } + + public int getId() { + return id; + } +} 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 b79295b..395eca7 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/UserCurriculum.java @@ -23,10 +23,14 @@ public class UserCurriculum { private int year; - public UserCurriculum(User user, Curriculum curriculum, int year){ + //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() {} @@ -58,4 +62,12 @@ public class UserCurriculum { public void setYear(int year) { this.year = year; } + + public void setActual(boolean actual) { + this.actual = actual; + } + + public boolean isActual() { + return actual; + } } diff --git a/frontend/src/Apps/Inscription/AboutStudent.vue b/frontend/src/Apps/Inscription/AboutStudent.vue index 03368c2..54d81fc 100644 --- a/frontend/src/Apps/Inscription/AboutStudent.vue +++ b/frontend/src/Apps/Inscription/AboutStudent.vue @@ -66,9 +66,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
@@ -78,9 +78,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index f31f5da..28a0763 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -8,7 +8,7 @@ import CourseList from "@/Apps/Inscription/CourseList.vue"; import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js"; import {postPayment} from "@/rest/payment.js"; - import {addUninscReq, createScholarshipRequest} from "@/rest/requests.js"; + import {addUninscReq, createScholarshipRequest, postChangeCurrReq} from "@/rest/requests.js"; const user = ref(await getSelf()); const UserCurriculum = ref(""); @@ -62,6 +62,12 @@ residencyDocUrl : "" }) + const changecurrdata = reactive({ + userId : user.value.regNo, + actualcursus:null, + newcursus:null + }) + //Used to post a uninscription request const uninscriptionData = reactive({ reason : null, @@ -132,7 +138,7 @@ function getActualCurriculumList(){ let actualCurriculumList = []; for (let i = 0; i < UserCurriculum.value.curriculumList.length; i++){ - if (UserCurriculum.value.curriculumList[i].dateyear === getYear()){ + if (UserCurriculum.value.curriculumList[i].actual === true){ actualCurriculumList.push(UserCurriculum.value.curriculumList[i]); } } @@ -281,20 +287,23 @@
- +
- {{i18n("Curriculum")}}: - + + + New Curriculum : +
-
- +
@@ -329,9 +338,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
@@ -341,9 +350,9 @@
-
Bac {{item.year}}
-
{{item.option}}
-
Année {{item.dateyear}}-{{item.dateyear+1}}
+
Bac {{item.year}}
+
{{item.option}}
+
Année {{item.dateyear}}-{{item.dateyear+1}}
diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index 9d43968..a4396a4 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -46,4 +46,8 @@ export async function editUnregReq(id, newstate){ export async function getAllPayments(){ return restGet("/payment") +} + +export async function postChangeCurrReq(item){ + return restPost("/changecurriculumreq", item) } \ No newline at end of file From 1be7b4cdbe96c04b515decb983c8cf29c605065f Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 17 Apr 2024 13:57:52 +0200 Subject: [PATCH 16/39] Add the unregistration of a specific cursus only --- .../Inscription/RequestsController.java | 25 +++++++++++++++---- .../Clyde/EndPoints/MockController.java | 2 +- .../UserCurriculumRepository.java | 1 + .../Tables/Inscription/UnregisterRequest.java | 18 ++++++++++++- frontend/src/Apps/Profil.vue | 19 +++++++++++--- frontend/src/rest/requests.js | 4 +-- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java index 2b4f9d3..faeefb2 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java @@ -103,7 +103,15 @@ public class RequestsController { @PostMapping(value = "/unregister") public ResponseEntity postUnregReq(@RequestBody Map uninscr){ User u = userRepository.findById((int) uninscr.get("userId")); - UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail()); + Curriculum c; + + if (uninscr.get("curriculumId") == null){ + c = null; + }else{ + c = curriculumRepository.findById((Integer) uninscr.get("curriculumId")); + } + + UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail(), c); unregisterRequestRepository.save(ur); return new ResponseEntity<>(HttpStatus.OK); } @@ -149,11 +157,18 @@ public class RequestsController { unregisterRequest.setState(newstate); if (newstate == RequestState.Accepted){ - ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); - for (int i = 0; i < userCurricula.size(); i++){ - userCurricula.get(i).setActual(false); + if (unregisterRequest.getCurriculum() == null){ + ArrayList userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u); + for (int i = 0; i < userCurricula.size(); i++){ + userCurricula.get(i).setActual(false); + } + userCurriculumRepository.saveAll(userCurricula); + }else{ + //This usercurriculum will contain the usercurriculum to set false + UserCurriculum userCurriculum = userCurriculumRepository.findByUserAndCurriculumAndActual(u, unregisterRequest.getCurriculum(), true); + userCurriculum.setActual(false); + userCurriculumRepository.save(userCurriculum); } - userCurriculumRepository.saveAll(userCurricula); } unregisterRequestRepository.save(unregisterRequest); 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 918a924..3919597 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -128,7 +128,7 @@ public class MockController { inscriptionService.save(inscriptionRequest); - UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail()); + UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail(), null); uninscriptionRequestRepository.save(unregisterRequest); ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java index 2f1c2a3..dbf203e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/UserCurriculumRepository.java @@ -14,4 +14,5 @@ public interface UserCurriculumRepository extends CrudRepository findByUserOrderByCurriculum(User student); + UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java index ba22294..9127ecb 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Inscription/UnregisterRequest.java @@ -1,6 +1,7 @@ package ovh.herisson.Clyde.Tables.Inscription; import jakarta.persistence.*; +import ovh.herisson.Clyde.Tables.Curriculum; import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Tables.User; @@ -24,7 +25,12 @@ public class UnregisterRequest { private String email; - public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email){ + //Null if the user unregister for the academic year, contains a curriculum if the user wants to unregister from a specific curriculum + @ManyToOne + @JoinColumn(name = "Curriculum") + private Curriculum curriculum; + + public UnregisterRequest(RequestState state, String reason, Date date, long regNo, String firstName, String lastName, String email, Curriculum curriculum){ this.state = state; this.reason = reason; this.date = date; @@ -32,6 +38,7 @@ public class UnregisterRequest { this.firstName = firstName; this.lastName = lastName; this.email = email; + this.curriculum = curriculum; } public UnregisterRequest(){} @@ -95,5 +102,14 @@ public class UnregisterRequest { public long getRegNo() { return regNo; } + + public void setCurriculum(Curriculum curriculum) { + this.curriculum = curriculum; + } + + public Curriculum getCurriculum() { + return curriculum; + } + } diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 28a0763..7a9fbc0 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -28,6 +28,8 @@ //0 base, 1 modif, 2 curriculum, 3 register, 4 courselist, 5 minerval, 6 payment, 7 scholarship, 8 scholarshipinfos, 9 unregister, 10 sure, 11 aboutunregister const windowState = ref(0); + const isChecked = ref(false); + const pattern = { profilPictureUrl:null, email:null, @@ -71,7 +73,8 @@ //Used to post a uninscription request const uninscriptionData = reactive({ reason : null, - userId : user.value.regNo + userId : user.value.regNo, + curriculumId:null }) const paymentAmount = ref(0); let toModify= Object.assign({}, pattern); @@ -194,14 +197,24 @@
-
Please enter the reason you leave the university
+
Please enter the reason you leave
+
+ I only want to unregister from a specific cursus + +
+
+ Please select that cursus + +
Are you sure that you want to unregister ? - +

You request has been send !

diff --git a/frontend/src/rest/requests.js b/frontend/src/rest/requests.js index a4396a4..4bf8411 100644 --- a/frontend/src/rest/requests.js +++ b/frontend/src/rest/requests.js @@ -20,8 +20,8 @@ export async function editEquivalenceState(id, newstate){ return restPatch("/request/registerequiv/"+id+"/"+newstate) } -export async function addUninscReq(userId, reason){ - return restPost("/unregister", {"userId" : userId, "reason" : reason}) +export async function addUninscReq(userId, reason, curriculumId){ + return restPost("/unregister", {"userId" : userId, "reason" : reason, "curriculumId":curriculumId}) } export async function editScholarshipReq(body){ From a27cf63daf9b7de35f8154a4c7c3d7d46977cea0 Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Wed, 17 Apr 2024 21:42:33 +0200 Subject: [PATCH 17/39] Add the post feature for differents types of changeCurriculumRequest --- .../Inscription/RequestsController.java | 9 +++- .../Clyde/EndPoints/MockController.java | 3 +- frontend/src/Apps/Profil.vue | 52 +++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java index faeefb2..83292ec 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Inscription/RequestsController.java @@ -179,7 +179,14 @@ public class RequestsController { public ResponseEntity addChangeCurrReq(@RequestBody Map reqInfos){ User user = userRepository.findById((Integer) reqInfos.get("userId")); - Curriculum actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus")); + Curriculum actualCurriculum; + + //If null then it means we are in a supplementary cursus case + if (reqInfos.get("actualcursus") == null){ + actualCurriculum = null; + }else{ + actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus")); + } Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus")); 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 3919597..2181da0 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -85,13 +85,14 @@ public class MockController { Curriculum infoBab2 = new Curriculum(2,"info"); Curriculum masterinfo1 = new Curriculum(4, "info"); Curriculum masterinfo2 = new Curriculum(5, "info"); - + Curriculum chemistryBab2 = new Curriculum(2, "chemistry"); curriculumService.save(infoBab1); curriculumService.save(chemistryBab1); curriculumService.save(psychologyBab1); curriculumService.save(infoBab2); curriculumService.save(masterinfo1); curriculumService.save(masterinfo2); + curriculumService.save(chemistryBab2); ucr.save(new UserCurriculum(joe, infoBab1, 2022, false)); ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true)); diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 7a9fbc0..eb9a80b 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -1,7 +1,7 @@ diff --git a/frontend/src/Apps/Login.vue b/frontend/src/Apps/Login.vue index dbac9e3..705012f 100644 --- a/frontend/src/Apps/Login.vue +++ b/frontend/src/Apps/Login.vue @@ -100,7 +100,7 @@ diff --git a/frontend/src/Apps/Inscription/ManageRequests.vue b/frontend/src/Apps/Inscription/ManageRequests.vue index 8fd7ddf..1aa9bf0 100644 --- a/frontend/src/Apps/Inscription/ManageRequests.vue +++ b/frontend/src/Apps/Inscription/ManageRequests.vue @@ -1,6 +1,6 @@ @@ -118,6 +119,10 @@

Année de fin

+
+

Veuillez soumettre un document attestant de ce parcours

+ +
diff --git a/frontend/src/Apps/Login.vue b/frontend/src/Apps/Login.vue index 531259b..7080f26 100644 --- a/frontend/src/Apps/Login.vue +++ b/frontend/src/Apps/Login.vue @@ -108,13 +108,13 @@ const val = await register(outputs.firstname, outputs.surname, outputs.birthday, outputs.password, outputs.email, outputs.address, outputs.country, outputs.curriculum, ppData, identityCardFile.url, new Date(), outputs.equivalenceState, justif); for (let item in externalCurrTab.value){ - await createExternalCurriculum(val.id, externalCurrTab.value[item].school, externalCurrTab.value[item].formation, externalCurrTab.value[item].completion, externalCurrTab.value[item].startYear, externalCurrTab.value[item].endYear, externalCurrTab.value[item].justifdocUrl); + const temp = await uploadFile(externalCurrTab.value[item].justifdocUrl, "JustificationDocument") + await createExternalCurriculum(val.id, externalCurrTab.value[item].school, externalCurrTab.value[item].formation, externalCurrTab.value[item].completion, externalCurrTab.value[item].startYear, externalCurrTab.value[item].endYear, temp.value.url); } } - @@ -113,4 +113,12 @@ async function editExemp(newstate){ background-color:rgb(50,50,50); border-radius:20px; } + +button{ + border:none; + background-color:rgb(239, 60, 168); + border-radius:10px; + height:35px; + margin-top:10px; +} \ No newline at end of file diff --git a/frontend/src/Apps/Inscription/AboutRequest.vue b/frontend/src/Apps/Inscription/AboutRequest.vue index 77565ed..efe401b 100644 --- a/frontend/src/Apps/Inscription/AboutRequest.vue +++ b/frontend/src/Apps/Inscription/AboutRequest.vue @@ -31,7 +31,7 @@ async function editEquivalence(id, newstate){ diff --git a/frontend/src/Apps/Inscription/ExternalCurriculumList.vue b/frontend/src/Apps/Inscription/ExternalCurriculumList.vue index 88fefbb..e608777 100644 --- a/frontend/src/Apps/Inscription/ExternalCurriculumList.vue +++ b/frontend/src/Apps/Inscription/ExternalCurriculumList.vue @@ -53,7 +53,7 @@ async function postExternalCurr(){ if (props.mode === 1){ const temp = await uploadFile(externalCurr.justifdocUrl, "JustificationDocument") - await createExternalCurriculum(externalCurr.inscriptionRequestId, externalCurr.school, externalCurr.formation, externalCurr.completion, externalCurr.startYear, externalCurr.endYear, temp.value.url, externalCurr.userRegNo); + await createExternalCurriculum(externalCurr.inscriptionRequestId, externalCurr.school, externalCurr.formation, externalCurr.completion, externalCurr.startYear, externalCurr.endYear, temp.url, externalCurr.userRegNo); //We refresh the list extCurrList.value = await getExternalCurriculumByUser(externalCurr.userRegNo); list.value = !list.value; @@ -77,9 +77,9 @@