T8: Service List Page - ServiceController with index, finalize, reopen actions - Services/Index.vue with status indicators (songs mapped/arranged, slides uploaded) - German UI with finalize/reopen toggle buttons - Status aggregation via SQL subqueries for efficiency - Tests: 3 passing (46 assertions) T9: Song CRUD Backend - SongController with full REST API (index, store, show, update, destroy) - SongService for default groups/arrangements creation - SongRequest validation (title required, ccli_id unique) - Search by title and CCLI ID - last_used_in_service accessor via service_songs join - Tests: 20 passing (85 assertions) T10: Slide Upload Component - SlideController with store, destroy, updateExpireDate - SlideUploader.vue with vue3-dropzone drag-and-drop - SlideGrid.vue with thumbnail grid and inline expire date editing - Multi-format support: images (sync), PPT (async job), ZIP (extract) - Type validation: information (global), moderation/sermon (service-specific) - Tests: 15 passing (37 assertions) T11: Arrangement Configurator - ArrangementController with store, clone, update, destroy - ArrangementConfigurator.vue with vue-draggable-plus - Drag-and-drop arrangement editor with colored group pills - Clone from default or existing arrangement - Color picker for group customization - Prevent deletion of last arrangement - Tests: 4 passing (17 assertions) T12: Song Matching Service - SongMatchingService with autoMatch, manualAssign, requestCreation, unassign - ServiceSongController API endpoints for song assignment - Auto-match by CCLI ID during CTS sync - Manual assignment with searchable song select - Email request for missing songs (MissingSongRequest mailable) - Tests: 14 passing (33 assertions) T13: Translation Service - TranslationService with fetchFromUrl, importTranslation, removeTranslation - TranslationController API endpoints - URL scraping (best-effort HTTP fetch with strip_tags) - Line-count distribution algorithm (match original slide line counts) - Mark song as translated, remove translation - Tests: 18 passing (18 assertions) All tests passing: 103/103 (488 assertions) Build: ✓ Vite production build successful German UI: All user-facing text in German with 'Du' form
174 lines
5.6 KiB
PHP
174 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\SongRequest;
|
|
use App\Models\Song;
|
|
use App\Services\SongService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SongController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly SongService $songService,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Alle Songs auflisten (paginiert, durchsuchbar).
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$query = Song::query();
|
|
|
|
if ($search = $request->input('search')) {
|
|
$query->where(function ($q) use ($search) {
|
|
$q->where('title', 'like', "%{$search}%")
|
|
->orWhere('ccli_id', 'like', "%{$search}%");
|
|
});
|
|
}
|
|
|
|
$songs = $query->orderBy('title')
|
|
->paginate($request->input('per_page', 20));
|
|
|
|
return response()->json([
|
|
'data' => $songs->map(fn (Song $song) => [
|
|
'id' => $song->id,
|
|
'title' => $song->title,
|
|
'ccli_id' => $song->ccli_id,
|
|
'author' => $song->author,
|
|
'has_translation' => $song->has_translation,
|
|
'last_used_at' => $song->last_used_at?->toDateString(),
|
|
'last_used_in_service' => $song->last_used_in_service,
|
|
'created_at' => $song->created_at->toDateTimeString(),
|
|
'updated_at' => $song->updated_at->toDateTimeString(),
|
|
]),
|
|
'meta' => [
|
|
'current_page' => $songs->currentPage(),
|
|
'last_page' => $songs->lastPage(),
|
|
'per_page' => $songs->perPage(),
|
|
'total' => $songs->total(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Neuen Song erstellen mit Default-Gruppen und -Arrangement.
|
|
*/
|
|
public function store(SongRequest $request): JsonResponse
|
|
{
|
|
$song = DB::transaction(function () use ($request) {
|
|
$song = Song::create($request->validated());
|
|
|
|
$this->songService->createDefaultGroups($song);
|
|
$this->songService->createDefaultArrangement($song);
|
|
|
|
return $song;
|
|
});
|
|
|
|
return response()->json([
|
|
'message' => 'Song erfolgreich erstellt',
|
|
'data' => $this->formatSongDetail($song->fresh(['groups.slides', 'arrangements.arrangementGroups'])),
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* Song mit Gruppen, Slides und Arrangements anzeigen.
|
|
*/
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
$song = Song::with(['groups.slides', 'arrangements.arrangementGroups'])->find($id);
|
|
|
|
if (! $song) {
|
|
return response()->json(['message' => 'Song nicht gefunden'], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'data' => $this->formatSongDetail($song),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Song-Metadaten aktualisieren.
|
|
*/
|
|
public function update(SongRequest $request, int $id): JsonResponse
|
|
{
|
|
$song = Song::find($id);
|
|
|
|
if (! $song) {
|
|
return response()->json(['message' => 'Song nicht gefunden'], 404);
|
|
}
|
|
|
|
$song->update($request->validated());
|
|
|
|
return response()->json([
|
|
'message' => 'Song erfolgreich aktualisiert',
|
|
'data' => $this->formatSongDetail($song->fresh(['groups.slides', 'arrangements.arrangementGroups'])),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Song soft-löschen.
|
|
*/
|
|
public function destroy(int $id): JsonResponse
|
|
{
|
|
$song = Song::find($id);
|
|
|
|
if (! $song) {
|
|
return response()->json(['message' => 'Song nicht gefunden'], 404);
|
|
}
|
|
|
|
$song->delete();
|
|
|
|
return response()->json([
|
|
'message' => 'Song erfolgreich gelöscht',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Song-Detail formatieren.
|
|
*/
|
|
private function formatSongDetail(Song $song): array
|
|
{
|
|
return [
|
|
'id' => $song->id,
|
|
'title' => $song->title,
|
|
'ccli_id' => $song->ccli_id,
|
|
'author' => $song->author,
|
|
'copyright_text' => $song->copyright_text,
|
|
'copyright_year' => $song->copyright_year,
|
|
'publisher' => $song->publisher,
|
|
'has_translation' => $song->has_translation,
|
|
'last_used_at' => $song->last_used_at?->toDateString(),
|
|
'last_used_in_service' => $song->last_used_in_service,
|
|
'created_at' => $song->created_at->toDateTimeString(),
|
|
'updated_at' => $song->updated_at->toDateTimeString(),
|
|
'groups' => $song->groups->sortBy('order')->values()->map(fn ($group) => [
|
|
'id' => $group->id,
|
|
'name' => $group->name,
|
|
'color' => $group->color,
|
|
'order' => $group->order,
|
|
'slides' => $group->slides->sortBy('order')->values()->map(fn ($slide) => [
|
|
'id' => $slide->id,
|
|
'order' => $slide->order,
|
|
'text_content' => $slide->text_content,
|
|
'text_content_translated' => $slide->text_content_translated,
|
|
'notes' => $slide->notes,
|
|
])->toArray(),
|
|
])->toArray(),
|
|
'arrangements' => $song->arrangements->map(fn ($arr) => [
|
|
'id' => $arr->id,
|
|
'name' => $arr->name,
|
|
'is_default' => $arr->is_default,
|
|
'arrangement_groups' => $arr->arrangementGroups->sortBy('order')->values()->map(fn ($ag) => [
|
|
'id' => $ag->id,
|
|
'song_group_id' => $ag->song_group_id,
|
|
'order' => $ag->order,
|
|
])->toArray(),
|
|
])->toArray(),
|
|
];
|
|
}
|
|
}
|