diff --git a/src/Controllers/Admin/FaqController.php b/src/Controllers/Admin/FaqController.php index a7f8cd3a..d0e002ff 100644 --- a/src/Controllers/Admin/FaqController.php +++ b/src/Controllers/Admin/FaqController.php @@ -47,13 +47,7 @@ class FaqController extends BaseController $faq = $this->faq->findOrNew($faqId); if ($request->request->has('delete')) { - $faq->delete(); - - $this->log->info('Deleted faq "{question}"', ['question' => $faq->question]); - - $this->addNotification('faq.delete.success'); - - return $this->redirect->to('/faq'); + return $this->delete($faq); } $data = $this->validate($request, [ @@ -79,6 +73,17 @@ class FaqController extends BaseController return $this->redirect->to('/faq#faq-' . $faq->id); } + protected function delete(Faq $faq): Response + { + $faq->delete(); + + $this->log->info('Deleted faq "{question}"', ['question' => $faq->question]); + + $this->addNotification('faq.delete.success'); + + return $this->redirect->to('/faq'); + } + protected function showEdit(?Faq $faq): Response { return $this->response->withView( diff --git a/src/Controllers/Admin/NewsController.php b/src/Controllers/Admin/NewsController.php index dc5fe766..c3cbf464 100644 --- a/src/Controllers/Admin/NewsController.php +++ b/src/Controllers/Admin/NewsController.php @@ -67,19 +67,7 @@ class NewsController extends BaseController $news = $this->news->findOrNew($newsId); if ($request->request->has('delete')) { - $news->delete(); - - $this->log->info( - 'Deleted {type} "{news}"', - [ - 'type' => $news->is_meeting ? 'meeting' : 'news', - 'news' => $news->title, - ] - ); - - $this->addNotification('news.delete.success'); - - return $this->redirect->to('/news'); + return $this->delete($news); } $data = $this->validate($request, [ @@ -138,4 +126,21 @@ class NewsController extends BaseController return $this->redirect->to('/news'); } + + protected function delete(News $news): Response + { + $news->delete(); + + $this->log->info( + 'Deleted {type} "{news}"', + [ + 'type' => $news->is_meeting ? 'meeting' : 'news', + 'news' => $news->title, + ] + ); + + $this->addNotification('news.delete.success'); + + return $this->redirect->to('/news'); + } } diff --git a/tests/Unit/Controllers/Admin/FaqControllerTest.php b/tests/Unit/Controllers/Admin/FaqControllerTest.php index 84d1ba12..a183ea38 100644 --- a/tests/Unit/Controllers/Admin/FaqControllerTest.php +++ b/tests/Unit/Controllers/Admin/FaqControllerTest.php @@ -123,6 +123,7 @@ class FaqControllerTest extends ControllerTest /** * @covers \Engelsystem\Controllers\Admin\FaqController::save + * @covers \Engelsystem\Controllers\Admin\FaqController::delete */ public function testSaveDelete(): void { diff --git a/tests/Unit/Controllers/Admin/NewsControllerTest.php b/tests/Unit/Controllers/Admin/NewsControllerTest.php index d8f23730..06096586 100644 --- a/tests/Unit/Controllers/Admin/NewsControllerTest.php +++ b/tests/Unit/Controllers/Admin/NewsControllerTest.php @@ -224,6 +224,7 @@ class NewsControllerTest extends ControllerTest /** * @covers \Engelsystem\Controllers\Admin\NewsController::save + * @covers \Engelsystem\Controllers\Admin\NewsController::delete */ public function testSaveDelete(): void {