Kurzanmeldungen
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Event\Controllers;
|
||||
|
||||
use App\Domains\Event\Actions\CertificateOfConductionCheck\CertificateOfConductionCheckCommand;
|
||||
use App\Domains\Event\Actions\CertificateOfConductionCheck\CertificateOfConductionCheckRequest;
|
||||
use App\Domains\Event\Actions\ShortSignUp\ShortSignUpCommand;
|
||||
use App\Domains\Event\Actions\ShortSignUp\ShortSignUpRequest;
|
||||
use App\Enumerations\FirstAidPermission;
|
||||
use App\Enumerations\SwimmingPermission;
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
use App\Providers\DoubleCheckEventRegistrationProvider;
|
||||
use App\Scopes\CommonController;
|
||||
use DateTime;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
/**
|
||||
* Nimmt die verkürzte Anmeldung entgegen. Öffentlich erreichbar, deshalb werden die Eingaben hier -- anders als
|
||||
* im langen Prozess -- validiert, bevor sie die Action erreichen.
|
||||
*/
|
||||
class ShortSignupController extends CommonController {
|
||||
public function __invoke(int $eventId, Request $request) : JsonResponse {
|
||||
$event = $this->events->getById($eventId, false);
|
||||
|
||||
if (!$event->registration_allowed || new DateTime() > $event->start_date) {
|
||||
return response()->json(['status' => 'closed'], 403);
|
||||
}
|
||||
|
||||
// Die Kurzanmeldung darf nicht als Abkürzung um den langen Prozess herum benutzt werden.
|
||||
if (!$event->short_registration) {
|
||||
return response()->json(['status' => 'closed'], 403);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'firstname' => 'required|string|max:255',
|
||||
'lastname' => 'required|string|max:255',
|
||||
'nickname' => 'nullable|string|max:255',
|
||||
'birthday' => 'required|date_format:Y-m-d|before:today',
|
||||
'email' => 'required|email|max:255',
|
||||
'phone' => 'required|string|max:255',
|
||||
// Gegen die teilnehmenden Stämme prüft der Command -- hier reicht die Typprüfung.
|
||||
'localGroup' => 'nullable|integer',
|
||||
'contactPerson' => 'nullable|string|max:255',
|
||||
'contactEmail' => 'nullable|email|max:255',
|
||||
'allergies' => 'nullable|string|max:255',
|
||||
'intolerances' => 'nullable|string|max:255',
|
||||
'firstAidPermission' => ['nullable', 'string', 'in:' . implode(',', FirstAidPermission::query()->pluck('slug')->toArray())],
|
||||
'swimmingPermission' => ['nullable', 'string', 'in:' . implode(',', SwimmingPermission::query()->pluck('slug')->toArray())],
|
||||
'foto' => 'array',
|
||||
'participationOptions' => 'array',
|
||||
'paymentMethod' => 'nullable|string',
|
||||
'paymentOptions' => 'array',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['status' => 'error', 'message' => $validator->errors()->first()], 422);
|
||||
}
|
||||
|
||||
$birthday = DateTime::createFromFormat('Y-m-d', $request->input('birthday'));
|
||||
|
||||
$doubleCheck = new DoubleCheckEventRegistrationProvider(
|
||||
$event,
|
||||
$request->input('firstname'),
|
||||
$request->input('lastname'),
|
||||
$request->input('email'),
|
||||
$birthday
|
||||
);
|
||||
|
||||
if ($doubleCheck->isRegistered()) {
|
||||
return response()->json(['status' => 'exists']);
|
||||
}
|
||||
|
||||
$foto = (array)$request->input('foto', []);
|
||||
|
||||
$shortSignUpRequest = new ShortSignUpRequest(
|
||||
event: $event,
|
||||
user_id: currentUser()?->id,
|
||||
firstname: $request->input('firstname'),
|
||||
lastname: $request->input('lastname'),
|
||||
nickname: $request->input('nickname'),
|
||||
birthday: $birthday,
|
||||
email: $request->input('email'),
|
||||
phone: $request->input('phone'),
|
||||
localGroupId: $request->input('localGroup') !== null ? (int)$request->input('localGroup') : null,
|
||||
contactPerson: $request->input('contactPerson') ?: null,
|
||||
contactEmail: $request->input('contactEmail') ?: null,
|
||||
allergies: $request->input('allergies') ?: null,
|
||||
intolerances: $request->input('intolerances') ?: null,
|
||||
firstAidPermission: $request->input('firstAidPermission') ?: null,
|
||||
swimmingPermission: $request->input('swimmingPermission') ?: null,
|
||||
foto_socialmedia: (bool)($foto['socialmedia'] ?? false),
|
||||
foto_print: (bool)($foto['print'] ?? false),
|
||||
foto_webseite: (bool)($foto['webseite'] ?? false),
|
||||
foto_partner: (bool)($foto['partner'] ?? false),
|
||||
foto_intern: (bool)($foto['intern'] ?? false),
|
||||
paymentMethod: $request->input('paymentMethod') ?: null,
|
||||
paymentOptions: (array)$request->input('paymentOptions', []),
|
||||
participationOptions: (array)$request->input('participationOptions', []),
|
||||
);
|
||||
|
||||
$shortSignUpResponse = new ShortSignUpCommand($shortSignUpRequest)->execute();
|
||||
|
||||
if (!$shortSignUpResponse->success) {
|
||||
return response()->json(['status' => 'error', 'message' => $shortSignUpResponse->message], 422);
|
||||
}
|
||||
|
||||
$participant = $shortSignUpResponse->participant;
|
||||
|
||||
$cocResponse = new CertificateOfConductionCheckCommand(
|
||||
new CertificateOfConductionCheckRequest($participant)
|
||||
)->execute();
|
||||
|
||||
$participant->efz_status = $cocResponse->status;
|
||||
$participant->save();
|
||||
|
||||
Mail::to($participant->email_1)->send(new EventSignUpSuccessfullMail(participant: $participant));
|
||||
|
||||
if ($participant->email_2 !== null) {
|
||||
Mail::to($participant->email_2)->send(new EventSignUpSuccessfullMail(participant: $participant));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'participant' => $participant->toResource()->toArray($request),
|
||||
'status' => 'success',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user