clientLocationRepository->all(); return ClientLocationResource::collection($clientLocations); } catch (\Exception $e) { Log::error('Error fetching client locations: ' . $e->getMessage(), [ 'exception' => $e, 'trace' => $e->getTraceAsString(), ]); return response()->json([ 'message' => 'Une erreur est survenue lors de la récupération des lieux clients.', 'error' => config('app.debug') ? $e->getMessage() : null, ], 500); } } /** * Store a newly created client location. */ public function store(StoreClientLocationRequest $request): ClientLocationResource|JsonResponse { try { $clientLocation = $this->clientLocationRepository->create($request->validated()); return new ClientLocationResource($clientLocation); } catch (\Exception $e) { Log::error('Error creating client location: ' . $e->getMessage(), [ 'exception' => $e, 'trace' => $e->getTraceAsString(), 'data' => $request->validated(), ]); return response()->json([ 'message' => 'Une erreur est survenue lors de la création du lieu client.', 'error' => config('app.debug') ? $e->getMessage() : null, ], 500); } } /** * Display the specified client location. */ public function show(string $id): ClientLocationResource|JsonResponse { try { $clientLocation = $this->clientLocationRepository->find($id); if (!$clientLocation) { return response()->json([ 'message' => 'Lieu client non trouvé.', ], 404); } return new ClientLocationResource($clientLocation); } 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); } } /** * Update the specified client location. */ public function update(UpdateClientLocationRequest $request, string $id): ClientLocationResource|JsonResponse { try { $updated = $this->clientLocationRepository->update($id, $request->validated()); if (!$updated) { return response()->json([ 'message' => 'Lieu client non trouvé ou échec de la mise à jour.', ], 404); } $clientLocation = $this->clientLocationRepository->find($id); return new ClientLocationResource($clientLocation); } catch (\Exception $e) { Log::error('Error updating client location: ' . $e->getMessage(), [ 'exception' => $e, 'trace' => $e->getTraceAsString(), 'client_location_id' => $id, 'data' => $request->validated(), ]); return response()->json([ 'message' => 'Une erreur est survenue lors de la mise à jour du lieu client.', 'error' => config('app.debug') ? $e->getMessage() : null, ], 500); } } /** * Remove the specified client location. */ public function destroy(string $id): JsonResponse { try { $deleted = $this->clientLocationRepository->delete($id); if (!$deleted) { return response()->json([ 'message' => 'Lieu client non trouvé ou échec de la suppression.', ], 404); } return response()->json([ 'message' => 'Lieu client supprimé avec succès.', ], 200); } catch (\Exception $e) { Log::error('Error deleting client location: ' . $e->getMessage(), [ 'exception' => $e, 'trace' => $e->getTraceAsString(), 'client_location_id' => $id, ]); return response()->json([ 'message' => 'Une erreur est survenue lors de la suppression du lieu client.', 'error' => config('app.debug') ? $e->getMessage() : null, ], 500); } } }