src/Controller/Api/OCRSearchController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Service\ElasticSearchClientInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class OCRSearchController extends AbstractController
  10. {
  11.     private ElasticSearchClientInterface $elasticSearchService;
  12.     public function __construct(ElasticSearchClientInterface $elasticSearchService)
  13.     {
  14.         $this->elasticSearchService $elasticSearchService;
  15.     }
  16.     /**
  17.      * @Route("/search-in-letters/{orgaId}", name="app_search_in_letters", methods={"GET"})
  18.      */
  19.     public function searchInLetters(Request $requeststring $orgaId): JsonResponse
  20.     {
  21.         $user $this->getUser();
  22.         if (null === $user) {
  23.             return $this->json('Vous devez etre connecté'Response::HTTP_UNAUTHORIZED);
  24.         }
  25.         $searchTerm $request->query->get('search');
  26.         if (!$searchTerm) {
  27.             return $this->json('No search term provided'Response::HTTP_BAD_REQUEST);
  28.         }
  29.         return $this->json($this->elasticSearchService->searchInLetters($orgaId$searchTerm), Response::HTTP_OK);
  30.     }
  31. }