wip: implement admin crud
This commit is contained in:
1 parent
13491f346d
commit
b075e3ecfc
78 files changed
+2555
-101
No files matched your search
@@ -2,13 +2,18 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class CmsDataProvider
|
||||
{
|
||||
public function __construct(private readonly HttpClientInterface $httpClient, private readonly string $apiKey)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly HttpClientInterface $httpClient,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly string $apiKey,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,33 +32,98 @@ class CmsDataProvider
|
||||
return $result['hotel']['images'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function getHotelImages(string $hotelCode): ?array
|
||||
{
|
||||
$result = $this->getHotelDetails($hotelCode);
|
||||
|
||||
if (true === isset($result['success']) && false === $result['success']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result['images'] ?? null;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getHotelDetails(string $hotelCode): array
|
||||
{
|
||||
return $this->cache->get(
|
||||
sprintf('cms_hotel_%s', $hotelCode),
|
||||
function (ItemInterface $item) use ($hotelCode): array {
|
||||
$item->expiresAfter(3600);
|
||||
|
||||
try {
|
||||
$request = $this->httpClient->request('GET', 'api/hotel', [
|
||||
'query' => [
|
||||
'hotel' => $hotelCode,
|
||||
'key' => $this->apiKey,
|
||||
],
|
||||
]);
|
||||
} catch (ExceptionInterface $e) {
|
||||
$item->expiresAfter(0);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $request->toArray();
|
||||
} catch (ExceptionInterface $e) {
|
||||
$item->expiresAfter(0);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function getProductDetails(string $productCode, ?string $hotelCode = null): array
|
||||
{
|
||||
try {
|
||||
$request = $this->httpClient->request('GET', 'api/product', [
|
||||
'query' => [
|
||||
'product' => $productCode,
|
||||
'hotel' => $hotelCode,
|
||||
'key' => $this->apiKey,
|
||||
],
|
||||
]);
|
||||
} catch (ExceptionInterface $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
return $this->cache->get(
|
||||
sprintf('cms_product_%s_%s', $productCode, $hotelCode ?? ''),
|
||||
function (ItemInterface $item) use ($productCode, $hotelCode): array {
|
||||
$item->expiresAfter(3600);
|
||||
|
||||
try {
|
||||
$data = $request->toArray();
|
||||
} catch (ExceptionInterface $e) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
try {
|
||||
$request = $this->httpClient->request('GET', 'api/product', [
|
||||
'query' => [
|
||||
'product' => $productCode,
|
||||
'hotel' => $hotelCode,
|
||||
'key' => $this->apiKey,
|
||||
],
|
||||
]);
|
||||
} catch (ExceptionInterface $e) {
|
||||
$item->expiresAfter(0);
|
||||
|
||||
return $data;
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $request->toArray();
|
||||
} catch (ExceptionInterface $e) {
|
||||
$item->expiresAfter(0);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user