- MacroImportController + LabelImportController: POST endpoints accepting uploaded .bin files,
delegating to MacrosImportService / LabelsImportService and returning import stats / warnings as JSON.
Generic German 422 error if parser rejects the file.
- MacroAssignmentController: index renders Settings Inertia page with assignments / macros / labels /
collections / last-import metadata. store/update/destroy/reorder for global MacroAssignment rows.
- ServiceMacroOverrideController: store snapshots all matching global MacroAssignments into
service-specific rows when a service opts to override; destroy removes both override and
service-specific assignments. storeAssignment / updateAssignment / destroyAssignment manage the
per-service rows directly.
- routes/web.php: 12 new named routes inside the auth middleware group; reorder route placed before
{macroAssignment} parameter route to avoid capture conflict.
- Tests: 19 new Pest tests across 4 feature files (54 assertions). Full suite 376 passed.
95 lines
3.3 KiB
PHP
95 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\MacroAssignment;
|
|
use App\Models\Service;
|
|
use App\Models\ServiceMacroAssignment;
|
|
use App\Models\ServiceMacroOverride;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ServiceMacroOverrideController extends Controller
|
|
{
|
|
public function store(Request $request, Service $service): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'part_type' => ['required', 'in:information,moderation,sermon,song,agenda_item'],
|
|
]);
|
|
|
|
ServiceMacroOverride::firstOrCreate([
|
|
'service_id' => $service->id,
|
|
'part_type' => $validated['part_type'],
|
|
]);
|
|
|
|
$globals = MacroAssignment::where('part_type', $validated['part_type'])->orderBy('order')->get();
|
|
foreach ($globals as $global) {
|
|
ServiceMacroAssignment::firstOrCreate([
|
|
'service_id' => $service->id,
|
|
'part_type' => $validated['part_type'],
|
|
'macro_id' => $global->macro_id,
|
|
'position' => $global->position,
|
|
'label_id' => $global->label_id,
|
|
'order' => $global->order,
|
|
]);
|
|
}
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function destroy(Service $service, Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'part_type' => ['required', 'in:information,moderation,sermon,song,agenda_item'],
|
|
]);
|
|
|
|
ServiceMacroOverride::where('service_id', $service->id)
|
|
->where('part_type', $validated['part_type'])
|
|
->delete();
|
|
|
|
ServiceMacroAssignment::where('service_id', $service->id)
|
|
->where('part_type', $validated['part_type'])
|
|
->delete();
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function storeAssignment(Request $request, Service $service): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'part_type' => ['required', 'in:information,moderation,sermon,song,agenda_item'],
|
|
'macro_id' => ['required', 'integer', 'exists:macros,id'],
|
|
'position' => ['required', 'in:all_slides,first_slide,last_slide,by_label'],
|
|
'label_id' => ['nullable', 'integer', 'exists:labels,id'],
|
|
'order' => ['integer', 'min:0'],
|
|
]);
|
|
|
|
$assignment = ServiceMacroAssignment::create([
|
|
'service_id' => $service->id,
|
|
...$validated,
|
|
]);
|
|
|
|
return response()->json(['id' => $assignment->id, 'success' => true]);
|
|
}
|
|
|
|
public function updateAssignment(Request $request, Service $service, ServiceMacroAssignment $serviceMacroAssignment): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'position' => ['sometimes', 'in:all_slides,first_slide,last_slide,by_label'],
|
|
'label_id' => ['nullable', 'integer', 'exists:labels,id'],
|
|
'order' => ['sometimes', 'integer', 'min:0'],
|
|
]);
|
|
|
|
$serviceMacroAssignment->update($validated);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function destroyAssignment(Service $service, ServiceMacroAssignment $serviceMacroAssignment): JsonResponse
|
|
{
|
|
$serviceMacroAssignment->delete();
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|