Refactor CurrencyController to improve error handling and update messages
- Reordered the dispatching of jobs in the runAllFetchs method to ensure proper execution sequence. - Updated API response messages from Turkish to English for consistency and clarity. - Enhanced error messages for data retrieval failures to provide clearer feedback to users. - Improved documentation comments to reflect the changes in functionality. These changes collectively enhance the usability and clarity of the CurrencyController in the Truncgil Finance application.
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Jobs\FetchCurrencyRates;
|
use App\Jobs\FetchCurrencyRates;
|
||||||
use App\Jobs\FetchGoldRates;
|
use App\Jobs\FetchGoldRates;
|
||||||
use App\Jobs\MergeCurrencyAndGoldRates;
|
|
||||||
use App\Jobs\FetchCryptoCurrencyRates;
|
use App\Jobs\FetchCryptoCurrencyRates;
|
||||||
|
use App\Jobs\MergeCurrencyAndGoldRates;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
@@ -28,14 +28,15 @@ class CurrencyController extends Controller
|
|||||||
public function runAllFetchs()
|
public function runAllFetchs()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
FetchCryptoCurrencyRates::dispatchSync();
|
|
||||||
FetchCurrencyRates::dispatchSync();
|
FetchCurrencyRates::dispatchSync();
|
||||||
FetchGoldRates::dispatchSync();
|
FetchGoldRates::dispatchSync();
|
||||||
|
FetchCryptoCurrencyRates::dispatchSync();
|
||||||
MergeCurrencyAndGoldRates::dispatchSync();
|
MergeCurrencyAndGoldRates::dispatchSync();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'message' => 'Tüm döviz ve altın kurları başarıyla güncellendi'
|
'message' => 'All currency and gold rates have been successfully updated'
|
||||||
]);
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -46,7 +47,7 @@ class CurrencyController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 🪙 💵 Retrieves all gold and currency rates
|
* 🪙 💵 ₿ Retrieves all gold and currency rates
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
@@ -76,7 +77,7 @@ class CurrencyController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
return response()->json(['error' => 'Data not found'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +111,7 @@ class CurrencyController extends Controller
|
|||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
return response()->json(['error' => 'Data not found'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +145,7 @@ class CurrencyController extends Controller
|
|||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
return response()->json(['error' => 'Data not found'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -177,7 +178,7 @@ class CurrencyController extends Controller
|
|||||||
return response()->json($data);
|
return response()->json($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
return response()->json(['error' => 'Data not found'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,9 +237,9 @@ class CurrencyController extends Controller
|
|||||||
if (isset($data[$cryptoCurrencyName])) {
|
if (isset($data[$cryptoCurrencyName])) {
|
||||||
return response()->json([$cryptoCurrencyName => $data[$cryptoCurrencyName]]);
|
return response()->json([$cryptoCurrencyName => $data[$cryptoCurrencyName]]);
|
||||||
}
|
}
|
||||||
return response()->json(['error' => 'Kripto para birimi bulunamadı'], 404);
|
return response()->json(['error' => 'Cryptocurrency not found'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['error' => 'Veri bulunamadı'], 404);
|
return response()->json(['error' => 'Data not found'], 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user