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:
Ümit Tunç
2025-01-21 22:29:08 +03:00
parent a46f286ce2
commit 9409a4dbd9
+11 -10
View File
@@ -4,8 +4,8 @@ namespace App\Http\Controllers;
use App\Jobs\FetchCurrencyRates;
use App\Jobs\FetchGoldRates;
use App\Jobs\MergeCurrencyAndGoldRates;
use App\Jobs\FetchCryptoCurrencyRates;
use App\Jobs\MergeCurrencyAndGoldRates;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\Controller;
@@ -28,14 +28,15 @@ class CurrencyController extends Controller
public function runAllFetchs()
{
try {
FetchCryptoCurrencyRates::dispatchSync();
FetchCurrencyRates::dispatchSync();
FetchGoldRates::dispatchSync();
FetchCryptoCurrencyRates::dispatchSync();
MergeCurrencyAndGoldRates::dispatchSync();
return response()->json([
'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) {
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
*/
@@ -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(['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(['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(['error' => 'Veri bulunamadı'], 404);
return response()->json(['error' => 'Data not found'], 404);
}
/**
@@ -236,9 +237,9 @@ class CurrencyController extends Controller
if (isset($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);
}
}