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.
This commit is contained in:
Ümit Tunç
2025-01-17 21:45:55 +03:00
parent c630e1ada6
commit de00f293c9
@@ -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);
}
}