pp-planer/app/Http/Controllers/ServiceSongController.php
Thorsten Bus 7a29a21822 feat: confirm-state for service songs + service-edit UX fixes
- add explicit confirmed_at assignment state (red/amber/green) with confirm/unconfirm endpoints
- clone leader arrangement before opening dialog to avoid flicker
- agenda slide strip: show all previews, drag-reorder, number badges, auto-hide uploader
- fix info-slide expire-date saving via axios (was rendering raw JSON modal)
- point top-left logo to / instead of /dashboard
2026-06-21 11:53:55 +02:00

144 lines
4.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\ServiceSong;
use App\Models\Song;
use App\Services\SongMatchingService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
class ServiceSongController extends Controller
{
public function __construct(
private readonly SongMatchingService $songMatchingService,
) {}
/**
* Manuell einen Song aus der DB einem ServiceSong zuordnen.
*/
public function assignSong(int $serviceSongId, Request $request): JsonResponse
{
$validated = $request->validate([
'song_id' => ['required', 'integer', 'exists:songs,id'],
]);
$serviceSong = ServiceSong::findOrFail($serviceSongId);
$song = Song::findOrFail($validated['song_id']);
$this->songMatchingService->manualAssign($serviceSong, $song);
return response()->json([
'message' => 'Song erfolgreich zugeordnet',
'service_song' => $serviceSong->fresh(),
]);
}
/**
* E-Mail-Anfrage für fehlenden Song senden.
*/
public function requestSong(int $serviceSongId): JsonResponse
{
$serviceSong = ServiceSong::findOrFail($serviceSongId);
$this->songMatchingService->requestCreation($serviceSong);
return response()->json([
'message' => 'Anfrage wurde gesendet',
'service_song' => $serviceSong->fresh(),
]);
}
/**
* Song-Zuordnung entfernen.
*/
public function unassign(int $serviceSongId): JsonResponse
{
$serviceSong = ServiceSong::findOrFail($serviceSongId);
$this->songMatchingService->unassign($serviceSong);
return response()->json([
'message' => 'Zuordnung entfernt',
'service_song' => $serviceSong->fresh(),
]);
}
public function update(int $serviceSongId, Request $request): JsonResponse
{
$validated = $request->validate([
'song_arrangement_id' => ['nullable', 'integer', 'exists:song_arrangements,id'],
'use_translation' => ['sometimes', 'boolean'],
]);
$serviceSong = ServiceSong::with('song')->findOrFail($serviceSongId);
if (array_key_exists('song_arrangement_id', $validated) && $validated['song_arrangement_id'] !== null) {
if ($serviceSong->song_id === null || $serviceSong->song === null) {
return response()->json([
'message' => 'Arrangement kann ohne zugeordneten Song nicht gespeichert werden.',
], 422);
}
$isValidArrangement = $serviceSong->song
->arrangements()
->whereKey($validated['song_arrangement_id'])
->exists();
if (! $isValidArrangement) {
return response()->json([
'message' => 'Das Arrangement gehoert nicht zu diesem Song.',
], 422);
}
}
// Bei tatsaechlicher Aenderung des Arrangements muss neu bestaetigt werden.
if (array_key_exists('song_arrangement_id', $validated)
&& $validated['song_arrangement_id'] !== $serviceSong->song_arrangement_id) {
$validated['confirmed_at'] = null;
}
$serviceSong->update($validated);
return response()->json([
'message' => 'Service-Song wurde aktualisiert.',
'service_song' => $serviceSong->fresh(),
]);
}
/**
* Zuordnung eines Service-Songs explizit bestaetigen.
*/
public function confirm(int $serviceSongId): JsonResponse
{
$serviceSong = ServiceSong::findOrFail($serviceSongId);
$serviceSong->update([
'confirmed_at' => Carbon::now(),
]);
return response()->json([
'success' => true,
'message' => 'Zuordnung wurde bestaetigt.',
]);
}
/**
* Bestaetigung eines Service-Songs zuruecknehmen.
*/
public function unconfirm(int $serviceSongId): JsonResponse
{
$serviceSong = ServiceSong::findOrFail($serviceSongId);
$serviceSong->update([
'confirmed_at' => null,
]);
return response()->json([
'success' => true,
'message' => 'Bestaetigung wurde zurueckgenommen.',
]);
}
}