diff --git a/public/js/customButton.js b/public/js/customButton.js
index 985ba89..8a85ad9 100644
--- a/public/js/customButton.js
+++ b/public/js/customButton.js
@@ -1,4 +1,5 @@
let myButton = document.getElementById("refreshPokemonListBtn")
myButton.addEventListener("click", (event)=>{
event.preventDefault()
+ window.location = "/pokemon"
})
diff --git a/src/Controller/PokemonController.php b/src/Controller/PokemonController.php
index 28314df..26e25d0 100644
--- a/src/Controller/PokemonController.php
+++ b/src/Controller/PokemonController.php
@@ -23,15 +23,14 @@ class PokemonController extends AbstractController
{
// Si l'utilisateur saisit un mot clé
if ($pokemonSearchTerm = $request->query->get('keyword')) {
- $qr = $pokemonRepository->findPokemonsWithSearchTerm($pokemonSearchTerm);
+ $qr = $pokemonRepository->findPokemonsWithSearchTermQuery($pokemonSearchTerm);
} else {
// Sinon on affichera tout les pokemons
- $qr = $pokemonRepository->findAll();
+ $qr = $pokemonRepository->findAllPokemonQuery();
}
// Paginate the results of the query
$pokemons = $paginator->paginate(
- // TODO: poser la question à Simon (performances moindres avec passage du result ?)
$qr, /*query NOT result*/
$request->query->getInt('page', 1), /*page number*/
15 /*Items per page*/
diff --git a/src/Entity/Pokemon.php b/src/Entity/Pokemon.php
index 9d27cac..41a8985 100644
--- a/src/Entity/Pokemon.php
+++ b/src/Entity/Pokemon.php
@@ -6,6 +6,8 @@ use App\Repository\PokemonRepository;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
+use ApiPlatform\Core\Annotation\ApiFilter;
+use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ORM\Entity(repositoryClass=PokemonRepository::class)
@@ -14,6 +16,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
* "groups"={"pokemon_read"}
* }
* )
+ * @ApiFilter(SearchFilter::class, properties={"nom": "partial"})
*/
class Pokemon
{
diff --git a/src/Repository/PokemonRepository.php b/src/Repository/PokemonRepository.php
index 9747632..fdc2406 100644
--- a/src/Repository/PokemonRepository.php
+++ b/src/Repository/PokemonRepository.php
@@ -4,6 +4,7 @@ namespace App\Repository;
use App\Entity\Pokemon;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\ORM\Query;
use Doctrine\Persistence\ManagerRegistry;
/**
@@ -19,12 +20,23 @@ class PokemonRepository extends ServiceEntityRepository
parent::__construct($registry, Pokemon::class);
}
+ /**
+ * @return Query
+ */
+
+ public function findAllPokemonQuery(): Query
+ {
+ return $this->createQueryBuilder('p')
+ ->orderBy('p.numero', 'ASC')
+ ->getQuery();
+ }
+
/**
* @param $params
- * @return Pokemon[] Returns an array of Pokemon objects
+ * @return Query
*/
- public function findPokemonsWithSearchTerm($searchTerm): array
+ public function findPokemonsWithSearchTermQuery($searchTerm): Query
{
return $this->createQueryBuilder('p')
->andWhere('p.nom LIKE :searchTerm
@@ -34,8 +46,7 @@ class PokemonRepository extends ServiceEntityRepository
->leftJoin('p.generation', 'gen')
->setParameter('searchTerm', '%' . $searchTerm . '%')
->orderBy('p.numero', 'ASC')
- ->getQuery()
- ->getResult();
+ ->getQuery();
}
diff --git a/templates/pokemon/index.html.twig b/templates/pokemon/index.html.twig
index b314900..87f461d 100644
--- a/templates/pokemon/index.html.twig
+++ b/templates/pokemon/index.html.twig
@@ -3,6 +3,7 @@
{% block title %}Pokemon index{% endblock %}
{% block stylesheets %}
+