From 981348274186b189a732b1a916a1a2329b4ae95b Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 16 Oct 2023 16:36:02 +0200 Subject: [PATCH] Add update for payment --- app/Payment/Actions/PaymentUpdateAction.php | 37 ++++++++++++++++----- app/Payment/PaymentController.php | 13 -------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/app/Payment/Actions/PaymentUpdateAction.php b/app/Payment/Actions/PaymentUpdateAction.php index f8f3e7e6..6f5ab70e 100644 --- a/app/Payment/Actions/PaymentUpdateAction.php +++ b/app/Payment/Actions/PaymentUpdateAction.php @@ -2,16 +2,23 @@ namespace App\Payment\Actions; +use App\Lib\JobMiddleware\JobChannels; +use App\Lib\JobMiddleware\WithJobState; +use App\Lib\Queue\TracksJob; +use App\Payment\Payment; use Illuminate\Http\JsonResponse; use Illuminate\Validation\Rules\In; +use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; class PaymentUpdateAction { use AsAction; + use TracksJob; - public function handle(): void + public function handle(Payment $payment, array $attributes): void { + $payment->update($attributes); } /** @@ -19,19 +26,31 @@ class PaymentUpdateAction */ public function rules(): array { - return []; + return [ + 'nr' => 'required', + 'subscription_id' => 'required|exists:subscriptions,id', + 'status_id' => 'required|exists:statuses,id', + ]; + } + + public function asController(Payment $payment, ActionRequest $request): JsonResponse + { + $this->startJob($payment, $request->validated()); + + return response()->json([]); } /** - * @return array + * @param mixed $parameters */ - public function getValidationAttributes(): array + public function jobState(WithJobState $jobState, ...$parameters): WithJobState { - return []; - } + $member = $parameters[0]->member; - public function asController(): JsonResponse - { - return response()->json([]); + return $jobState + ->before('Zahlung für ' . $member->fullname . ' wird aktualisiert') + ->after('Zahlung für ' . $member->fullname . ' aktualisiert') + ->failed('Fehler beim Aktualisieren der Zahlung für ' . $member->fullname) + ->shouldReload(JobChannels::make()->add('member')->add('payment')); } } diff --git a/app/Payment/PaymentController.php b/app/Payment/PaymentController.php index 8cef777f..baf2a029 100644 --- a/app/Payment/PaymentController.php +++ b/app/Payment/PaymentController.php @@ -11,19 +11,6 @@ use Illuminate\Http\Response; class PaymentController extends Controller { - public function update(Request $request, Member $member, Payment $payment): Response - { - $payment->update($request->validate([ - 'nr' => 'required', - 'subscription_id' => 'required|exists:subscriptions,id', - 'status_id' => 'required|exists:statuses,id', - ])); - - ClientMessage::make('Zahlung aktualisiert.')->shouldReload()->dispatch(); - - return response(''); - } - public function destroy(Request $request, Member $member, Payment $payment): Response { $payment->delete();