aa03ed3706
- Added the `FetchGoldRates` job to retrieve gold rates and the `MergeCurrencyAndGoldRates` job to combine currency and gold rates. - Updated the `getCurrentRates` method to read from a new JSON file `merged/rates.json` instead of the previous `currency/today.json`. - Commented out the synchronous dispatch of the fetching jobs for future implementation. This commit enhances the CurrencyController's functionality by preparing it for integrated financial data management.
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers;
|
||
|
||
use App\Jobs\FetchCurrencyRates;
|
||
use App\Jobs\FetchGoldRates;
|
||
use App\Jobs\MergeCurrencyAndGoldRates;
|
||
use Illuminate\Support\Facades\Storage;
|
||
|
||
class CurrencyController extends Controller
|
||
{
|
||
public function getCurrentRates()
|
||
{
|
||
// Job'ı çalıştır
|
||
/*
|
||
FetchCurrencyRates::dispatchSync();
|
||
FetchGoldRates::dispatchSync();
|
||
MergeCurrencyAndGoldRates::dispatchSync();
|
||
*/
|
||
// JSON dosyasından oku
|
||
if (Storage::exists('merged/rates.json')) {
|
||
return response()->json(
|
||
json_decode(Storage::get('merged/rates.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);
|
||
}
|
||
} |