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:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user