Files
finance/app/Http/Controllers/CurrencyController.php
T
Ümit Tunç de00f293c9 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.
2025-01-17 21:45:55 +03:00

38 lines
1.1 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 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);
}
}