implement ListCommentsForPost use case

Renames seed() helper to seedComment() to avoid clashing with
Illuminate\Foundation\Testing\TestCase::seed().
This commit is contained in:
Yisroel Baum 2026-05-06 22:15:49 +03:00
parent f9e2529994
commit a59fc4890f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 42 additions and 4 deletions

View file

@ -0,0 +1,28 @@
<?php
namespace App\Comment\UseCases\ListCommentsForPost;
use App\Comment\Comment;
use App\Comment\CommentRepository;
use App\Exceptions\BadRequestException;
class ListCommentsForPost
{
public function __construct(
private CommentRepository $commentRepo,
) {}
/**
* @return Comment[]
*
* @throws BadRequestException
*/
public function execute(ListCommentsForPostRequest $request): array
{
if ($request->postId <= 0) {
throw new BadRequestException('postId must be positive');
}
return $this->commentRepo->findByPostId($request->postId);
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace App\Comment\UseCases\ListCommentsForPost;
class ListCommentsForPostRequest
{
public function __construct(
public int $postId,
) {}
}