pp-planer/app/Http/Controllers/MacroImportController.php
Thorsten Bus 6ce5b6e018 feat(controllers): add macro/label import + global assignment + service override controllers and routes
- 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.
2026-05-03 23:17:04 +02:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Services\MacrosImportService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Throwable;
class MacroImportController extends Controller
{
public function __construct(
private readonly MacrosImportService $importService,
) {}
public function store(Request $request): JsonResponse
{
$request->validate(['file' => ['required', 'file', 'max:5120']]);
$file = $request->file('file');
$tempPath = $file->getPathname();
try {
$result = $this->importService->import($tempPath, $file->getClientOriginalName());
} catch (Throwable $e) {
return response()->json([
'message' => 'Die Datei konnte nicht gelesen werden. Stelle sicher, dass es eine gültige ProPresenter Makro-Datei ist.',
], 422);
}
return response()->json([
'stats' => [
'new' => $result->new,
'updated' => $result->updated,
'disabled' => $result->disabled,
're_enabled' => $result->reEnabled,
],
'warnings' => $result->warnings,
]);
}
}