++ fix: Rientro assegnazione e territorio
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\TerritorioPdfImportDispatcher;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use RuntimeException;
|
||||
|
||||
class TerritoryPdfImportController extends Controller
|
||||
{
|
||||
public function storeZip(Request $request, TerritorioPdfImportDispatcher $dispatcher): JsonResponse|RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'pdfZip' => ['required', 'file', 'mimes:zip', 'max:256000'],
|
||||
]);
|
||||
|
||||
try {
|
||||
$importId = $dispatcher->dispatchUploadedZip($request->file('pdfZip'), auth()->id());
|
||||
} catch (RuntimeException $exception) {
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'message' => $exception->getMessage(),
|
||||
'errors' => ['pdfZip' => [$exception->getMessage()]],
|
||||
], 422);
|
||||
}
|
||||
|
||||
return back()->withErrors(['pdfZip' => $exception->getMessage()]);
|
||||
}
|
||||
|
||||
$redirectUrl = route('xml.exchange', ['pdf-import' => $importId]);
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'message' => 'Import PDF avviato in background.',
|
||||
'import_id' => $importId,
|
||||
'redirect_url' => $redirectUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect($redirectUrl)
|
||||
->with('success', 'Import PDF avviato in background. I log si aggiorneranno automaticamente.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user