-
Notifications
You must be signed in to change notification settings - Fork 29
feat(events): rsvp enrollment end-to-end #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
73bd3b5
fix(admin): use status instead of active on event resource
BrunaDomingues be352a3
fix(events): assert event_date in check-in factory test
BrunaDomingues 64f54ee
feat(events): add RSVP enroll action and domain event
BrunaDomingues 5f27cc7
test(events): add EnrollUserAction coverage and factory states
BrunaDomingues 1cafa8a
feat(panel-app): add participant events and RSVP UI
BrunaDomingues 46b8df1
fix(admin): validate unique event slug per tenant
BrunaDomingues e3bfc4a
refactor(events): use EnrollUserDTO in enroll action
BrunaDomingues File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'already_enrolled' => 'You are already enrolled in this event.', | ||
| 'event_past' => 'This event has already started and is no longer accepting enrollments.', | ||
| 'event_not_active' => 'This event is not available for enrollment.', | ||
| 'invalid_enrollment_method' => 'This event does not accept RSVP enrollments.', | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'back_to_events' => 'Back to Events', | ||
| 'confirm_presence' => 'Confirm Presence', | ||
| 'confirm_presence_hint' => 'Confirm your attendance to this event.', | ||
| 'confirm_presence_success' => 'Your presence has been confirmed!', | ||
| '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.', | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'already_enrolled' => 'Você já está inscrito neste evento.', | ||
| 'event_past' => 'Este evento já começou e não aceita mais inscrições.', | ||
| 'event_not_active' => 'Este evento não está disponível para inscrição.', | ||
| 'invalid_enrollment_method' => 'Este evento não aceita inscrições via RSVP.', | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'back_to_events' => 'Voltar para Eventos', | ||
| 'confirm_presence' => 'Confirmar Presença', | ||
| 'confirm_presence_hint' => 'Confirme sua presença neste evento.', | ||
| 'confirm_presence_success' => 'Sua presença foi confirmada!', | ||
| '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.', | ||
| ]; |
92 changes: 92 additions & 0 deletions
92
app-modules/events/src/Enrollment/Actions/EnrollUserAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Events\Enrollment\Actions; | ||
|
|
||
| use He4rt\Events\Enrollment\DTOs\EnrollUserDTO; | ||
| use He4rt\Events\Enrollment\Enums\EnrollmentMethod; | ||
| use He4rt\Events\Enrollment\Enums\EnrollmentStatus; | ||
| use He4rt\Events\Enrollment\Enums\TriggeredBy; | ||
| use He4rt\Events\Enrollment\Events\EnrollmentConfirmed; | ||
| use He4rt\Events\Enrollment\Exceptions\EnrollmentException; | ||
| use He4rt\Events\Enrollment\Models\Enrollment; | ||
| use He4rt\Events\Enrollment\Models\EnrollmentTransition; | ||
| use He4rt\Events\Event\Enums\EventStatus; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class EnrollUserAction | ||
| { | ||
| public function handle(EnrollUserDTO $dto): Enrollment | ||
| { | ||
| $this->validate($dto); | ||
|
|
||
| return DB::transaction(function () use ($dto): Enrollment { | ||
| throw_if( | ||
| Enrollment::query() | ||
| ->where('event_id', $dto->eventId) | ||
| ->where('user_id', $dto->userId) | ||
| ->exists(), | ||
| EnrollmentException::alreadyEnrolled(), | ||
| ); | ||
|
|
||
| $now = now(); | ||
|
|
||
| $enrollment = new Enrollment([ | ||
| 'event_id' => $dto->eventId, | ||
| 'user_id' => $dto->userId, | ||
| 'enrolled_at' => $now, | ||
| 'confirmed_at' => $now, | ||
| ]); | ||
| $enrollment->status = EnrollmentStatus::Confirmed; | ||
| $enrollment->save(); | ||
|
|
||
| EnrollmentTransition::query()->create([ | ||
| 'enrollment_id' => $enrollment->id, | ||
| 'from_status' => null, | ||
| 'to_status' => EnrollmentStatus::Confirmed, | ||
| 'actor_id' => $dto->userId, | ||
| 'triggered_by' => TriggeredBy::User, | ||
| ]); | ||
|
|
||
| event(new EnrollmentConfirmed( | ||
| enrollmentId: $enrollment->id, | ||
| eventId: $dto->eventId, | ||
| userId: $dto->userId, | ||
| xpRewardRsvp: $dto->xpRewardOnConfirmed, | ||
| )); | ||
|
|
||
| return $enrollment->fresh(['event.enrollmentPolicy']); | ||
| }); | ||
| } | ||
|
|
||
| private function validate(EnrollUserDTO $dto): void | ||
| { | ||
| throw_unless( | ||
| $dto->eventStatus === EventStatus::Published, | ||
| EnrollmentException::eventNotActive(), | ||
| ); | ||
|
|
||
| throw_if( | ||
| $dto->eventStartsAt->lte(now()), | ||
| EnrollmentException::eventPast(), | ||
| ); | ||
|
|
||
| throw_unless( | ||
| in_array( | ||
| $dto->enrollmentMethod, | ||
| [EnrollmentMethod::Rsvp, EnrollmentMethod::RsvpCheckin], | ||
| strict: true, | ||
| ), | ||
| EnrollmentException::invalidEnrollmentMethod(), | ||
| ); | ||
|
|
||
| throw_if( | ||
| Enrollment::query() | ||
| ->where('event_id', $dto->eventId) | ||
| ->where('user_id', $dto->userId) | ||
| ->exists(), | ||
| EnrollmentException::alreadyEnrolled(), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Events\Enrollment\DTOs; | ||
|
|
||
| use Carbon\CarbonInterface; | ||
| use He4rt\Events\Enrollment\Enums\EnrollmentMethod; | ||
| use He4rt\Events\Event\Enums\EventStatus; | ||
| use He4rt\Events\Event\Models\Event; | ||
| use He4rt\Identity\User\Models\User; | ||
|
|
||
| final readonly class EnrollUserDTO | ||
| { | ||
| public function __construct( | ||
| public string $eventId, | ||
| public string $userId, | ||
| public EventStatus $eventStatus, | ||
| public CarbonInterface $eventStartsAt, | ||
| public ?EnrollmentMethod $enrollmentMethod, | ||
| public int $xpRewardOnConfirmed, | ||
| ) {} | ||
|
|
||
| public static function fromModels(Event $event, User $user): self | ||
| { | ||
| $event->loadMissing('enrollmentPolicy'); | ||
|
|
||
| return new self( | ||
| eventId: $event->id, | ||
| userId: $user->id, | ||
| eventStatus: $event->status, | ||
| eventStartsAt: $event->starts_at, | ||
| enrollmentMethod: $event->enrollmentPolicy?->enrollment_method, | ||
| xpRewardOnConfirmed: $event->enrollmentPolicy?->xp_on_confirmed ?? 0, | ||
| ); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
app-modules/events/src/Enrollment/Events/EnrollmentConfirmed.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Events\Enrollment\Events; | ||
|
|
||
| use Illuminate\Contracts\Events\ShouldDispatchAfterCommit; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| final readonly class EnrollmentConfirmed implements ShouldDispatchAfterCommit | ||
| { | ||
| use Dispatchable; | ||
|
|
||
| public function __construct( | ||
| public string $enrollmentId, | ||
| public string $eventId, | ||
| public string $userId, | ||
| public int $xpRewardRsvp, | ||
| ) {} | ||
| } |
43 changes: 43 additions & 0 deletions
43
app-modules/events/src/Enrollment/Exceptions/EnrollmentException.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Events\Enrollment\Exceptions; | ||
|
|
||
| use Exception; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| final class EnrollmentException extends Exception | ||
| { | ||
| public static function alreadyEnrolled(): self | ||
| { | ||
| return new self( | ||
| __('events::exceptions.already_enrolled'), | ||
| Response::HTTP_CONFLICT, | ||
| ); | ||
| } | ||
|
|
||
| public static function eventPast(): self | ||
| { | ||
| return new self( | ||
| __('events::exceptions.event_past'), | ||
| Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ); | ||
| } | ||
|
|
||
| public static function eventNotActive(): self | ||
| { | ||
| return new self( | ||
| __('events::exceptions.event_not_active'), | ||
| Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ); | ||
| } | ||
|
|
||
| public static function invalidEnrollmentMethod(): self | ||
| { | ||
| return new self( | ||
| __('events::exceptions.invalid_enrollment_method'), | ||
| Response::HTTP_UNPROCESSABLE_ENTITY, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.