This commit is contained in:
Debucquoy Anthony 2024-04-08 10:02:03 +02:00
parent 5a4d066c45
commit 5f483216b9
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 28 additions and 0 deletions

View File

@ -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<Topic> 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: <tonitch> Create a new post/topic and response to a topic
}

View File

@ -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<Topic, Long> {
}