feat(events): expose published events to storefront
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticketing\Event\Controllers;
|
||||||
|
|
||||||
|
use App\Domains\Core\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticketing\Event\Models\Event;
|
||||||
|
use App\Domains\Ticketing\Event\Requests\ListPublicEventsRequest;
|
||||||
|
use App\Domains\Ticketing\Event\Resources\PublicEventResource;
|
||||||
|
use App\Domains\Ticketing\Event\Services\PublicEventService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||||
|
|
||||||
|
class PublicEventController extends Controller
|
||||||
|
{
|
||||||
|
public function index(ListPublicEventsRequest $request, Tenant $tenant, PublicEventService $events): AnonymousResourceCollection
|
||||||
|
{
|
||||||
|
abort_unless($tenant->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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticketing\Event\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class ListPublicEventsRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'q' => ['sometimes', 'string', 'max:120'],
|
||||||
|
'page' => ['sometimes', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticketing\Event\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class PublicEventResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $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),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
36
app/Domains/Ticketing/Event/Services/PublicEventService.php
Normal file
36
app/Domains/Ticketing/Event/Services/PublicEventService.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticketing\Event\Services;
|
||||||
|
|
||||||
|
use App\Domains\Core\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticketing\Event\Models\Event;
|
||||||
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||||
|
|
||||||
|
class PublicEventService
|
||||||
|
{
|
||||||
|
public function list(Tenant $tenant, string $term, int $page): LengthAwarePaginator
|
||||||
|
{
|
||||||
|
$query = $tenant->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Domains\Ticketing\Event\Controllers\EventDateNoticeController;
|
use App\Domains\Ticketing\Event\Controllers\EventDateNoticeController;
|
||||||
|
use App\Domains\Ticketing\Event\Controllers\PublicEventController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
require __DIR__.'/adminapp.php';
|
require __DIR__.'/adminapp.php';
|
||||||
|
|
||||||
|
Route::prefix('tenants/{tenant:codigo}')->group(function (): void {
|
||||||
|
Route::get('events', [PublicEventController::class, 'index']);
|
||||||
|
Route::get('events/{event}', [PublicEventController::class, 'show']);
|
||||||
|
});
|
||||||
|
|
||||||
Route::middleware('auth:sanctum')->post(
|
Route::middleware('auth:sanctum')->post(
|
||||||
'tenants/{tenant:codigo}/event-date-notices/claim',
|
'tenants/{tenant:codigo}/event-date-notices/claim',
|
||||||
[EventDateNoticeController::class, 'claim'],
|
[EventDateNoticeController::class, 'claim'],
|
||||||
|
|||||||
Reference in New Issue
Block a user