feat(desfile): enhance entry reservation form and service with tenant-specific data

This commit is contained in:
2026-09-23 16:55:35 -03:00
parent 5e78f2bb1e
commit 3671b95a83
6 changed files with 170 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ namespace App\Shared\Forms\Controllers\AdminApp;
use App\Http\Controllers\Controller;
use App\Shared\Forms\Resources\DesfileEntryReservationFormResource;
use App\Shared\Forms\Services\DesfileEntryReservationFormService;
use Illuminate\Http\Request;
class DesfileEntryReservationFormController extends Controller
{
@@ -12,8 +13,10 @@ class DesfileEntryReservationFormController extends Controller
private readonly DesfileEntryReservationFormService $formService,
) {}
public function __invoke(): DesfileEntryReservationFormResource
public function __invoke(Request $request): DesfileEntryReservationFormResource
{
return DesfileEntryReservationFormResource::make($this->formService->get());
return DesfileEntryReservationFormResource::make(
$this->formService->get($request->user()->tenant()->firstOrFail()),
);
}
}

View File

@@ -12,6 +12,8 @@ class DesfileEntryReservationFormResource extends JsonResource
{
return [
'payment_types' => $this->resource['payment_types'],
'fields' => $this->resource['fields'],
'variants' => $this->resource['variants'],
];
}
}

View File

@@ -2,15 +2,48 @@
namespace App\Shared\Forms\Services;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Variant;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
class DesfileEntryReservationFormService
{
/** @return array{payment_types: list<array{value: string, label: string}>} */
public function get(): array
/** @return array<string, mixed> */
public function get(Tenant $tenant): array
{
$entry = CatalogItem::query()->forTenantCatalog($tenant)->where('slug', 'entrada')
->with([
'variants' => fn ($query) => $query->orderBy('id'),
'variants.inventory',
'variants.definitions.itemAttribute.attribute',
'variants.eventDates',
'variants.eventDate',
])->first();
$variants = $entry?->visibleVariants()
->map(function (Variant $variant): array {
$values = $variant->selectionValues();
return [
'id' => $variant->id,
'tipo' => (string) $values->get('tipo'),
'sector' => (string) $values->get('sector'),
'fila' => (string) $values->get('fila'),
'asiento' => (string) $values->get('asiento'),
'price' => $variant->getPrice(),
];
})->values() ?? collect();
return [
'payment_types' => EntryReservationPaymentType::options(),
'fields' => collect(['tipo' => 'Tipo', 'sector' => 'Sector', 'fila' => 'Fila', 'asiento' => 'Asiento'])
->map(fn (string $label, string $key): array => [
'key' => $key,
'label' => $label,
'options' => $variants->pluck($key)->unique()->sort(SORT_NATURAL)->values()
->map(fn (string $value): array => ['value' => $value, 'label' => $value])->all(),
])->values()->all(),
'variants' => $variants->all(),
];
}
}