Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.3 KB
Raw Blame
<?php

declare(strict_types=1);

namespace HiEvents\Enterprise\Seating\Http\Actions;

use HiEvents\Enterprise\Seating\Exceptions\InvalidSeatMapLayoutException;
use HiEvents\Enterprise\Seating\Exceptions\SeatMapChangeConflictException;
use HiEvents\Enterprise\Seating\Http\Request\UpsertSeatMapRequest;
use HiEvents\Enterprise\Seating\Resources\SeatMapResource;
use HiEvents\Enterprise\Seating\Services\Application\Handlers\UpdateSeatMapHandler;
use HiEvents\Http\ResponseCodes;
use Illuminate\Http\JsonResponse;

class UpdateSeatMapAction extends BaseSeatMapAction
{
    public function __construct(
        private readonly UpdateSeatMapHandler $handler,
    ) {}

    public function __invoke(int $organizerId, int $seatMapId, UpsertSeatMapRequest $request): JsonResponse
    {
        $this->authorizeSeatMapSetup($organizerId);

        try {
            $seatMap = $this->handler->handle($seatMapId, $this->upsertDtoFromRequest($organizerId, $request));
        } catch (InvalidSeatMapLayoutException $exception) {
            throw $this->layoutValidationException($exception);
        } catch (SeatMapChangeConflictException $exception) {
            return $this->errorResponse($exception->getMessage(), ResponseCodes::HTTP_CONFLICT);
        }

        return $this->resourceResponse(resource: SeatMapResource::class, data: $seatMap);
    }
}