wip: booking process, refactoring

This commit is contained in:
Björn Fromme committed 2025-07-16 19:37:17 +02:00
1 parent 47faa6b08e
commit eecea0abd1
43 files changed
+2269 -366

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Controller\Api;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use Psr\Cache\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
#[Route('/api')]
#[IsGranted('ROLE_OAUTH2_API')]
class ProductController extends AbstractController
{
public function __construct(
private readonly ApiClient $apiClient,
private readonly CacheInterface $cache,
) {
}
#[Route(path: '/products', name: 'api_products')]
public function index(): JsonResponse
{
try {
$products = $this->cache->get('api_products', function (ItemInterface $item) {
$item->expiresAfter(3600); // 1 hour cache
return $this->apiClient->getProducts();
});
return $this->json($products);
} catch (InvalidArgumentException|ApiClientException $e) {
return $this->json(['error' => $e->getMessage(), 'type' => 'api_error']);
}
}
}