From 8e382126fd8f28df1e7c4dfd5a4ef4a84fc3ebd4 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 25 Feb 2023 19:12:07 +0100 Subject: [PATCH] Add: delete activity --- app/Activity/Actions/DestroyAction.php | 24 +++++++++++-- resources/js/views/activity/VIndex.vue | 37 +++++++++++++++++-- tests/Feature/Activity/DestroyTest.php | 49 ++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 tests/Feature/Activity/DestroyTest.php diff --git a/app/Activity/Actions/DestroyAction.php b/app/Activity/Actions/DestroyAction.php index f5c7f7de..e02306fe 100644 --- a/app/Activity/Actions/DestroyAction.php +++ b/app/Activity/Actions/DestroyAction.php @@ -2,14 +2,34 @@ namespace App\Activity\Actions; +use App\Activity; +use App\Member\Membership; +use Illuminate\Http\RedirectResponse; +use Illuminate\Validation\ValidationException; use Lorisleiva\Actions\Concerns\AsAction; class DestroyAction { use AsAction; - public function handle() + public function handle(Activity $activity): void { - // ... + $activity->subactivities()->sync([]); + $activity->delete(); + } + + public function asController(Activity $activity): RedirectResponse + { + if (Membership::where('activity_id', $activity->id)->count()) { + throw ValidationException::withMessages(['activity' => 'Tätigkeit besitzt noch Mitglieder.']); + } + + if ($activity->hasNami) { + throw ValidationException::withMessages(['activity' => 'Tätigkeit ist in NaMi.']); + } + + $this->handle($activity); + + return redirect()->route('activity.index'); } } diff --git a/resources/js/views/activity/VIndex.vue b/resources/js/views/activity/VIndex.vue index aa2678a2..f36b51a0 100644 --- a/resources/js/views/activity/VIndex.vue +++ b/resources/js/views/activity/VIndex.vue @@ -1,5 +1,16 @@