implement ListUserPosts use case

validates userId > 0, delegates to PostRepository->findByUserId.
54 tests pass.
This commit is contained in:
yisroel 2026-05-06 15:25:07 +03:00
parent e97ca28237
commit 32cbf4229c
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,28 @@
<?php
namespace App\Post\UseCases\ListUserPosts;
use App\Exceptions\BadRequestException;
use App\Post\Post;
use App\Post\PostRepository;
class ListUserPosts
{
public function __construct(
private PostRepository $postRepo,
) {}
/**
* @return Post[]
*
* @throws BadRequestException
*/
public function execute(ListUserPostsRequest $request): array
{
if ($request->userId <= 0) {
throw new BadRequestException('userId must be positive');
}
return $this->postRepo->findByUserId($request->userId);
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace App\Post\UseCases\ListUserPosts;
class ListUserPostsRequest
{
public function __construct(
public int $userId,
) {}
}