WIP: Implement closer BPN integration

This commit is contained in:
Björn Fromme
2023-10-06 18:14:05 +02:00
parent bea5edd615
commit 25a90b04aa
23 changed files with 628 additions and 224 deletions
@@ -1,39 +0,0 @@
<?php
namespace App\BusProNet\DataProvider;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\Product;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
class ProductDataProvider
{
public function __construct(private readonly ApiClient $apiClient, private readonly CacheInterface $cache)
{}
public function getAll(): array
{
try {
$products = $this->cache->get('bpn_products', function (ItemInterface $item) {
$item->expiresAfter(3600);
return $this
->apiClient
->getBaseData(ApiClient::TYPE_PRODUCTS)
->getItems()
;
});
} catch (ApiClientException $e) {
$products = [];
}
return $products;
}
public function get(int $busProId): ?Product
{
return $this->getAll()[$busProId] ?? null;
}
}