feat(service): add post api

This commit is contained in:
2024-07-29 20:41:57 +02:00
parent 5029dfcc37
commit 07d7a3025a
3 changed files with 113 additions and 2 deletions

View File

@@ -4,7 +4,32 @@ declare(strict_types=1);
namespace App\Service\Remote;
use App\Entity\Remote\Brilo\Posts\Post;
use App\Entity\Remote\Brilo\Users\User;
use Psr\Log\LoggerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class BriloApiPosts
{
use BriloApiFetchTrait;
public function __construct(
protected readonly HttpClientInterface $httpClient,
protected readonly LoggerInterface $logger,
protected readonly SerializerInterface $serializer,
protected readonly int $retryCount = 3,
protected readonly int $sleepTimeS = 1,
) {
}
/**
* Fetch all posts from Brilo API and return them as an array of Post entities.
* @return Post[]
* @throws \Exception
*/
public function getPosts(): array
{
return $this->fetchApiResponse('https://jsonplaceholder.typicode.com/posts', Post::class);
}
}

View File

@@ -25,6 +25,7 @@ final class BriloApiUsers
}
/**
* Fetch all users from the Brilo API and return them as an array of User entities.
* @return User[]
* @throws \Exception
*/