diff --git a/app/Contribution/Actions/FormAction.php b/app/Contribution/Actions/FormAction.php deleted file mode 100644 index e7ef6f76..00000000 --- a/app/Contribution/Actions/FormAction.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace App\Contribution\Actions; - -use App\Contribution\ContributionFactory; -use App\Country; -use Inertia\Inertia; -use Inertia\Response; -use Lorisleiva\Actions\Concerns\AsAction; - -class FormAction -{ - use AsAction; - - /** - * @return array<string, mixed> - */ - public function handle(): array - { - return [ - 'countries' => Country::select('name', 'id')->get(), - 'data' => [ - 'country' => Country::firstWhere('name', 'Deutschland')->id, - ], - 'compilers' => app(ContributionFactory::class)->compilerSelect(), - ]; - } - - public function asController(): Response - { - session()->put('menu', 'contribution'); - session()->put('title', 'Zuschüsse'); - - return Inertia::render('contribution/VIndex', $this->handle()); - } -} diff --git a/app/Contribution/Actions/GenerateAction.php b/app/Contribution/Actions/GenerateAction.php deleted file mode 100644 index f26caa60..00000000 --- a/app/Contribution/Actions/GenerateAction.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace App\Contribution\Actions; - -use App\Contribution\ContributionFactory; -use App\Contribution\Documents\ContributionDocument; -use App\Rules\JsonBase64Rule; -use Illuminate\Support\Facades\Validator; -use Lorisleiva\Actions\ActionRequest; -use Lorisleiva\Actions\Concerns\AsAction; -use Zoomyboy\Tex\BaseCompiler; -use Zoomyboy\Tex\Tex; - -class GenerateAction -{ - use AsAction; - - /** - * @param class-string<ContributionDocument> $document - * @param array<string, mixed> $payload - */ - public function handle(string $document, array $payload): BaseCompiler - { - return Tex::compile($document::fromRequest($payload)); - } - - public function asController(ActionRequest $request): BaseCompiler - { - $payload = $this->payload($request); - $type = data_get($payload, 'type'); - ValidateAction::validateType($type); - Validator::make($payload, app(ContributionFactory::class)->rules($type))->validate(); - - return $this->handle($type, $payload); - } - - /** - * @return array<string, mixed> - */ - public function rules(): array - { - return [ - 'payload' => [new JsonBase64Rule()], - ]; - } - - /** - * @return array<string, string> - */ - private function payload(ActionRequest $request): array - { - return json_decode(rawurldecode(base64_decode($request->input('payload', ''))), true); - } -} diff --git a/app/Contribution/Actions/GenerateApiAction.php b/app/Contribution/Actions/GenerateApiAction.php deleted file mode 100644 index fc8de068..00000000 --- a/app/Contribution/Actions/GenerateApiAction.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -namespace App\Contribution\Actions; - -use App\Contribution\Documents\ContributionDocument; -use Lorisleiva\Actions\ActionRequest; -use Lorisleiva\Actions\Concerns\AsAction; -use Zoomyboy\Tex\BaseCompiler; -use Zoomyboy\Tex\Tex; - -class GenerateApiAction -{ - use AsAction; - - /** - * @param class-string<ContributionDocument> $document - * @param array<string, mixed> $payload - */ - public function handle(string $document, array $payload): BaseCompiler - { - return Tex::compile($document::fromApiRequest($payload)); - } - - public function asController(ActionRequest $request): BaseCompiler - { - ValidateAction::validateType($request->input('type')); - - return $this->handle($request->input('type'), $request->input()); - } - - /** - * @return array<string, mixed> - */ - public function rules(): array - { - return []; - } -} diff --git a/app/Contribution/Actions/ValidateAction.php b/app/Contribution/Actions/ValidateAction.php deleted file mode 100644 index 2d497c26..00000000 --- a/app/Contribution/Actions/ValidateAction.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace App\Contribution\Actions; - -use App\Contribution\ContributionFactory; -use Illuminate\Http\JsonResponse; -use Illuminate\Support\Facades\Validator; -use Lorisleiva\Actions\ActionRequest; -use Lorisleiva\Actions\Concerns\AsAction; - -class ValidateAction -{ - use AsAction; - - public function asController(): JsonResponse - { - return response()->json(['valid' => true]); - } - - /** - * @return array<string, mixed> - */ - public function rules(): array - { - return app(ContributionFactory::class)->rules(request()->type); - } - - public function prepareForValidation(ActionRequest $request): void - { - static::validateType($request->input('type')); - } - - public static function validateType(?string $type = null): void - { - Validator::make(['type' => $type], app(ContributionFactory::class)->typeRule())->validate(); - } -} diff --git a/app/Contribution/ContributionFactory.php b/app/Contribution/ContributionFactory.php index 1c2bc29c..db9ed775 100644 --- a/app/Contribution/ContributionFactory.php +++ b/app/Contribution/ContributionFactory.php @@ -10,7 +10,6 @@ use App\Contribution\Documents\CitySolingenDocument; use App\Contribution\Documents\CityFrankfurtMainDocument; use App\Contribution\Documents\WuppertalDocument; use Illuminate\Support\Collection; -use Illuminate\Validation\Rule; class ContributionFactory { @@ -36,27 +35,4 @@ class ContributionFactory 'id' => $document, ]); } - - /** - * @return array<string, mixed> - */ - public function typeRule(): array - { - return [ - 'type' => ['required', Rule::in($this->documents)], - ]; - } - - /** - * @param class-string<ContributionDocument> $type - * - * @return array<string, mixed> - */ - public function rules(string $type): array - { - return [ - ...$type::globalRules(), - ...$type::rules(), - ]; - } } diff --git a/modules/Contribution/Components/FillList.php b/modules/Contribution/Components/FillList.php index f3b1fc89..35ce6cea 100644 --- a/modules/Contribution/Components/FillList.php +++ b/modules/Contribution/Components/FillList.php @@ -6,8 +6,10 @@ use App\Contribution\ContributionFactory; use App\Country; use Illuminate\Support\Collection; use App\Member\Member; +use Carbon\Carbon; use Livewire\Attributes\Validate; use Livewire\Component; +use Zoomyboy\Tex\Tex; class FillList extends Component { @@ -43,12 +45,14 @@ class FillList extends Component $this->compilers = app(ContributionFactory::class)->compilerSelect(); $this->countries = Country::select('name', 'id')->get()->toBase(); $this->clearSearch(); + $this->country = Country::firstWhere('name', 'Deutschland')->id; } - /** @todo implement compilation of document */ - public function submit(): void + public function submit() { - $this->validate(); + $payload = $this->validate(); + + return Tex::compile($this->compiler::fromRequest($payload)); } public function updatedSearch(): void @@ -96,7 +100,7 @@ class FillList extends Component <x-form::text name="eventName" wire:model="eventName" class="col-span-2" label="Veranstaltungs-Name" required></x-form::text> <x-form::text name="dateFrom" wire:model="dateFrom" type="date" label="Datum von" required></x-form::text> <x-form::text name="dateUntil" wire:model="dateUntil" type="date" label="Datum bis" required></x-form::text> - <x-form::text name="zipLocation" v-model="zipLocation" label="PLZ / Ort" required></x-form::text> + <x-form::text name="zipLocation" wire:model="zipLocation" label="PLZ / Ort" required></x-form::text> <x-form::select name="country" wire:model="country" :options="$countries" label="Land" required></x-form::select> <x-form::select name="compiler" wire:model="compiler" :options="$compilers" label="Formular" required></x-form::select> diff --git a/routes/api.php b/routes/api.php index 70730f99..2e5e81be 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,11 +1,9 @@ <?php -use App\Contribution\Actions\GenerateApiAction as ContributionGenerateApiAction; use App\Form\Actions\FormApiListAction; use App\Form\Actions\RegisterAction; use App\Group\Actions\GroupApiIndexAction; -Route::post('/contribution-generate', ContributionGenerateApiAction::class)->name('api.contribution.generate')->middleware('client:contribution-generate'); Route::post('/form/{form}/register', RegisterAction::class)->name('form.register'); Route::get('/group/{group?}', GroupApiIndexAction::class)->name('api.group'); Route::get('/form', FormApiListAction::class)->name('api.form.index'); diff --git a/routes/web.php b/routes/web.php index cb4725d3..3f6e2351 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,7 +11,6 @@ use App\Activity\Api\SubactivityStoreAction; use App\Activity\Api\SubactivityUpdateAction; use App\Contribution\Actions\FormAction as ContributionFormAction; use App\Contribution\Actions\GenerateAction as ContributionGenerateAction; -use App\Contribution\Actions\ValidateAction as ContributionValidateAction; use App\Course\Actions\CourseDestroyAction; use App\Course\Actions\CourseIndexAction; use App\Course\Actions\CourseStoreAction; @@ -102,11 +101,6 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::get('/subactivity/{subactivity}', SubactivityShowAction::class)->name('api.subactivity.show'); Route::post('/api/member/search', SearchAction::class)->name('member.search'); - // ------------------------------- Contributions ------------------------------- - Route::get('/contribution', ContributionFormAction::class)->name('contribution.form'); - Route::get('/contribution-generate', ContributionGenerateAction::class)->name('contribution.generate'); - Route::post('/contribution-validate', ContributionValidateAction::class)->name('contribution.validate'); - // ----------------------------------- mail ------------------------------------ Route::get('/maildispatcher', IndexAction::class)->name('maildispatcher.index'); Route::get('/maildispatcher/create', CreateAction::class)->name('maildispatcher.create');