freescout2ant/Http/Controllers/AmeiseController.php
2025-04-21 21:22:12 +02:00

48 lines
1.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Modules\AmeiseModule\Http\Controllers;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Modules\AmeiseModule\Services\CrmService;
class AmeiseController extends Controller
{
public function __construct(
protected CrmService $crm
) {}
/**
* Zentraler AjaxEndpunkt.
*
* Erwartet JSON mit { action: string, data: array }
*/
public function ajax(Request $request): JsonResponse
{
$validated = $request->validate([
'action' => 'required|string',
'data' => 'array',
]);
return match ($validated['action']) {
'createContact' => $this->ok($this->crm->createContact($validated['data'])),
'updateContact' => $this->ok($this->crm->updateContact($validated['data']['id'], $validated['data'])),
'createContract' => $this->ok($this->crm->createContract($validated['data'])),
'updateContract' => $this->ok($this->crm->updateContract($validated['data']['id'], $validated['data'])),
'uploadAttachment'=> $this->ok(
$this->crm->uploadAttachment(
$validated['data']['name'],
$validated['data']['mime'],
$validated['data']['path'],
)
),
default => response()->json(['error' => 'Unbekannte Action'], 400),
};
}
private function ok(mixed $payload): JsonResponse
{
return response()->json(['status' => 'ok', 'data' => $payload]);
}
}