<?php
namespace App\Controller\Api;
use App\Service\ElasticSearchClientInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class OCRSearchController extends AbstractController
{
private ElasticSearchClientInterface $elasticSearchService;
public function __construct(ElasticSearchClientInterface $elasticSearchService)
{
$this->elasticSearchService = $elasticSearchService;
}
/**
* @Route("/search-in-letters/{orgaId}", name="app_search_in_letters", methods={"GET"})
*/
public function searchInLetters(Request $request, string $orgaId): JsonResponse
{
$user = $this->getUser();
if (null === $user) {
return $this->json('Vous devez etre connecté', Response::HTTP_UNAUTHORIZED);
}
$searchTerm = $request->query->get('search');
if (!$searchTerm) {
return $this->json('No search term provided', Response::HTTP_BAD_REQUEST);
}
return $this->json($this->elasticSearchService->searchInLetters($orgaId, $searchTerm), Response::HTTP_OK);
}
}