feat: fetch additional content from cms via api

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent fc05350ae4
commit a8c0a1aa61
18 changed files with 107 additions and 124 deletions
+6 -24
View File
@@ -7,36 +7,18 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class CmsDataService
{
public const MODE_PRODUCT = 'product';
public const MODE_HOTEL = 'hotel';
public function __construct(private readonly HttpClientInterface $httpClient)
public function __construct(private readonly HttpClientInterface $httpClient, private readonly string $apiKey)
{
}
public function getProductDetails(string $code): array
public function getProductDetails(string $productCode, ?string $hotelCode = null): array
{
return $this->makeApiCall(static::MODE_PRODUCT, $code);
}
public function getHotelDetails(string $code): array
{
return $this->makeApiCall(static::MODE_HOTEL, $code);
}
public function makeApiCall(string $mode, string $code): array
{
if (false === in_array($mode, [self::MODE_PRODUCT, self::MODE_HOTEL])) {
throw new \InvalidArgumentException('Invalid mode provided');
}
try {
$request = $this->httpClient->request('GET', '/', [
$request = $this->httpClient->request('GET', 'api/product', [
'query' => [
'type' => 1720,
'tx_epproducts_api[code]' => $code,
'tx_epproducts_api[action]' => $mode,
'tx_epproducts_api[controller]' => 'Api',
'product' => $productCode,
'hotel' => $hotelCode,
'key' => $this->apiKey,
],
]);
} catch (ExceptionInterface $e) {