Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app-modules/events/lang/en/check_in.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
'check_in_outside_event_date_range' => 'Check-in date must be within the event date range.',
'already_checked_in_for_date' => 'This enrollment has already checked in for this date.',
'invalid_check_in_actor' => 'Manual check-in requires the organizer user id.',
'qr_token_not_found' => 'QR token not found or does not belong to this event.',
'qr_token_expired' => 'This QR token has expired.',
];
12 changes: 12 additions & 0 deletions app-modules/events/lang/en/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
'back_to_events' => 'Back to Events',
'confirm_presence' => 'Confirm Presence',
'confirm_presence_hint' => 'Confirm your attendance to this event.',
'confirm_presence_prompt' => 'Are you sure you want to enroll in this event?',
'confirm_presence_yes' => 'Yes, enroll me',
'confirm_presence_cancel' => 'Cancel',
'confirm_presence_success' => 'Your presence has been confirmed!',
'waitlist_success' => 'You have been added to the waitlist for this event.',
'enrollment_status_label' => 'Your enrollment status',
'enrolled_at' => 'Enrolled on :date',
'no_enrollments' => 'You are not enrolled in any events yet.',
'no_upcoming_events' => 'No upcoming events available.',
'my_qr_code' => 'My QR Code',
'qr_code_hint' => 'Present this QR code to the organizer for check-in.',
'copy_token' => 'Copy Token',
'token_copied' => 'Copied!',
'download_qr' => 'Download QR',
'checked_in_today' => 'Check-in done today',
'check_in_history' => 'Check-in History',
'check_in_history_date' => ':date',
'no_check_ins_yet' => 'No check-ins recorded yet.',
];
2 changes: 2 additions & 0 deletions app-modules/events/lang/pt_BR/check_in.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
'check_in_outside_event_date_range' => 'A data do check-in deve estar dentro do período do evento.',
'already_checked_in_for_date' => 'Esta inscrição já possui check-in para essa data.',
'invalid_check_in_actor' => 'Check-in manual exige o ID do usuário organizador.',
'qr_token_not_found' => 'Token QR não encontrado ou não pertence a este evento.',
'qr_token_expired' => 'Este token QR expirou.',
];
12 changes: 12 additions & 0 deletions app-modules/events/lang/pt_BR/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
'back_to_events' => 'Voltar para Eventos',
'confirm_presence' => 'Confirmar Presença',
'confirm_presence_hint' => 'Confirme sua presença neste evento.',
'confirm_presence_prompt' => 'Tem certeza que deseja se inscrever neste evento?',
'confirm_presence_yes' => 'Sim, me inscrever',
'confirm_presence_cancel' => 'Cancelar',
'confirm_presence_success' => 'Sua presença foi confirmada!',
'waitlist_success' => 'Você entrou na lista de espera deste evento.',
'enrollment_status_label' => 'Status da sua inscrição',
'enrolled_at' => 'Inscrito em :date',
'no_enrollments' => 'Você ainda não está inscrito em nenhum evento.',
'no_upcoming_events' => 'Nenhum evento disponível no momento.',
'my_qr_code' => 'Meu QR Code',
'qr_code_hint' => 'Apresente este QR code ao organizador para realizar o check-in.',
'copy_token' => 'Copiar Token',
'token_copied' => 'Copiado!',
'download_qr' => 'Baixar QR',
'checked_in_today' => 'Check-in feito hoje',
'check_in_history' => 'Histórico de Check-ins',
'check_in_history_date' => ':date',
'no_check_ins_yet' => 'Nenhum check-in registrado ainda.',
];
30 changes: 30 additions & 0 deletions app-modules/events/src/CheckIn/Actions/GenerateQrTokenAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace He4rt\Events\CheckIn\Actions;

use He4rt\Events\CheckIn\Models\QrToken;
use He4rt\Events\Enrollment\Models\Enrollment;
use Illuminate\Support\Str;

