- Introduced Event and EventDate models with relationships to Tenant and CatalogItem. - Added active_event_id to Tenant model to track the currently active event. - Updated TenantResource to include active event details in the response. - Enhanced Ticket model to link to CatalogItem and Variant, allowing for event-specific ticketing. - Implemented migrations to create events and link them to catalog items and variants. - Updated seeders to populate events and their associated dates for the Fiesta Futbol Infantil tenant. - Modified Ticket generation logic to respect event dates over standard ticket dates. - Added tests for event and ticket functionalities, ensuring proper relationships and date handling.
50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticket\Controllers;
|
|
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use App\Domains\Ticket\Exceptions\TicketNotAvailableException;
|
|
use App\Domains\Ticket\Models\Ticket;
|
|
use App\Domains\Ticket\Requests\DownloadTicketsPdfRequest;
|
|
use App\Domains\Ticket\Resources\TicketResource;
|
|
use App\Domains\Ticket\Services\TicketPdfService;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class TicketController extends Controller
|
|
{
|
|
public function __construct(private readonly TicketPdfService $ticketPdfService) {}
|
|
|
|
public function index(Request $request, Tenant $tenant): JsonResponse
|
|
{
|
|
$tickets = Ticket::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('user_id', $request->user()->getKey())
|
|
->with('sourceVariant.eventDate', 'sourceVariant.catalogItem')
|
|
->orderByDesc('id')
|
|
->get();
|
|
|
|
return TicketResource::collection($tickets)->response();
|
|
}
|
|
|
|
public function downloadPdf(DownloadTicketsPdfRequest $request, Tenant $tenant): Response
|
|
{
|
|
$ticketIds = $request->validated('ticket_ids');
|
|
$tickets = Ticket::query()
|
|
->where('tenant_code', $tenant->codigo)
|
|
->where('user_id', $request->user()->getKey())
|
|
->whereIn('id', $ticketIds)
|
|
->with('sourceVariant.eventDate', 'sourceVariant.catalogItem')
|
|
->orderByDesc('id')
|
|
->get();
|
|
|
|
if ($tickets->count() !== count($ticketIds)) {
|
|
throw new TicketNotAvailableException(__('api.ticket.not_available'));
|
|
}
|
|
|
|
return $this->ticketPdfService->download($tenant, $tickets);
|
|
}
|
|
}
|