diff --git a/src/Controller/APISearchController.php b/src/Controller/APISearchController.php index 4cf58e9..2567c11 100644 --- a/src/Controller/APISearchController.php +++ b/src/Controller/APISearchController.php @@ -23,9 +23,11 @@ class APISearchController extends AbstractController { // Récupérer le paramètre "q" depuis la requête $query = $request->query->get('q'); + $nb_pages = $request->query->get('page') ?? '1'; + // Appeler le service GoogleBooks avec la requête - return $this->googleBooksService->searchBooks($query); + return $this->googleBooksService->searchBooks($query, 'fr', ($nb_pages - 1) *10); } #[Route('/toggleLike/{idGoogle}', name: 'like', methods: "POST")] diff --git a/src/services/GoogleService.php b/src/services/GoogleService.php index 07b634a..761449f 100644 --- a/src/services/GoogleService.php +++ b/src/services/GoogleService.php @@ -13,20 +13,22 @@ class GoogleBooksService $this->client = $client; } - public function searchBooks(string $query, string $lang = 'fr'): array + public function searchBooks(string $query, string $lang = 'fr', string $nb_pages): array { $url = 'https://www.googleapis.com/books/v1/volumes'; $response = $this->client->request('GET', $url, [ 'query' => [ 'q' => $query, 'langRestrict' => $lang, + 'maxResults' => 10, + 'startIndex' => $nb_pages, + 'printType' => 'books', ], ]); // Convertir la réponse JSON en tableau PHP $dataArray = $response->toArray(); - return $dataArray; } } diff --git a/templates/apiSearch/index.html.twig b/templates/apiSearch/index.html.twig index 312fb66..4012959 100644 --- a/templates/apiSearch/index.html.twig +++ b/templates/apiSearch/index.html.twig @@ -3,6 +3,7 @@ {% block title %}{% endblock %} {% block body %} +

Résultats pour : @@ -28,9 +29,12 @@

Aux éditions : {{ book.volumeInfo.publisher }}

-

Date de publication : + {% if book.volumeInfo.publishedDate is defined %} +

Date de publication : {{ book.volumeInfo.publishedDate }}

+ {% endif %} + {% if book.volumeInfo.categories is defined %} {% for categorie in book.volumeInfo.categories %}

Catégorie : @@ -72,12 +76,58 @@ {% endfor %} + {% if favoris is empty %} + + + + {% endif %} {% endif %}

{% endfor %} + {% set nb_items = datas.totalItems %} +{% set nb_pages = nb_items / 10 %} +{% set current_page = app.request.get('page') ? app.request.get('page') : 1 %} + +{% if nb_pages > 1 %} +
+ +
+{% endif %} +