From f6e8716218f390cd5a5dbea71929fc43f3480697 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Fri, 18 Sep 2026 14:33:28 -0300 Subject: [PATCH] feat(events): expose published events to storefront --- .../Controllers/PublicEventController.php | 29 +++++++++++++++ .../Requests/ListPublicEventsRequest.php | 16 +++++++++ .../Event/Resources/PublicEventResource.php | 23 ++++++++++++ .../Event/Services/PublicEventService.php | 36 +++++++++++++++++++ app/Domains/Ticketing/Event/routes/api.php | 6 ++++ 5 files changed, 110 insertions(+) create mode 100644 app/Domains/Ticketing/Event/Controllers/PublicEventController.php create mode 100644 app/Domains/Ticketing/Event/Requests/ListPublicEventsRequest.php create mode 100644 app/Domains/Ticketing/Event/Resources/PublicEventResource.php create mode 100644 app/Domains/Ticketing/Event/Services/PublicEventService.php diff --git a/app/Domains/Ticketing/Event/Controllers/PublicEventController.php b/app/Domains/Ticketing/Event/Controllers/PublicEventController.php new file mode 100644 index 0000000..8346b89 --- /dev/null +++ b/app/Domains/Ticketing/Event/Controllers/PublicEventController.php @@ -0,0 +1,29 @@ +storefront_website_type_code === 'onticket_multi_event', 404); + + $term = trim((string) $request->validated('q', '')); + return PublicEventResource::collection($events->list($tenant, $term, (int) $request->validated('page', 1))); + } + + public function show(Tenant $tenant, Event $event, PublicEventService $events): PublicEventResource + { + abort_unless($tenant->storefront_website_type_code === 'onticket_multi_event', 404); + + return PublicEventResource::make($events->find($tenant, $event)); + } +} diff --git a/app/Domains/Ticketing/Event/Requests/ListPublicEventsRequest.php b/app/Domains/Ticketing/Event/Requests/ListPublicEventsRequest.php new file mode 100644 index 0000000..5431fb8 --- /dev/null +++ b/app/Domains/Ticketing/Event/Requests/ListPublicEventsRequest.php @@ -0,0 +1,16 @@ + ['sometimes', 'string', 'max:120'], + 'page' => ['sometimes', 'integer', 'min:1'], + ]; + } +} diff --git a/app/Domains/Ticketing/Event/Resources/PublicEventResource.php b/app/Domains/Ticketing/Event/Resources/PublicEventResource.php new file mode 100644 index 0000000..e5a5395 --- /dev/null +++ b/app/Domains/Ticketing/Event/Resources/PublicEventResource.php @@ -0,0 +1,23 @@ + $this->id, + 'title' => $this->title, + 'subtitle' => $this->subtitle, + 'description' => $this->description, + 'location' => $this->location, + 'date_text' => $this->date_text, + 'attachment_id' => $this->attachment_id, + 'image' => $this->attachment?->getTemporaryUrl(1440), + ]; + } +} diff --git a/app/Domains/Ticketing/Event/Services/PublicEventService.php b/app/Domains/Ticketing/Event/Services/PublicEventService.php new file mode 100644 index 0000000..7cd4da1 --- /dev/null +++ b/app/Domains/Ticketing/Event/Services/PublicEventService.php @@ -0,0 +1,36 @@ +events() + ->whereNotNull('published_at') + ->where('published_at', '<=', now()); + + if ($term !== '') { + $query->where(function ($query) use ($term): void { + $query->where('title', 'like', '%'.$term.'%') + ->orWhere('subtitle', 'like', '%'.$term.'%') + ->orWhere('location', 'like', '%'.$term.'%'); + }); + } + + return $query->with('attachment')->orderByDesc('published_at')->orderByDesc('id')->paginate(15, ['*'], 'page', $page); + } + + public function find(Tenant $tenant, Event $event): Event + { + abort_unless($event->tenant_code === $tenant->codigo + && $event->published_at !== null + && $event->published_at->isPast(), 404); + + return $event->load('attachment'); + } +} diff --git a/app/Domains/Ticketing/Event/routes/api.php b/app/Domains/Ticketing/Event/routes/api.php index bfe92e9..37eef63 100644 --- a/app/Domains/Ticketing/Event/routes/api.php +++ b/app/Domains/Ticketing/Event/routes/api.php @@ -1,10 +1,16 @@ group(function (): void { + Route::get('events', [PublicEventController::class, 'index']); + Route::get('events/{event}', [PublicEventController::class, 'show']); +}); + Route::middleware('auth:sanctum')->post( 'tenants/{tenant:codigo}/event-date-notices/claim', [EventDateNoticeController::class, 'claim'],