chore: code cleanup
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\XmlLoader\TravelXmlLoader;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -16,10 +17,10 @@ use Symfony\Contracts\Cache\ItemInterface;
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelXmlLoader $travelDataLoader,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly Security $security,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -35,17 +36,22 @@ class IndexController extends AbstractController
|
||||
|
||||
// Cache bookings for a short ttl
|
||||
$cacheKey = sprintf('bpn_bookings_%s', sha1($bpnUser->getUserIdentifier()));
|
||||
$bookings = $this->cache->get($cacheKey, function (ItemInterface $item) use ($bpnUser) {
|
||||
$item->expiresAfter(300);
|
||||
try {
|
||||
$bookings = $this->cache->get($cacheKey, function (ItemInterface $item) use ($bpnUser) {
|
||||
$item->expiresAfter(300);
|
||||
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
$this->travelDataLoader->patchBookings($bookings);
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
$this->travelDataLoader->patchBookings($bookings);
|
||||
|
||||
return $bookings;
|
||||
});
|
||||
return $bookings;
|
||||
});
|
||||
$items = $bookings->getItems();
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$items = [];
|
||||
}
|
||||
|
||||
return $this->render('booking/index.html.twig', [
|
||||
'bookings' => $bookings->getItems(),
|
||||
'bookings' => $items,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user