From 5f483216b9e6d79a48adef14e2364deb5ecfd1e4 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Mon, 8 Apr 2024 10:02:03 +0200 Subject: [PATCH] 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 { + +} +