refactor search functionality; remove deprecated services and implement new action and task classes for improved structure and maintainability

This commit is contained in:
F4ilji
2025-07-18 14:14:10 +05:00
parent 0874d3e6b5
commit b8235404b8
20 changed files with 525 additions and 440 deletions
@@ -0,0 +1,27 @@
<?php
namespace App\Containers\Search\Tasks;
class PaginateSearchResultsTask
{
public function run(array $results, int $page, int $perPage, ?array $categories): array
{
$total = count($results);
$lastPage = max(1, ceil($total / $perPage));
$page = max(1, min($page, $lastPage));
$offset = ($page - 1) * $perPage;
$paginatedResults = array_slice($results, $offset, $perPage);
return [
'data' => $paginatedResults,
'meta' => [
'current_page' => $page,
'total' => $total,
'per_page' => $perPage,
'last_page' => $lastPage
],
'categories' => $categories
];
}
}