implement ListUserPosts use case
validates userId > 0, delegates to PostRepository->findByUserId. 54 tests pass.
This commit is contained in:
parent
e97ca28237
commit
32cbf4229c
2 changed files with 38 additions and 0 deletions
28
backend/app/Post/UseCases/ListUserPosts/ListUserPosts.php
Normal file
28
backend/app/Post/UseCases/ListUserPosts/ListUserPosts.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Post\UseCases\ListUserPosts;
|
||||
|
||||
class ListUserPostsRequest
|
||||
{
|
||||
public function __construct(
|
||||
public int $userId,
|
||||
) {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue