presseportale/app/Http/Controllers/Api/Legacy/LegacyContactController.php
Kevin Adametz a3fd361ece Legacy-API-Paritaet S1+S2: connektar-Flow verhaltensgleich + KI-Schalter
Eigene Compat-Controller (Api/Legacy) fuer die 5 real genutzten
/service-Endpoints (Prod-Log-Beleg): Company-/Kontakt-Create (liefen
410!), PM-Create, Bild-Upload, published-only-GET — verschachtelte
Alt-Params, 201+Location+{}, Alt-Fehlerformat, Hit-Zaehlung,
Legacy-Land-Mapping.

- Anlegen = Einreichen (Alt-Verhalten); Sofort-Publish via neuer
  Permission api:immediate-publication (WS-7: connektar zuweisen)
- Admin-Schalter 'KI-Pruefung Legacy-API' (app_settings-Tabelle,
  Toggle auf /admin/press-releases): an = review + KI-Routing
- Admin-PM-Liste: KI-Spalte (Ampel-Badge) + manueller Pruef-Button
  ohne Routing fuer ungepruefte PMs
- Mails bei API-Einlieferern an Pressekontakt, sonst Firmen-Mail,
  Fallback Einlieferer (User-Entscheidung 10.07.)
- Tests: LegacyServiceParityTest (connektar-Flow end-to-end);
  Suite 1182 gruen

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-10 14:09:40 +00:00

65 lines
2.5 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Legacy;
use App\Http\Controllers\Controller;
use App\Models\Company;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
/**
* Alt-Vertrag POST /service/users/me/companies/{id}/contacts:
* Felder unter contact[...], salutation_id 1/2 → mr/mrs (wie ContactImporter),
* nur eigene Firmen. Paritäts-Doku §1/§4 S1.
*/
class LegacyContactController extends Controller
{
use RespondsLikeLegacyApi;
public function store(Request $request, int $company): JsonResponse
{
$company = Company::withoutGlobalScopes()
->whereKey($company)
->accessibleBy($request->user())
->first();
if (! $company) {
return $this->legacyError(403, ['You may only access companies which are related to your user-account']);
}
try {
$validated = $request->validate([
'contact' => ['required', 'array'],
'contact.salutation_id' => ['nullable', 'integer'],
'contact.title' => ['nullable', 'string', 'max:100'],
'contact.first_name' => ['required', 'string', 'max:255'],
'contact.last_name' => ['required', 'string', 'max:255'],
'contact.responsibility' => ['nullable', 'string', 'max:255'],
'contact.phone' => ['nullable', 'string', 'max:100'],
'contact.fax' => ['nullable', 'string', 'max:100'],
'contact.email' => ['nullable', 'email', 'max:255'],
])['contact'];
} catch (ValidationException $exception) {
return $this->legacyValidationError($exception);
}
$contact = $company->contacts()->create([
'portal' => $company->portal?->value,
'salutation_key' => match ((int) ($validated['salutation_id'] ?? 0)) {
1 => 'mr',
2 => 'mrs',
default => null,
},
'title' => $validated['title'] ?? null,
'first_name' => $validated['first_name'],
'last_name' => $validated['last_name'],
'responsibility' => $validated['responsibility'] ?? null,
'phone' => $validated['phone'] ?? null,
'fax' => $validated['fax'] ?? null,
'email' => $validated['email'] ?? null,
]);
return $this->legacyCreated(url("/service/users/me/companies/{$company->id}/contacts/{$contact->id}"));
}
}