Implement crypto currency rates feature and enhance API responses
- Added a new job to fetch crypto currency rates from an external source and store them in a JSON file. - Updated the CurrencyController to include methods for retrieving current crypto currency rates and rates by name. - Enhanced the API to return detailed metadata for crypto currency rates, including timestamps and update information. - Updated the API routes to support new endpoints for crypto currency rates. - Modified the merged rates JSON to include crypto currency data alongside existing currency and gold rates. - Improved the welcome view to display additional crypto currency information, enhancing user experience. These changes collectively expand the functionality of the Truncgil Finance application, providing users with comprehensive access to crypto currency data.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Jobs\FetchCurrencyRates;
|
||||
use App\Jobs\FetchGoldRates;
|
||||
use App\Jobs\MergeCurrencyAndGoldRates;
|
||||
use App\Jobs\FetchCryptoCurrencyRates;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
@@ -27,6 +28,7 @@ class CurrencyController extends Controller
|
||||
public function runAllFetchs()
|
||||
{
|
||||
try {
|
||||
FetchCryptoCurrencyRates::dispatchSync();
|
||||
FetchCurrencyRates::dispatchSync();
|
||||
FetchGoldRates::dispatchSync();
|
||||
MergeCurrencyAndGoldRates::dispatchSync();
|
||||
@@ -50,28 +52,28 @@ class CurrencyController extends Controller
|
||||
*/
|
||||
public function getAllRates()
|
||||
{
|
||||
// JSON dosyasından oku
|
||||
$jsonFile = 'merged/rates.json';
|
||||
$jsonFile = 'merged/rates.json';
|
||||
|
||||
if (Storage::exists($jsonFile)) {
|
||||
$data = json_decode(Storage::get($jsonFile), true);
|
||||
$currentDate = now(); // Şu anki tarih
|
||||
$currentDate = now();
|
||||
$updateDate = isset($data['Update_Date']) ? \Carbon\Carbon::parse($data['Update_Date']) : null;
|
||||
|
||||
if ($updateDate) {
|
||||
$minutesAgo = round($currentDate->diffInMinutes($updateDate), 2); // Kaç dakika önce alındığı
|
||||
$metaData = [ // Tarih bilgileri için alt dizi
|
||||
$minutesAgo = round($currentDate->diffInMinutes($updateDate), 2);
|
||||
$metaData = [
|
||||
'Minutes_Ago' => $minutesAgo,
|
||||
'Current_Date' => $currentDate->toDateTimeString(),
|
||||
'Update_Date' => $updateDate->toDateTimeString(), // Update_Date burada kalacak
|
||||
'Update_Date' => $updateDate->toDateTimeString(),
|
||||
];
|
||||
unset($data['Update_Date']); // Rates içerisindeki Update_Date elemanını kaldır
|
||||
unset($data['Update_Date']);
|
||||
$data = [
|
||||
'Meta_Data' => $metaData, // Tarih bilgileri alt dizisi
|
||||
'Rates' => $data, // Kur bilgileri alt dizisi
|
||||
'Meta_Data' => $metaData,
|
||||
'Rates' => $data
|
||||
];
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
||||
@@ -145,6 +147,39 @@ class CurrencyController extends Controller
|
||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* ₿ Retrieves the current crypto currency rates
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getCryptoCurrencyRates()
|
||||
{
|
||||
$jsonFile = 'crypto/today.json';
|
||||
if (Storage::exists($jsonFile)) {
|
||||
$data = json_decode(Storage::get($jsonFile), true);
|
||||
$currentDate = now();
|
||||
$updateDate = isset($data['Update_Date']) ? \Carbon\Carbon::parse($data['Update_Date']) : null;
|
||||
|
||||
if ($updateDate) {
|
||||
$minutesAgo = round($currentDate->diffInMinutes($updateDate), 2);
|
||||
$metaData = [
|
||||
'Minutes_Ago' => $minutesAgo,
|
||||
'Current_Date' => $currentDate->toDateTimeString(),
|
||||
'Update_Date' => $updateDate->toDateTimeString(),
|
||||
];
|
||||
unset($data['Update_Date']);
|
||||
$data = [
|
||||
'Meta_Data' => $metaData,
|
||||
'Rates' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 🟰 💵 Retrieves the currency rate by its name
|
||||
*
|
||||
@@ -186,4 +221,24 @@ class CurrencyController extends Controller
|
||||
|
||||
return response()->json(['error' => 'Data not found'], 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* 🟰 ₿ Retrieves the crypto currency rate by its name
|
||||
*
|
||||
* @param string $cryptoCurrencyName
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function getCryptoCurrencyRateByName($cryptoCurrencyName)
|
||||
{
|
||||
$jsonFile = 'crypto/today.json';
|
||||
if (Storage::exists($jsonFile)) {
|
||||
$data = json_decode(Storage::get($jsonFile), true);
|
||||
if (isset($data[$cryptoCurrencyName])) {
|
||||
return response()->json([$cryptoCurrencyName => $data[$cryptoCurrencyName]]);
|
||||
}
|
||||
return response()->json(['error' => 'Kripto para birimi bulunamadı'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user