From 94064b27c31ca7ba37c71bd6c0d21fc99d553100 Mon Sep 17 00:00:00 2001 From: ykiakao Date: Thu, 21 May 2026 13:22:17 -0500 Subject: [PATCH] Restore platform route and db diagnostics --- app/Http/Controllers/GameController.php | 13 ++++++++++++ config/database.php | 6 +++++- routes/api.php | 22 +++++++++++++++++++ routes/web.php | 28 +++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/GameController.php b/app/Http/Controllers/GameController.php index fe023cf..6e55591 100644 --- a/app/Http/Controllers/GameController.php +++ b/app/Http/Controllers/GameController.php @@ -53,6 +53,19 @@ class GameController extends Controller return response()->json($games); } + /** + * Ranking por plataforma + */ + public function platformRanking($platform) + { + $games = Game::where('platform', $platform) + ->orderBy('weekly_points', 'desc') + ->take(10) + ->get(); + + return response()->json($games); + } + /** * Histórico de ranking * diff --git a/config/database.php b/config/database.php index 3dcbec4..e5c07ab 100644 --- a/config/database.php +++ b/config/database.php @@ -15,7 +15,11 @@ return [ | */ - 'default' => env('DB_CONNECTION', 'mysql'), + 'default' => env('DB_CONNECTION') ?: ( + str_starts_with((string) env('DATABASE_URL'), 'postgres') + ? 'pgsql' + : 'mysql' + ), /* |-------------------------------------------------------------------------- diff --git a/routes/api.php b/routes/api.php index a1a9557..6300234 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,8 @@ middleware(['jwt.auth'])->group(function () { Route::get('/rankings/monthly', [GameController::class, 'monthlyRanking']); Route::get('/rankings/yearly', [GameController::class, 'yearlyRanking']); Route::get('/rankings/history/{id}', [GameController::class, 'history']); + Route::get('/rankings/platforms/{platform}', [GameController::class, 'platformRanking']); // Jogos Route::get('/games/most-played', [GameController::class, 'mostPlayed']); @@ -37,3 +40,22 @@ Route::get('/health-check-key', function () { 'openssl_error' => openssl_error_string(), ]); }); + +Route::get('/health-check-db', function () { + try { + $hasGamesTable = Schema::hasTable('games'); + + return response()->json([ + 'connection' => config('database.default'), + 'driver' => DB::connection()->getDriverName(), + 'database' => DB::connection()->getDatabaseName(), + 'games_table_exists' => $hasGamesTable, + 'games_count' => $hasGamesTable ? DB::table('games')->count() : null, + ]); + } catch (Throwable $e) { + return response()->json([ + 'connection' => config('database.default'), + 'error' => $e->getMessage(), + ], 500); + } +}); diff --git a/routes/web.php b/routes/web.php index 1c715bc..f260cea 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,15 @@ json([ + 'status' => 'ok', + 'service' => 'api-ranking-jogos', + ]); +}); Route::get('/health', function () { return response()->json(['status' => 'ok']); @@ -18,3 +27,22 @@ Route::get('/health-check-key', function () { 'openssl_error' => openssl_error_string(), ]); }); + +Route::get('/health-check-db', function () { + try { + $hasGamesTable = Schema::hasTable('games'); + + return response()->json([ + 'connection' => config('database.default'), + 'driver' => DB::connection()->getDriverName(), + 'database' => DB::connection()->getDatabaseName(), + 'games_table_exists' => $hasGamesTable, + 'games_count' => $hasGamesTable ? DB::table('games')->count() : null, + ]); + } catch (Throwable $e) { + return response()->json([ + 'connection' => config('database.default'), + 'error' => $e->getMessage(), + ], 500); + } +});