From cb750b8505f956717eb137a06f161eb89210c446 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 2 Apr 2024 21:40:52 +0200 Subject: [PATCH 01/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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();
+
+
+ + +
+