diff --git a/thanasoft-back/app/Http/Controllers/Api/ClientGroupController.php b/thanasoft-back/app/Http/Controllers/Api/ClientGroupController.php index 4eec3fe..c60eb29 100644 --- a/thanasoft-back/app/Http/Controllers/Api/ClientGroupController.php +++ b/thanasoft-back/app/Http/Controllers/Api/ClientGroupController.php @@ -13,6 +13,7 @@ use App\Models\Client; use App\Repositories\ClientGroupRepositoryInterface; use Illuminate\Http\JsonResponse; use Illuminate\Http\Resources\Json\AnonymousResourceCollection; +use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\DB; @@ -27,10 +28,18 @@ class ClientGroupController extends Controller /** * Display a listing of client groups. */ - public function index(): AnonymousResourceCollection|JsonResponse + public function index(Request $request): AnonymousResourceCollection|JsonResponse { try { - $clientGroups = $this->clientGroupRepository->all(); + $perPage = (int) $request->get('per_page', 5); + $filters = array_filter([ + 'search' => $request->get('search'), + 'sort_by' => $request->get('sort_by', 'created_at'), + 'sort_direction' => $request->get('sort_direction', 'desc'), + ], static fn ($value) => $value !== null && $value !== ''); + + $clientGroups = $this->clientGroupRepository->paginate($perPage, $filters); + return ClientGroupResource::collection($clientGroups); } catch (\Exception $e) { Log::error('Error fetching client groups: ' . $e->getMessage(), [ diff --git a/thanasoft-back/app/Repositories/ClientGroupRepository.php b/thanasoft-back/app/Repositories/ClientGroupRepository.php index a703de8..9bed03e 100644 --- a/thanasoft-back/app/Repositories/ClientGroupRepository.php +++ b/thanasoft-back/app/Repositories/ClientGroupRepository.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Repositories; use App\Models\ClientGroup; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; class ClientGroupRepository extends BaseRepository implements ClientGroupRepositoryInterface { @@ -12,4 +13,22 @@ class ClientGroupRepository extends BaseRepository implements ClientGroupReposit { parent::__construct($model); } + + public function paginate(int $perPage = 15, array $filters = []): LengthAwarePaginator + { + $query = $this->model->newQuery()->withCount('clients'); + + if (!empty($filters['search'])) { + $query->where(function ($builder) use ($filters) { + $builder + ->where('name', 'like', '%' . $filters['search'] . '%') + ->orWhere('description', 'like', '%' . $filters['search'] . '%'); + }); + } + + $sortField = $filters['sort_by'] ?? 'created_at'; + $sortDirection = $filters['sort_direction'] ?? 'desc'; + + return $query->orderBy($sortField, $sortDirection)->paginate($perPage); + } } diff --git a/thanasoft-back/app/Repositories/ClientGroupRepositoryInterface.php b/thanasoft-back/app/Repositories/ClientGroupRepositoryInterface.php index 378dcc2..8cd3303 100644 --- a/thanasoft-back/app/Repositories/ClientGroupRepositoryInterface.php +++ b/thanasoft-back/app/Repositories/ClientGroupRepositoryInterface.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace App\Repositories; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; + interface ClientGroupRepositoryInterface extends BaseRepositoryInterface { - // Add ClientGroup-specific methods here later if needed + public function paginate(int $perPage = 15, array $filters = []): LengthAwarePaginator; } diff --git a/thanasoft-back/database/seeders/ClientGroupSeeder.php b/thanasoft-back/database/seeders/ClientGroupSeeder.php new file mode 100644 index 0000000..db17be4 --- /dev/null +++ b/thanasoft-back/database/seeders/ClientGroupSeeder.php @@ -0,0 +1,34 @@ + $group, + 'description' => $faker->sentence, + 'price_list_id' => null, // volontairement null + ]); + } + } +} \ No newline at end of file diff --git a/thanasoft-front/src/components/Organism/CRM/lieux/ListeLieuxPresentation.vue b/thanasoft-front/src/components/Organism/CRM/lieux/ListeLieuxPresentation.vue index d6cb9a2..24149a2 100644 --- a/thanasoft-front/src/components/Organism/CRM/lieux/ListeLieuxPresentation.vue +++ b/thanasoft-front/src/components/Organism/CRM/lieux/ListeLieuxPresentation.vue @@ -13,8 +13,7 @@ [], }, - currentPage: { - type: Number, - default: 1, - }, - perPage: { - type: Number, - default: 10, + pagination: { + type: Object, + default: () => ({ + current_page: 1, + last_page: 1, + per_page: 10, + total: 0, + from: 0, + to: 0, + }), }, }); diff --git a/thanasoft-front/src/components/Organism/ClientGroup/ClientGroupListPresentation.vue b/thanasoft-front/src/components/Organism/ClientGroup/ClientGroupListPresentation.vue index fd36e3d..ae94eab 100644 --- a/thanasoft-front/src/components/Organism/ClientGroup/ClientGroupListPresentation.vue +++ b/thanasoft-front/src/components/Organism/ClientGroup/ClientGroupListPresentation.vue @@ -1,29 +1,41 @@ diff --git a/thanasoft-front/src/components/molecules/Tables/ClientGroup/ClientGroupTable.vue b/thanasoft-front/src/components/molecules/Tables/ClientGroup/ClientGroupTable.vue index 07bc1fb..77da255 100644 --- a/thanasoft-front/src/components/molecules/Tables/ClientGroup/ClientGroupTable.vue +++ b/thanasoft-front/src/components/molecules/Tables/ClientGroup/ClientGroupTable.vue @@ -1,151 +1,166 @@ + + diff --git a/thanasoft-front/src/components/molecules/location/LocationTable.vue b/thanasoft-front/src/components/molecules/location/LocationTable.vue index 0c25bc7..fef35a8 100644 --- a/thanasoft-front/src/components/molecules/location/LocationTable.vue +++ b/thanasoft-front/src/components/molecules/location/LocationTable.vue @@ -1,31 +1,30 @@