fix: invalidate booking data caches after updating personal data
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Controller\Booking;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits\BookingDataTrait;
|
||||
use App\Entity\User;
|
||||
use App\Security\Crypt;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -15,17 +14,13 @@ use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
use function Symfony\Component\String\u;
|
||||
|
||||
class DownloadController extends AbstractController
|
||||
{
|
||||
use BookingDataTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
|
||||
@@ -94,7 +94,7 @@ class IndexController extends AbstractController
|
||||
}
|
||||
|
||||
// Fetch booking data for display (surcharges, canceled status, etc.)
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id);
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id, $user);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
@@ -166,7 +166,7 @@ class IndexController extends AbstractController
|
||||
}
|
||||
|
||||
// Fetch booking data to check for canceled status
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id);
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id, $user);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
@@ -269,7 +269,7 @@ class IndexController extends AbstractController
|
||||
$this->travelDataService->enrichWithFreshAvailabilities($bookingDto->travel);
|
||||
|
||||
// Fetch booking data and mutable data
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id);
|
||||
$bookingData = $this->dataLoader->fetchBookingData($email, $password, $id, $user);
|
||||
$mutableData = null !== $bookingData && !($bookingData instanceof Notification)
|
||||
? $this->travelDataService->getMutabilityData($bookingData->dateId)
|
||||
: null;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
|
||||
trait BookingDataTrait
|
||||
{
|
||||
public function fetchBookingData(string $email, string $password, int $id): Booking|Notification|null
|
||||
{
|
||||
$cacheKey = sprintf('bpn_booking_%d', $id);
|
||||
try {
|
||||
$bookingData = $this->cache->get($cacheKey, function (ItemInterface $item) use ($email, $password, $id) {
|
||||
$item->expiresAfter(300);
|
||||
|
||||
return $this->apiClient->getBooking($email, $password, $id);
|
||||
});
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$bookingData = null;
|
||||
}
|
||||
|
||||
return $bookingData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user