From de00f293c93698647162b33ed29aeeff16fc6289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Fri, 17 Jan 2025 21:45:55 +0300 Subject: [PATCH] Add method to retrieve currency rate by name in CurrencyController Implemented a new method `getCurrencyRateByName` in the CurrencyController to fetch the currency rate based on the provided currency name from a JSON file. The method handles cases where the file does not exist or the currency is not found, returning appropriate JSON responses for each scenario. --- app/Http/Controllers/CurrencyController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index 7f02a45..05bb80c 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -21,4 +21,18 @@ class CurrencyController extends Controller return response()->json(['error' => 'Veri bulunamadı'], 404); } + + public function getCurrencyRateByName($currencyName) + { + // JSON dosyasından oku + if (Storage::exists('currency/today.json')) { + $data = json_decode(Storage::get('currency/today.json'), true); + if (isset($data[$currencyName])) { + return response()->json([$currencyName => $data[$currencyName]]); + } + return response()->json(['error' => 'Para birimi bulunamadı'], 404); + } + + return response()->json(['error' => 'Veri bulunamadı'], 404); + } } \ No newline at end of file