feat: ajout d'une route GetMangaByIdHandler.php et fix de la SearchBar.vue
This commit is contained in:
parent
ed0a075a6c
commit
d9e935f7de
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user