pp-planer/app/Http/Controllers/TranslationController.php
Thorsten Bus 27f8402ae8 feat: Wave 4 - Song DB Management + Finalization (T20-T24)
T20: Song DB Page
- Songs/Index.vue with search, action buttons, pagination
- Upload area for .pro files (calls T23 placeholder)
- Song-Datenbank nav link added to AuthenticatedLayout
- Tests: 9 new (44 assertions)

T21: Song DB Edit Popup
- SongEditModal.vue with metadata + ArrangementConfigurator
- Auto-save with fetch (500ms debounce for text, immediate on blur)
- Tests: 11 new (53 assertions)

T22: Song DB Translate Page
- Songs/Translate.vue with two-column editor
- URL fetch or manual paste, line-count constraints
- Group headers with colors, save marks has_translation=true
- Tests: 1 new (12 assertions)

T23: .pro File Placeholders
- ProParserNotImplementedException with HTTP 501
- ProFileController with importPro/downloadPro placeholders
- German error messages
- Tests: 5 new (7 assertions)

T24: Service Finalization + Status
- Two-step finalization with warnings (unmatched songs, missing slides)
- Download placeholder toast
- isReadyToFinalize accessor on Service model
- Tests: 11 new (30 assertions)

All tests passing: 174/174 (905 assertions)
Build: ✓ Vite production build successful
German UI: All user-facing text in German with 'Du' form
2026-03-01 20:30:07 +01:00

122 lines
3.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Song;
use App\Services\TranslationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class TranslationController extends Controller
{
public function __construct(
private readonly TranslationService $translationService,
) {
}
public function page(Song $song): Response
{
$song->load([
'groups' => fn ($query) => $query
->orderBy('order')
->with([
'slides' => fn ($slideQuery) => $slideQuery->orderBy('order'),
]),
]);
return Inertia::render('Songs/Translate', [
'song' => [
'id' => $song->id,
'title' => $song->title,
'ccli_id' => $song->ccli_id,
'has_translation' => $song->has_translation,
'groups' => $song->groups->map(fn ($group) => [
'id' => $group->id,
'name' => $group->name,
'color' => $group->color,
'order' => $group->order,
'slides' => $group->slides->map(fn ($slide) => [
'id' => $slide->id,
'order' => $slide->order,
'text_content' => $slide->text_content,
'text_content_translated' => $slide->text_content_translated,
])->values(),
])->values(),
],
]);
}
/**
* URL abrufen und Text zum Prüfen zurückgeben.
*
* Der Text wird NICHT automatisch gespeichert — der Benutzer
* prüft ihn zuerst und importiert dann explizit.
*/
public function fetchUrl(Request $request): JsonResponse
{
$request->validate([
'url' => ['required', 'url'],
]);
$text = $this->translationService->fetchFromUrl($request->input('url'));
if ($text === null) {
return response()->json([
'message' => 'Konnte Text nicht abrufen',
], 422);
}
return response()->json([
'text' => $text,
]);
}
/**
* Übersetzungstext für einen Song importieren.
*
* Verteilt den Text zeilenweise auf die Slides des Songs.
*/
public function import(int $songId, Request $request): JsonResponse
{
$song = Song::find($songId);
if (! $song) {
return response()->json([
'message' => 'Song nicht gefunden',
], 404);
}
$request->validate([
'text' => ['required', 'string'],
]);
$this->translationService->importTranslation($song, $request->input('text'));
return response()->json([
'message' => 'Übersetzung erfolgreich importiert',
]);
}
/**
* Übersetzung eines Songs komplett entfernen.
*/
public function destroy(int $songId): JsonResponse
{
$song = Song::find($songId);
if (! $song) {
return response()->json([
'message' => 'Song nicht gefunden',
], 404);
}
$this->translationService->removeTranslation($song);
return response()->json([
'message' => 'Übersetzung entfernt',
]);
}
}