final readonly class GenerateQrTokenAction
{
public function handle(Enrollment $enrollment): QrToken
{
$existing = QrToken::query()->where('enrollment_id', $enrollment->id)->first();

if ($existing !== null) {
return $existing;
}

do {
$token = Str::random(64);
} while (QrToken::query()->where('token', $token)->exists());

return QrToken::query()->create([
'enrollment_id' => $enrollment->id,
'token' => $token,
]);
}
}
45 changes: 45 additions & 0 deletions app-modules/events/src/CheckIn/Actions/QrCheckInAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace He4rt\Events\CheckIn\Actions;

use He4rt\Events\CheckIn\DTOs\CheckInDTO;
use He4rt\Events\CheckIn\DTOs\QrCheckInDTO;
use He4rt\Events\CheckIn\Enums\CheckInMethod;
use He4rt\Events\CheckIn\Exceptions\CheckInException;
use He4rt\Events\CheckIn\Models\CheckIn;
use He4rt\Events\CheckIn\Models\QrToken;
use He4rt\Events\Enrollment\Enums\TriggeredBy;

final readonly class QrCheckInAction
{
public function handle(QrCheckInDTO $dto): CheckIn
{
$qrToken = QrToken::query()
->with('enrollment')
->where('token', $dto->token)
->first();

throw_unless(
$qrToken !== null && $qrToken->enrollment->event_id === $dto->event->id,
CheckInException::qrTokenNotFound(),
);

throw_if(
$qrToken->expires_at !== null && $qrToken->expires_at->isPast(),
CheckInException::qrTokenExpired(),
);

return resolve(CheckInAction::class)->handle(
new CheckInDTO(
enrollment: $qrToken->enrollment,
method: CheckInMethod::QrCode,
payload: ['token' => $dto->token],
eventDate: $dto->eventDate,
actorUserId: $dto->actorUserId,
triggeredBy: TriggeredBy::Admin,
),
);
}
}
22 changes: 22 additions & 0 deletions app-modules/events/src/CheckIn/DTOs/QrCheckInDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace He4rt\Events\CheckIn\DTOs;

use Carbon\CarbonInterface;
use He4rt\Events\CheckIn\Exceptions\CheckInException;
use He4rt\Events\Event\Models\Event;

final readonly class QrCheckInDTO
{
public function __construct(
public string $token,
public Event $event,
public CarbonInterface $eventDate,
public string $actorUserId,
) {
throw_if(blank($this->token), CheckInException::qrTokenNotFound());
throw_if(blank($this->actorUserId), CheckInException::invalidCheckInActor());
}
}
16 changes: 16 additions & 0 deletions app-modules/events/src/CheckIn/Exceptions/CheckInException.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ public static function invalidCheckInActor(): self
Response::HTTP_UNPROCESSABLE_ENTITY,
);
}

public static function qrTokenNotFound(): self
{
return new self(
__('events::check_in.qr_token_not_found'),
Response::HTTP_NOT_FOUND,
);
}

public static function qrTokenExpired(): self
{
return new self(
__('events::check_in.qr_token_expired'),
Response::HTTP_UNPROCESSABLE_ENTITY,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace He4rt\Events\CheckIn\Listeners;

use He4rt\Events\CheckIn\Actions\GenerateQrTokenAction;
use He4rt\Events\Enrollment\Events\EnrollmentConfirmed;
use He4rt\Events\Enrollment\Models\Enrollment;

final readonly class GenerateQrTokenOnConfirmed
{
public function handle(EnrollmentConfirmed $event): void
{
$enrollment = Enrollment::query()->findOrFail($event->enrollmentId);

resolve(GenerateQrTokenAction::class)->handle($enrollment);
}
}
5 changes: 5 additions & 0 deletions app-modules/events/src/EventsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace He4rt\Events;

use He4rt\Events\CheckIn\Listeners\GenerateQrTokenOnConfirmed;
use He4rt\Events\Enrollment\Events\EnrollmentConfirmed;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;

class EventsServiceProvider extends ServiceProvider
Expand All @@ -13,5 +16,7 @@ public function boot(): void
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'events');
$this->loadTranslationsFrom(__DIR__.'/../lang', 'events');

Event::listen(EnrollmentConfirmed::class, GenerateQrTokenOnConfirmed::class);
}
}
Loading