Enhance FetchGoldRates job to include update date and improve gold name formatting
- Added an 'Update_Date' field to store the current timestamp when fetching gold rates. - Refactored gold name formatting to ensure consistency by converting names to uppercase and replacing specific substrings with standardized abbreviations. - Improved maintainability by using a full name variable for gold types before abbreviation. These changes enhance the data structure and clarity of the gold rates fetched by the application.
This commit is contained in:
@@ -18,6 +18,7 @@ class FetchGoldRates implements ShouldQueue
|
|||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$data['Update_Date'] = now()->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
// Altın kurları
|
// Altın kurları
|
||||||
$goldResponse = $this->fetchData('https://altin.doviz.com');
|
$goldResponse = $this->fetchData('https://altin.doviz.com');
|
||||||
@@ -36,14 +37,15 @@ class FetchGoldRates implements ShouldQueue
|
|||||||
$valueGold = NumberFormatter::commaToDot($element->nodeValue);
|
$valueGold = NumberFormatter::commaToDot($element->nodeValue);
|
||||||
|
|
||||||
if (trim($attrGold) !== '') {
|
if (trim($attrGold) !== '') {
|
||||||
|
|
||||||
$nameGold = strtoupper(str_replace("-", "", $attrGold));
|
$nameGold = strtoupper(str_replace("-", "", $attrGold));
|
||||||
|
$fullNameGold = $nameGold;
|
||||||
$nameGold = str_replace("14", "OD", $nameGold);
|
$nameGold = str_replace("14", "OD", $nameGold);
|
||||||
$nameGold = str_replace("18", "OS", $nameGold);
|
$nameGold = str_replace("18", "OS", $nameGold);
|
||||||
$nameGold = str_replace("22", "YI", $nameGold);
|
$nameGold = str_replace("22", "YI", $nameGold);
|
||||||
$nameGold = str_replace("gram-altin", "GRA", $nameGold);
|
$nameGold = str_replace("GRAMALTIN", "GRA", $nameGold);
|
||||||
$nameGold = str_replace("gramaltin", "GRA", $nameGold);
|
$nameGold = str_replace("GRAMPLATIN", "GPL", $nameGold);
|
||||||
$nameGold = str_replace("gramplatin", "GPL", $nameGold);
|
$nameGold = str_replace("GRAMHASALTIN", "HAS", $nameGold);
|
||||||
$nameGold = str_replace("gramhasaltin", "HAS", $nameGold);
|
|
||||||
$nameGold = strtoupper(substr($nameGold, 0, 3));
|
$nameGold = strtoupper(substr($nameGold, 0, 3));
|
||||||
|
|
||||||
$except = ['USD', 'EUR', 'GBP', 'XU1', 'BIT'];
|
$except = ['USD', 'EUR', 'GBP', 'XU1', 'BIT'];
|
||||||
@@ -57,6 +59,7 @@ class FetchGoldRates implements ShouldQueue
|
|||||||
if ($typeGold == "c") $data[$nameGold]['Change'] = round((float)$valueGold,
|
if ($typeGold == "c") $data[$nameGold]['Change'] = round((float)$valueGold,
|
||||||
2);
|
2);
|
||||||
$data[$nameGold]['Type'] = "Gold";
|
$data[$nameGold]['Type'] = "Gold";
|
||||||
|
$data[$nameGold]['Name'] = $fullNameGold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user