feat: ajout d'une route GetMangaByIdHandler.php et fix de la SearchBar.vue

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-25 22:44:26 +01:00
parent ed0a075a6c
commit d9e935f7de
26 changed files with 519 additions and 79 deletions

View File

@@ -148,4 +148,35 @@ class InMemoryMangaRepository implements MangaRepositoryInterface
$this->chapters = [];
$this->savedChapters = [];
}
}
public function search(string $query, int $page = 1, int $limit = 20): array
{
$filteredMangas = array_filter($this->mangas, function (Manga $manga) use ($query) {
$searchableFields = [
$manga->getTitle()->getValue(),
$manga->getSlug()->getValue(),
$manga->getAuthor(),
$manga->getDescription()
];
foreach ($searchableFields as $field) {
if (str_contains(strtolower($field), strtolower($query))) {
return true;
}
}
return false;
});
$sortedMangas = array_values($filteredMangas);
usort($sortedMangas, fn (Manga $a, Manga $b) => $a->getTitle()->getValue() <=> $b->getTitle()->getValue());
$offset = ($page - 1) * $limit;
return array_slice($sortedMangas, $offset, $limit);
}
public function countSearch(string $query): int
{
return count($this->search($query, 1, PHP_INT_MAX));
}
}