Files
mareike/app/Domains/Event/Controllers/DetailsController.php

119 lines
5.4 KiB
PHP

<?php
namespace App\Domains\Event\Controllers;
use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesCommand;
use App\Domains\Event\Actions\SetParticipationFees\SetParticipationFeesRequest;
use App\Domains\Event\Actions\UpdateEvent\UpdateEventCommand;
use App\Domains\Event\Actions\UpdateEvent\UpdateEventRequest;
use App\Domains\Event\Actions\UpdateManagers\UpdateManagersCommand;
use App\Domains\Event\Actions\UpdateManagers\UpdateManagersRequest;
use App\Enumerations\ParticipationFeeType;
use App\Enumerations\ParticipationType;
use App\Providers\InertiaProvider;
use App\Resources\EventResource;
use App\Scopes\CommonController;
use App\ValueObjects\Amount;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DetailsController extends CommonController {
public function __invoke(int $eventId) {
$event = $this->events->getById($eventId);
return new InertiaProvider('Event/Details', ['event' => $event])->render();
}
public function summary(int $eventId) : JsonResponse {
$event = $this->events->getById($eventId);
return response()->json(['event' => new EventResource($event)->toArray()]);
}
public function updateCommonSettings(int $eventId, Request $request) : JsonResponse {
$event = $this->events->getById($eventId);
$earlyBirdEnd = \DateTime::createFromFormat('Y-m-d', $request->input('earlyBirdEnd'));
$registrationFinalEnd = \DateTime::createFromFormat('Y-m-d', $request->input('registrationFinalEnd'));
$flatSupport = Amount::fromString($request->input('flatSupport'));
$supportPerPerson = Amount::fromString($request->input('supportPerson'));
$contributinLocalGroups = $request->input('contributingLocalGroups');
$eatingHabits = $request->input('eatingHabits');
$eventUpdateRequest = new UpdateEventRequest(
$event,
$request->input('eventName'),
$request->input('eventLocation'),
$request->input('postalCode'),
$request->input('email'),
$earlyBirdEnd,
$registrationFinalEnd,
$request->input('alcoholicsAge'),
$request->input('sendWeeklyReports'),
$request->input('registrationAllowed'),
$flatSupport,
$supportPerPerson,
$contributinLocalGroups,
$eatingHabits
);
$eventUpdateCommand = new UpdateEventCommand($eventUpdateRequest);
$response = $eventUpdateCommand->execute();
return response()->json(['status' => $response->success ? 'success' : 'error']);
}
public function updateEventManagers(int $eventId, Request $request) : JsonResponse {
$event = $this->events->getById($eventId);
$updateEventManagersRequest = new UpdateManagersRequest($event, $request->input('selectedManagers'));
$updateEventManagersCommand = new UpdateManagersCommand($updateEventManagersRequest);
$response = $updateEventManagersCommand->execute();
return response()->json(['status' => $response->success ? 'success' : 'error']);
}
public function updateParticipationFees(int $eventId, Request $request) : JsonResponse {
$event = $this->events->getById($eventId);
$participationFeeFirst = [
'type' => ParticipationType::PARTICIPATION_TYPE_PARTICIPANT,
'name' => 'Teilnehmer',
'description' => $request->input('pft_1_description'),
'amount' => Amount::fromString($request->input('pft_1_amount'))
];
$participationFeeRequest = new SetParticipationFeesRequest($event, $participationFeeFirst);
if ($request->input('pft_2_active')) {
$participationFeeRequest->participationFeeSecond = [
'type' => ParticipationType::PARTICIPATION_TYPE_TEAM,
'name' => $event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_FIXED ? 'Kernteam' : 'Solidaritätsbeitrag',
'description' => $request->input('pft_2_description'),
'amount' => Amount::fromString($request->input('pft_2_amount'))
];
}
if ($request->input('pft_3_active')) {
$participationFeeRequest->participationFeeThird = [
'type' => ParticipationType::PARTICIPATION_TYPE_VOLUNTEER,
'name' => $event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_FIXED ? 'Unterstützende' : 'Reduzierter Beitrag',
'description' => $event->participation_fee_type !== ParticipationFeeType::PARTICIPATION_FEE_TYPE_SOLIDARITY ? $request->input('pft_3_description') : 'Nach Verfügbarkeit',
'amount' => Amount::fromString($request->input('pft_3_amount'))
];
}
if ($request->input('pft_4_active') && $event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_FIXED) {
$participationFeeRequest->participationFeeFourth = [
'type' => ParticipationType::PARTICIPATION_TYPE_OTHER,
'name' => 'Sonstige',
'description' => $request->input('pft_4_description'),
'amount' => Amount::fromString($request->input('pft_4_amount'))
];
}
$participationFeeCommand = new SetParticipationFeesCommand($participationFeeRequest);
$response = $participationFeeCommand->excetute();
return response()->json(['status' => $response->success ? 'success' : 'error']);
}
}