diff --git a/app/Contribution/ContributionController.php b/app/Contribution/ContributionController.php index 5c30147d..12c51fc5 100644 --- a/app/Contribution/ContributionController.php +++ b/app/Contribution/ContributionController.php @@ -5,6 +5,7 @@ namespace App\Contribution; use App\Contribution\Documents\SolingenDocument; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; use Zoomyboy\Tex\BaseCompiler; use Zoomyboy\Tex\Tex; @@ -12,9 +13,22 @@ class ContributionController extends Controller { public function generate(Request $request): BaseCompiler { - /** @var class-string */ - $type = $request->query('type'); + $payload = json_decode(base64_decode($request->input('payload', '')), true); - return Tex::compile($type::fromRequest($request)); + $validated = Validator::make($payload, [ + 'dateFrom' => 'required|date|date_format:Y-m-d', + 'dateUntil' => 'required|date|date_format:Y-m-d', + 'country' => 'required|exists:countries,id', + 'eventName' => 'required|max:100', + 'members' => 'array', + 'members.*' => 'integer|exists:members,id', + 'type' => 'required|string', + 'zipLocation' => 'required|string', + ])->validate(); + + /** @var class-string */ + $type = $validated['type']; + + return Tex::compile($type::fromRequest($validated)); } } diff --git a/app/Contribution/Documents/DvDocument.php b/app/Contribution/Documents/DvDocument.php index c55736c7..5fd9b094 100644 --- a/app/Contribution/Documents/DvDocument.php +++ b/app/Contribution/Documents/DvDocument.php @@ -6,7 +6,6 @@ use App\Country; use App\Member\Member; use Carbon\Carbon; use Illuminate\Support\Collection; -use Illuminate\Http\Request; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; @@ -33,14 +32,17 @@ class DvDocument extends ContributionDocument .Carbon::parse($this->dateUntil)->format('d.m.Y'); } - public static function fromRequest(Request $request): self + /** + * @param array $request + */ + public static function fromRequest(array $request): self { return new self( - dateFrom: $request->dateFrom, - dateUntil: $request->dateUntil, - zipLocation: $request->zipLocation, - country: Country::where('id', $request->country)->firstOrFail(), - members: Member::whereIn('id', $request->members)->orderByRaw('lastname, firstname')->get()->toBase()->chunk(17), + dateFrom: $request['dateFrom'], + dateUntil: $request['dateUntil'], + zipLocation: $request['zipLocation'], + country: Country::where('id', $request['country'])->firstOrFail(), + members: Member::whereIn('id', $request['members'])->orderByRaw('lastname, firstname')->get()->toBase()->chunk(17), ); } diff --git a/app/Contribution/Documents/RemscheidDocument.php b/app/Contribution/Documents/RemscheidDocument.php index 81a1dd80..18460f89 100644 --- a/app/Contribution/Documents/RemscheidDocument.php +++ b/app/Contribution/Documents/RemscheidDocument.php @@ -6,7 +6,6 @@ use App\Country; use App\Member\Member; use Carbon\Carbon; use Illuminate\Support\Collection; -use Illuminate\Http\Request; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; @@ -38,15 +37,18 @@ class RemscheidDocument extends ContributionDocument return Carbon::parse($this->dateUntil)->format('d.m.Y'); } - public static function fromRequest(Request $request): self + /** + * @param array $request + */ + public static function fromRequest(array $request): self { - [$leaders, $children] = Member::whereIn('id', $request->members)->orderByRaw('lastname, firstname')->get()->partition(fn ($member) => $member->isLeader()); + [$leaders, $children] = Member::whereIn('id', $request['members'])->orderByRaw('lastname, firstname')->get()->partition(fn ($member) => $member->isLeader()); return new self( - dateFrom: $request->dateFrom, - dateUntil: $request->dateUntil, - zipLocation: $request->zipLocation, - country: Country::where('id', $request->country)->firstOrFail(), + dateFrom: $request['dateFrom'], + dateUntil: $request['dateUntil'], + zipLocation: $request['zipLocation'], + country: Country::where('id', $request['country'])->firstOrFail(), leaders: $leaders->values()->toBase()->chunk(6), children: $children->values()->toBase()->chunk(20), ); diff --git a/app/Contribution/Documents/SolingenDocument.php b/app/Contribution/Documents/SolingenDocument.php index 7bc8f8fe..5217a944 100644 --- a/app/Contribution/Documents/SolingenDocument.php +++ b/app/Contribution/Documents/SolingenDocument.php @@ -5,7 +5,6 @@ namespace App\Contribution\Documents; use App\Member\Member; use Carbon\Carbon; use Illuminate\Support\Collection; -use Illuminate\Http\Request; use Illuminate\Support\Str; use Zoomyboy\Tex\Engine; use Zoomyboy\Tex\Template; @@ -25,14 +24,17 @@ class SolingenDocument extends ContributionDocument ) { } - public static function fromRequest(Request $request): static + /** + * @param array $request + */ + public static function fromRequest(array $request): static { return new static( - dateFrom: $request->dateFrom, - dateUntil: $request->dateUntil, - zipLocation: $request->zipLocation, - members: $request->members, - eventName: $request->eventName, + dateFrom: $request['dateFrom'], + dateUntil: $request['dateUntil'], + zipLocation: $request['zipLocation'], + members: $request['members'], + eventName: $request['eventName'], ); } diff --git a/resources/js/views/contribution/VIndex.vue b/resources/js/views/contribution/VIndex.vue index 2bc36da4..11a94aef 100644 --- a/resources/js/views/contribution/VIndex.vue +++ b/resources/js/views/contribution/VIndex.vue @@ -1,32 +1,11 @@