diff --git a/app/Http/Controllers/CurrencyController.php b/app/Http/Controllers/CurrencyController.php index b34bd83..7dc5c42 100644 --- a/app/Http/Controllers/CurrencyController.php +++ b/app/Http/Controllers/CurrencyController.php @@ -9,7 +9,15 @@ use Illuminate\Support\Facades\Storage; class CurrencyController extends Controller { - public function getCurrentRates() + + public function runAllFetchs() + { + FetchCurrencyRates::dispatchSync(); + FetchGoldRates::dispatchSync(); + MergeCurrencyAndGoldRates::dispatchSync(); + } + + public function getAllRates() { // Job'ı çalıştır /* @@ -18,9 +26,36 @@ class CurrencyController extends Controller MergeCurrencyAndGoldRates::dispatchSync(); */ // JSON dosyasından oku - if (Storage::exists('merged/rates.json')) { + $jsonFile = 'merged/rates.json'; + if (Storage::exists($jsonFile)) { return response()->json( - json_decode(Storage::get('merged/rates.json'), true) + json_decode(Storage::get($jsonFile), true) + ); + } + + return response()->json(['error' => 'Veri bulunamadı'], 404); + } + + public function getCurrentRates() + { + // JSON dosyasından oku + $jsonFile = 'currency/today.json'; + if (Storage::exists($jsonFile)) { + return response()->json( + json_decode(Storage::get($jsonFile), true) + ); + } + + return response()->json(['error' => 'Veri bulunamadı'], 404); + } + + public function getGoldRates() + { + // JSON dosyasından oku + $jsonFile = 'gold/today.json'; + if (Storage::exists($jsonFile)) { + return response()->json( + json_decode(Storage::get($jsonFile), true) ); } @@ -30,14 +65,30 @@ class CurrencyController extends Controller public function getCurrencyRateByName($currencyName) { // JSON dosyasından oku - if (Storage::exists('currency/today.json')) { - $data = json_decode(Storage::get('currency/today.json'), true); + $jsonFile = 'currency/today.json'; + if (Storage::exists($jsonFile)) { + $data = json_decode(Storage::get($jsonFile), true); if (isset($data[$currencyName])) { return response()->json([$currencyName => $data[$currencyName]]); } - return response()->json(['error' => 'Para birimi bulunamadı'], 404); + return response()->json(['error' => 'Currency not found'], 404); } - return response()->json(['error' => 'Veri bulunamadı'], 404); + return response()->json(['error' => 'Data not found'], 404); + } + + public function getGoldRateByName($goldName) + { + // JSON dosyasından oku + $jsonFile = 'gold/today.json'; + if (Storage::exists($jsonFile)) { + $data = json_decode(Storage::get($jsonFile), true); + if (isset($data[$goldName])) { + return response()->json([$goldName => $data[$goldName]]); + } + return response()->json(['error' => 'Currency not found'], 404); + } + + return response()->json(['error' => 'Data not found'], 404); } } \ No newline at end of file