diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index 3f6caa2..9c927f4 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -107,8 +107,10 @@ public function edit(Service $service): Response ->when( $service->date, fn ($query) => $query - ->whereNotNull('expire_date') - ->whereDate('expire_date', '>=', $service->date) + ->where(function ($q) use ($service) { + $q->whereNull('expire_date') + ->orWhereDate('expire_date', '>=', $service->date); + }) ) ->orderByDesc('uploaded_at') ->get(); @@ -222,6 +224,17 @@ public function reopen(Service $service): RedirectResponse ->with('success', 'Service wurde wieder geoeffnet.'); } + public function destroy(Service $service): RedirectResponse + { + $service->serviceSongs()->delete(); + $service->slides()->where('type', '!=', 'information')->delete(); + $service->delete(); + + return redirect() + ->route('services.index') + ->with('success', 'Service wurde gelöscht und wird beim nächsten Sync neu erstellt.'); + } + public function download(Service $service): JsonResponse|BinaryFileResponse { if (! $service->finalized_at) { diff --git a/tests/Feature/InformationBlockTest.php b/tests/Feature/InformationBlockTest.php index f6c8158..25b7ff6 100644 --- a/tests/Feature/InformationBlockTest.php +++ b/tests/Feature/InformationBlockTest.php @@ -178,7 +178,7 @@ ); }); -test('information slides without expire_date are not shown', function () { +test('information slides without expire_date are shown', function () { Carbon::setTestNow('2026-03-01 10:00:00'); $service = Service::factory()->create(['date' => '2026-03-10']); @@ -188,13 +188,14 @@ 'type' => 'information', 'service_id' => null, 'expire_date' => '2026-03-20', + 'uploaded_at' => '2026-02-01 10:00:00', ]); - // Info slide without expire_date (should NOT show — no expire means not scheduled) - Slide::factory()->create([ + $withoutExpire = Slide::factory()->create([ 'type' => 'information', 'service_id' => null, 'expire_date' => null, + 'uploaded_at' => '2026-02-15 10:00:00', ]); $response = $this->get(route('services.edit', $service)); @@ -202,8 +203,9 @@ $response->assertOk(); $response->assertInertia( fn ($page) => $page - ->has('informationSlides', 1) - ->where('informationSlides.0.id', $withExpire->id) + ->has('informationSlides', 2) + ->where('informationSlides.0.id', $withoutExpire->id) + ->where('informationSlides.1.id', $withExpire->id) ); });