refactor: split buspro ApiClient into domain clients
This commit is contained in:
1 parent
0a55544ca8
commit
b755a6f43e
52 files changed
+805
-695
No files matched your search
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\BookingClient;
|
||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Notification;
|
||||
@@ -33,7 +33,7 @@ class BookingEditDataLoader
|
||||
private array $droppedDraftServiceLabels = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly BookingClient $bookingClient,
|
||||
private readonly BookingDataProcessor $bookingDataProcessor,
|
||||
private readonly BookingSessionManager $bookingSessionService,
|
||||
private readonly BookingChangeTracker $fingerprintService,
|
||||
@@ -226,7 +226,7 @@ class BookingEditDataLoader
|
||||
$item->expiresAfter(300);
|
||||
$item->tag([$userTag]);
|
||||
|
||||
return $this->apiClient->getBooking($email, $password, $bookingId);
|
||||
return $this->bookingClient->getBooking($email, $password, $bookingId);
|
||||
});
|
||||
} catch (InvalidArgumentException) {
|
||||
return null;
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\BookingClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\TimeoutException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
@@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
class BookingEditSubmitter
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly BookingClient $bookingClient,
|
||||
private readonly BookingEditDataLoader $dataLoader,
|
||||
private readonly BookingEditDraftManager $draftService,
|
||||
private readonly TravelDataProvider $travelDataService,
|
||||
@@ -90,7 +90,7 @@ class BookingEditSubmitter
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->updateBooking($bookingDto, true);
|
||||
$response = $this->bookingClient->updateBooking($bookingDto, true);
|
||||
if ($response instanceof Notification) {
|
||||
$this->logger->error('Booking update not successful', [
|
||||
'email' => $email,
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\AccountClient;
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
@@ -26,7 +26,7 @@ class ParticipantDataPrefiller
|
||||
public const TOKEN = '#KUN#';
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly AccountClient $accountClient,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
@@ -90,7 +90,7 @@ class ParticipantDataPrefiller
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
$email = $user->getEmail();
|
||||
|
||||
$result = $this->apiClient->getPersonalData($email, $password);
|
||||
$result = $this->accountClient->getPersonalData($email, $password);
|
||||
|
||||
if ($result instanceof Notification) {
|
||||
$this->logger->warning('Failed to fetch personal data for prepopulation', [
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\TravelClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Notification;
|
||||
@@ -38,7 +38,7 @@ class TravelDataProvider
|
||||
|
||||
public function __construct(
|
||||
private readonly TravelLoader $travelLoader,
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelClient $travelClient,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly TravelSnapshotManager $travelSnapshotService,
|
||||
@@ -183,7 +183,7 @@ class TravelDataProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $this->apiClient->getTravelData($productId, $hotelId);
|
||||
$result = $this->travelClient->getTravelData($productId, $hotelId);
|
||||
|
||||
if (!$result instanceof Travel) {
|
||||
$this->logger->debug('API returned non-travel result', [
|
||||
@@ -522,7 +522,7 @@ class TravelDataProvider
|
||||
private function fetchMutabilityData(int $dateId): ?BaseData
|
||||
{
|
||||
try {
|
||||
$mutableData = $this->apiClient->getMutableData($dateId);
|
||||
$mutableData = $this->travelClient->getMutableData($dateId);
|
||||
|
||||
if ($mutableData instanceof Notification) {
|
||||
$this->logger->warning('API returned notification for mutability data', [
|
||||
@@ -552,7 +552,7 @@ class TravelDataProvider
|
||||
private function fetchAvailabilityData(int $dateId): ?ServiceAvailabilityResponse
|
||||
{
|
||||
try {
|
||||
$availabilities = $this->apiClient->getAvailabilities($dateId);
|
||||
$availabilities = $this->travelClient->getAvailabilities($dateId);
|
||||
|
||||
if ($availabilities instanceof Notification) {
|
||||
$this->logger->warning('API returned notification for availability data', [
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\TravelClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\ExtendedAvailability;
|
||||
use App\BusProNet\Model\ExtendedServiceAvailabilityResponse;
|
||||
@@ -32,7 +32,7 @@ class TravelSnapshotManager
|
||||
public function __construct(
|
||||
private readonly TravelSnapshotRepository $snapshotRepository,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly TravelClient $travelClient,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly int $retentionBufferDays = 14,
|
||||
@@ -210,7 +210,7 @@ class TravelSnapshotManager
|
||||
if (false === array_key_exists($dateId, $extendedResponseByDateId)) {
|
||||
$response = null;
|
||||
try {
|
||||
$response = $this->apiClient->getAvailabilitiesExtended($dateId);
|
||||
$response = $this->travelClient->getAvailabilitiesExtended($dateId);
|
||||
} catch (ApiClientException $e) {
|
||||
$extendedResponseByDateId[$dateId] = null;
|
||||
$this->logger->warning('Failed to fetch extended availability', [
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\VoucherClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||
@@ -27,7 +27,7 @@ class VoucherTemplateProvider
|
||||
private const string PAYMENT_METHOD_CACHE_KEY = 'voucher_shop.payment_method';
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly VoucherClient $voucherClient,
|
||||
private readonly TagAwareCacheInterface $cache,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
@@ -42,7 +42,7 @@ class VoucherTemplateProvider
|
||||
$item->expiresAfter(self::CACHE_TTL);
|
||||
$item->tag([self::CACHE_TAG]);
|
||||
|
||||
$result = $this->request(fn () => $this->apiClient->getVoucherTemplates(), 'templates');
|
||||
$result = $this->request(fn () => $this->voucherClient->getVoucherTemplates(), 'templates');
|
||||
if ([] === $result->templates) {
|
||||
$this->logger->error('BusPro offers no voucher templates for sale');
|
||||
|
||||
@@ -65,7 +65,7 @@ class VoucherTemplateProvider
|
||||
$item->tag([self::CACHE_TAG]);
|
||||
|
||||
/** @var list<VoucherPaymentMethod> $paymentMethods */
|
||||
$paymentMethods = $this->request(fn () => $this->apiClient->getVoucherPaymentMethods(), 'payment methods');
|
||||
$paymentMethods = $this->request(fn () => $this->voucherClient->getVoucherPaymentMethods(), 'payment methods');
|
||||
foreach ($paymentMethods as $paymentMethod) {
|
||||
if ($paymentMethod->isTransfer()) {
|
||||
return $paymentMethod;
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\VoucherClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PromoVoucherValidationResult;
|
||||
@@ -18,7 +18,7 @@ class VoucherValidator
|
||||
private const CACHE_TTL = 900; // 15 minutes
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly VoucherClient $voucherClient,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
@@ -34,7 +34,7 @@ class VoucherValidator
|
||||
$item->expiresAfter(self::CACHE_TTL);
|
||||
|
||||
try {
|
||||
$result = $this->apiClient->validatePurchaseVoucher($redemptionCode);
|
||||
$result = $this->voucherClient->validatePurchaseVoucher($redemptionCode);
|
||||
|
||||
if ($result instanceof Notification) {
|
||||
return new PurchaseVoucherValidationResult(
|
||||
@@ -89,7 +89,7 @@ class VoucherValidator
|
||||
$item->expiresAfter(self::CACHE_TTL);
|
||||
|
||||
try {
|
||||
$result = $this->apiClient->validatePromoVoucher($promoCode, $travelId, $participantPrice);
|
||||
$result = $this->voucherClient->validatePromoVoucher($promoCode, $travelId, $participantPrice);
|
||||
|
||||
if ($result instanceof Notification) {
|
||||
return new PromoVoucherValidationResult(
|
||||
|
||||
Reference in new issue
Block a user