58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Legacy;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
/**
|
|
* Response-Konventionen der Alt-API (Symfony, tnHttpError-Templates):
|
|
* Erfolg beim Anlegen = 201 + Location-Header + Body {};
|
|
* Fehler = {"global_errors":[…]} bzw. 422 zusätzlich mit "field_errors".
|
|
* Vertrag dokumentiert in dev/betrieb/api-legacy-paritaet.md §1.
|
|
*/
|
|
trait RespondsLikeLegacyApi
|
|
{
|
|
protected function legacyCreated(string $locationUrl): JsonResponse
|
|
{
|
|
return response()->json((object) [], 201)->header('Location', $locationUrl);
|
|
}
|
|
|
|
protected function legacyError(int $status, array $globalErrors): JsonResponse
|
|
{
|
|
return response()->json(['global_errors' => $globalErrors], $status);
|
|
}
|
|
|
|
protected function legacyValidationError(ValidationException $exception): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'global_errors' => [],
|
|
'field_errors' => $exception->errors(),
|
|
], 422);
|
|
}
|
|
|
|
/**
|
|
* Legacy-Land (country.id der Altportale) → ISO-Code des neuen Systems.
|
|
* Häufigste IDs aus dem Prod-Snapshot; unbekannte → null (Feld leer).
|
|
*/
|
|
protected function legacyCountryCode(mixed $legacyCountryId): ?string
|
|
{
|
|
return match ((int) $legacyCountryId) {
|
|
177 => 'DE',
|
|
80 => 'AT',
|
|
196 => 'CH',
|
|
229 => 'US',
|
|
30 => 'GB',
|
|
165 => 'FR',
|
|
78 => 'IT',
|
|
2 => 'NL',
|
|
47 => 'ES',
|
|
108 => 'CY',
|
|
115 => 'LI',
|
|
117 => 'LU',
|
|
15 => 'AU',
|
|
89 => 'CA',
|
|
default => null,
|
|
};
|
|
}
|
|
}
|