26 lines
488 B
PHP
26 lines
488 B
PHP
<?php
|
|
|
|
namespace App\Post\UseCases\GetPost;
|
|
|
|
use App\Exceptions\BadRequestException;
|
|
use App\Post\Post;
|
|
use App\Post\PostRepository;
|
|
|
|
class GetPost
|
|
{
|
|
public function __construct(
|
|
private PostRepository $postRepo,
|
|
) {}
|
|
|
|
/**
|
|
* @throws BadRequestException
|
|
*/
|
|
public function execute(int $id): ?Post
|
|
{
|
|
if ($id <= 0) {
|
|
throw new BadRequestException('id must be positive');
|
|
}
|
|
|
|
return $this->postRepo->find($id);
|
|
}
|
|
}
|