You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AudienceRegistration;
|
|
use App\Models\Competition;
|
|
use App\Support\BizDateTime;
|
|
use App\Support\SignupDisplay;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class PublicAudienceTicketController extends Controller
|
|
{
|
|
public function show(string $slug, string $ticketCode): JsonResponse
|
|
{
|
|
$competition = Competition::query()
|
|
->where('slug', $slug)
|
|
->where('published', true)
|
|
->first();
|
|
if ($competition === null) {
|
|
abort(404);
|
|
}
|
|
|
|
$code = trim($ticketCode);
|
|
if ($code === '' || strlen($code) > 64) {
|
|
abort(404);
|
|
}
|
|
|
|
$row = AudienceRegistration::query()
|
|
->with('session')
|
|
->where('competition_id', $competition->id)
|
|
->where('ticket_code', $code)
|
|
->first();
|
|
|
|
if ($row === null || ! $row->isApproved()) {
|
|
abort(404);
|
|
}
|
|
|
|
$session = $row->session;
|
|
|
|
return response()->json([
|
|
'session_name' => $session?->name,
|
|
'session_name_en' => $session?->name_en,
|
|
'event_date_text' => $row->approved_event_time_text,
|
|
'address' => $row->approved_event_address_text,
|
|
'name' => $row->name,
|
|
'ticket_code' => $row->ticket_code,
|
|
'checked_in_at' => BizDateTime::toIso8601($row->checked_in_at),
|
|
'signup_locale' => SignupDisplay::audienceLocale((int) $row->user_id, (int) $row->competition_id),
|
|
]);
|
|
}
|
|
}
|