add location

This commit is contained in:
Nyavokevin 2025-10-21 12:37:36 +03:00
parent e2cb4499bb
commit 78700a3c5a
4 changed files with 32 additions and 2 deletions

View File

@ -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.
*/

View File

@ -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();
}
}

View File

@ -6,5 +6,5 @@ namespace App\Repositories;
interface ClientLocationRepositoryInterface extends BaseRepositoryInterface
{
// Add ClientLocation-specific methods here later if needed
function getByClientId(int $client_id);
}

View File

@ -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);