From 8e3054da49522384c3ded24dccda531917d2435c Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 25 Apr 2024 21:49:31 +0200 Subject: [PATCH] Add: Delete participant --- app/Form/Actions/ParticipantDestroyAction.php | 36 +++++++++++++++++++ app/Form/Resources/ParticipantResource.php | 3 ++ resources/js/views/form/Participants.vue | 26 +++++++++++--- routes/web.php | 2 ++ .../Form/ParticipantDestroyActionTest.php | 27 ++++++++++++++ .../Form/ParticipantIndexActionTest.php | 1 + 6 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 app/Form/Actions/ParticipantDestroyAction.php create mode 100644 tests/Feature/Form/ParticipantDestroyActionTest.php diff --git a/app/Form/Actions/ParticipantDestroyAction.php b/app/Form/Actions/ParticipantDestroyAction.php new file mode 100644 index 00000000..bc6777a6 --- /dev/null +++ b/app/Form/Actions/ParticipantDestroyAction.php @@ -0,0 +1,36 @@ +delete(); + } + + public function asController(Participant $participant): void + { + $this->startJob($participant->id); + } + + /** + * @param mixed $parameters + */ + public function jobState(WithJobState $jobState, ...$parameters): WithJobState + { + return $jobState + ->after('Teilnehmer gelöscht.') + ->failed('Löschen von Teilnehmer fehlgeschlagen.') + ->shouldReload(JobChannels::make()->add('participant')); + } +} diff --git a/app/Form/Resources/ParticipantResource.php b/app/Form/Resources/ParticipantResource.php index 2e300cba..a1413e0a 100644 --- a/app/Form/Resources/ParticipantResource.php +++ b/app/Form/Resources/ParticipantResource.php @@ -24,6 +24,9 @@ class ParticipantResource extends JsonResource ...$this->getModel()->getFields()->present(), 'created_at' => $this->created_at->format('Y-m-d H:i:s'), 'created_at_display' => $this->created_at->format('d.m.Y'), + 'links' => [ + 'destroy' => route('participant.destroy', ['participant' => $this->getModel()]), + ] ]; } diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index ca4a68c7..83e22196 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -1,5 +1,14 @@