33 خطوط
1.0 KiB
PHP
33 خطوط
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\DuplicateService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DuplicateController extends Controller
|
|
{
|
|
public function __construct(private DuplicateService $duplicates) {}
|
|
|
|
public function check(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'entity_type' => 'required|in:lead,company',
|
|
'exclude_id' => 'nullable|integer',
|
|
'name' => 'nullable|string',
|
|
'company' => 'nullable|string',
|
|
'website' => 'nullable|string',
|
|
'email' => 'nullable|string',
|
|
'phone' => 'nullable|string',
|
|
]);
|
|
|
|
$items = $validated['entity_type'] === 'company'
|
|
? $this->duplicates->companySuggestions($validated, $validated['exclude_id'] ?? null)
|
|
: $this->duplicates->leadSuggestions($validated, $validated['exclude_id'] ?? null);
|
|
|
|
return response()->json(['data' => $items]);
|
|
}
|
|
}
|