From a59fc4890ffc467a5ae840e605eed5c1841c324a Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 22:15:49 +0300 Subject: [PATCH] implement ListCommentsForPost use case Renames seed() helper to seedComment() to avoid clashing with Illuminate\Foundation\Testing\TestCase::seed(). --- .../ListCommentsForPost.php | 28 +++++++++++++++++++ .../ListCommentsForPostRequest.php | 10 +++++++ .../UseCases/ListCommentsForPostTest.php | 8 +++--- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPost.php create mode 100644 backend/app/Comment/UseCases/ListCommentsForPost/ListCommentsForPostRequest.php 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,