diff --git a/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPost.php b/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPost.php new file mode 100644 index 0000000..13cf6c4 --- /dev/null +++ b/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPost.php @@ -0,0 +1,28 @@ +postId <= 0) { + throw new BadRequestException('postId must be positive'); + } + + return $this->commentRepo->findByPostId($request->postId); + } +} diff --git a/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPostRequest.php b/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPostRequest.php new file mode 100644 index 0000000..6f53289 --- /dev/null +++ b/backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPostRequest.php @@ -0,0 +1,10 @@ +useCase = new ListCommentsForPost($this->commentRepo); } - private function seed(int $postId, string $body, string $offset): void + private function seedComment(int $postId, string $body, string $offset): void { $this->commentRepo->create(new CreateCommentDto( postId: $postId, @@ -58,9 +58,9 @@ class ListCommentsForPostTest extends TestCase public function test_returns_only_comments_for_given_post(): void { - $this->seed(1, 'first', '+0 seconds'); - $this->seed(2, 'other-post', '+0 seconds'); - $this->seed(1, 'second', '+1 minute'); + $this->seedComment(1, 'first', '+0 seconds'); + $this->seedComment(2, 'other-post', '+0 seconds'); + $this->seedComment(1, 'second', '+1 minute'); $result = $this->useCase->execute(new ListCommentsForPostRequest( postId: 1,