- 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,
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,19 @@
|
||||
class="relative flex items-center">
|
||||
<!-- Cart Icon -->
|
||||
<div class="relative">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-500">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
|
||||
</svg>
|
||||
<input type="search" class="pl-10 pr-4 py-1 mr-6 rounded-xl border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Recherche...">
|
||||
<form action="/api/search" method="GET" class="relative">
|
||||
<button type="submit" class="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-500">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
|
||||
</svg>
|
||||
</button>
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
class="pl-10 pr-4 py-1 mr-6 rounded-xl border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
placeholder="Recherche..."
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<a class="me-4 text-neutral-600 transition duration-200 hover:text-neutral-700 hover:ease-in-out focus:text-neutral-700 disabled:text-black/30 motion-reduce:transition-none dark:text-neutral-200 dark:hover:text-neutral-300 dark:focus:text-neutral-300 [&.active]:text-black/90 dark:[&.active]:text-neutral-400" href="#">
|
||||
|
Reference in New Issue
Block a user