- Recherche back fonctionnel
This commit is contained in:
@ -4,7 +4,7 @@ namespace App\Controller;
|
||||
|
||||
use App\Service\GoogleBooksService;
|
||||
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;
|
||||
|
||||
@ -17,19 +17,25 @@ class APISearchController extends AbstractController
|
||||
$this->googleBooksService = $googleBooksService;
|
||||
}
|
||||
|
||||
public function search(): array
|
||||
public function search(Request $request): array
|
||||
{
|
||||
return $this->googleBooksService->searchBooks('Le loup des steppes');
|
||||
// Récupérer le paramètre "q" depuis la requête
|
||||
$query = $request->query->get('q');
|
||||
|
||||
// Appeler le service GoogleBooks avec la requête
|
||||
return $this->googleBooksService->searchBooks($query);
|
||||
}
|
||||
|
||||
#[Route('/api/search', name: 'api_search')]
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$datas = $this->search();
|
||||
// Appeler la méthode search et récupérer les résultats
|
||||
$datas = $this->search($request);
|
||||
|
||||
// Afficher les résultats dans le template
|
||||
return $this->render('apiSearch/index.html.twig', [
|
||||
'controller_name' => 'APISearchController',
|
||||
'datas' => $datas,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user