Files
finance/app/Http/Controllers/CurrencyController.php
T
Ümit Tunç aa03ed3706 Integrate FetchGoldRates and MergeCurrencyAndGoldRates jobs in CurrencyController
- 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.
2025-01-17 22:59:11 +03:00

43 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);
}
}