de00f293c9
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.
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Jobs\FetchCurrencyRates;
|
||
use Illuminate\Support\Facades\Storage;
|
||
|
||
class CurrencyController extends Controller
|
||
{
|
||
public function getCurrentRates()
|
||
{
|
||
// Job'ı çalıştır
|
||
// $data = FetchCurrencyRates::dispatchSync();
|
||
|
||
// JSON dosyasından oku
|
||
if (Storage::exists('currency/today.json')) {
|
||
return response()->json(
|
||
json_decode(Storage::get('currency/today.json'), true)
|
||
);
|
||
}
|
||
|
||
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);
|
||
}
|
||
} |