From 78700a3c5af131652167bfad09470568025a4454 Mon Sep 17 00:00:00 2001 From: Nyavokevin <42602932+nyavokevin@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:37:36 +0300 Subject: [PATCH] add location --- .../Api/ClientLocationController.php | 22 +++++++++++++++++++ .../Repositories/ClientLocationRepository.php | 7 ++++++ .../ClientLocationRepositoryInterface.php | 2 +- thanasoft-back/routes/api.php | 3 ++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/thanasoft-back/app/Http/Controllers/Api/ClientLocationController.php b/thanasoft-back/app/Http/Controllers/Api/ClientLocationController.php index f10614f..3189d6c 100644 --- a/thanasoft-back/app/Http/Controllers/Api/ClientLocationController.php +++ b/thanasoft-back/app/Http/Controllers/Api/ClientLocationController.php @@ -63,6 +63,28 @@ class ClientLocationController extends Controller } } + /** + * Display the specified client id. + */ + public function getLocationsByClient(string $id) + { + try { + $clientLocations = $this->clientLocationRepository->getByClientId((int)$id); + return ClientLocationResource::collection($clientLocations); + } catch (\Exception $e) { + Log::error('Error fetching client location: ' . $e->getMessage(), [ + 'exception' => $e, + 'trace' => $e->getTraceAsString(), + 'client_location_id' => $id, + ]); + + return response()->json([ + 'message' => 'Une erreur est survenue lors de la récupération du lieu client.', + 'error' => config('app.debug') ? $e->getMessage() : null, + ], 500); + } + } + /** * Display the specified client location. */ diff --git a/thanasoft-back/app/Repositories/ClientLocationRepository.php b/thanasoft-back/app/Repositories/ClientLocationRepository.php index e16fec1..eb4032e 100644 --- a/thanasoft-back/app/Repositories/ClientLocationRepository.php +++ b/thanasoft-back/app/Repositories/ClientLocationRepository.php @@ -12,4 +12,11 @@ class ClientLocationRepository extends BaseRepository implements ClientLocationR { parent::__construct($model); } + + public function getByClientId(int $client_id) + { + $query = $this->model->newQuery(); + $query->where('client_id', $client_id); + return $query->get(); + } } diff --git a/thanasoft-back/app/Repositories/ClientLocationRepositoryInterface.php b/thanasoft-back/app/Repositories/ClientLocationRepositoryInterface.php index e546521..55621a4 100644 --- a/thanasoft-back/app/Repositories/ClientLocationRepositoryInterface.php +++ b/thanasoft-back/app/Repositories/ClientLocationRepositoryInterface.php @@ -6,5 +6,5 @@ namespace App\Repositories; interface ClientLocationRepositoryInterface extends BaseRepositoryInterface { - // Add ClientLocation-specific methods here later if needed + function getByClientId(int $client_id); } diff --git a/thanasoft-back/routes/api.php b/thanasoft-back/routes/api.php index 7fdde85..da3c407 100644 --- a/thanasoft-back/routes/api.php +++ b/thanasoft-back/routes/api.php @@ -39,8 +39,9 @@ Route::middleware('auth:sanctum')->group(function () { Route::apiResource('clients', ClientController::class); Route::apiResource('client-groups', ClientGroupController::class); - Route::apiResource('client-locations', ClientLocationController::class); + Route::apiResource('client-locations', ClientLocationController::class); + Route::get('clients/{clientId}/locations', [ClientLocationController::class, 'getLocationsByClient']); // Contact management Route::apiResource('contacts', ContactController::class);