<?php
declare(strict_types=1);
namespace VehicleIngestBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route;
use VehicleIngestBundle\Message\IngestLeasingMessage;
use VehicleIngestBundle\Service\ErrorResponseFactory;
/**
* Accept-and-enqueue only: this controller's job is purely to satisfy the mobile.de seller-api
* contract (200 on PUT, 204 on DELETE) so the automedia exporter doesn't error on the leasing
* sub-resource, and to hand the payload off to Messenger. The actual persistence (mapping onto
* the vehicle's `Leasing` objectbrick + filterRate) happens asynchronously in
* IngestLeasingMessageHandler/LeasingMapper (Plan 3, Task 5) - kept off the request path so a
* slow/delayed leasing push never blocks the automedia exporter's ack.
*/
class LeasingController extends FrontendController
{
public function __construct(
private MessageBusInterface $bus,
private ErrorResponseFactory $errors,
) {
}
/**
* @Route("/seller-api/sellers/{sellerId}/ads/{adId}/leasing", name="seller_api_ad_leasing_put", methods={"PUT"}, requirements={"adId"="\d+"})
*/
public function putLeasingAction(Request $request, string $adId): Response
{
$data = json_decode($request->getContent(), true);
if (!is_array($data)) {
return $this->errors->keyed('body');
}
$this->bus->dispatch(new IngestLeasingMessage($adId, 'upsert', $data));
return new Response('', Response::HTTP_OK);
}
/**
* @Route("/seller-api/sellers/{sellerId}/ads/{adId}/leasing", name="seller_api_ad_leasing_delete", methods={"DELETE"}, requirements={"adId"="\d+"})
*/
public function deleteLeasingAction(string $adId): Response
{
$this->bus->dispatch(new IngestLeasingMessage($adId, 'delete', null));
return new Response('', Response::HTTP_NO_CONTENT);
}
}