diff --git a/cncnet-api/app/Http/Controllers/ApiLadderController.php b/cncnet-api/app/Http/Controllers/ApiLadderController.php index 79216517..4a993b7f 100755 --- a/cncnet-api/app/Http/Controllers/ApiLadderController.php +++ b/cncnet-api/app/Http/Controllers/ApiLadderController.php @@ -347,7 +347,7 @@ public function awardPoints($gameReport, $history) public function getAllLadders(Request $request) { - return $this->ladderService->getAllLadders(); + return $this->ladderService->getAllNonMigratedLadders(); } public function getCurrentLadders(Request $request) diff --git a/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php b/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php new file mode 100644 index 00000000..ae8149e3 --- /dev/null +++ b/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php @@ -0,0 +1,41 @@ +ladderService = new LadderService(); + } + + public function pingLadder(Request $request) + { + return "pong"; + } + + public function getLadder(Request $request, $game = null) + { + return $this->ladderService->getLadderByGameAbbreviation($game); + } + + public function getAllLadders(Request $request) + { + return $this->ladderService->getAllLadders(); + } + + public function getCurrentLadders(Request $request) + { + return $this->ladderService->getLadders(false); + } + + public function getLadderGame(Request $request, $game = null, $gameId = null) + { + return $this->ladderService->getLadderGameById($game, $gameId); + } +} diff --git a/cncnet-api/app/Http/Services/LadderService.php b/cncnet-api/app/Http/Services/LadderService.php index 355568f3..10937f4d 100755 --- a/cncnet-api/app/Http/Services/LadderService.php +++ b/cncnet-api/app/Http/Services/LadderService.php @@ -38,6 +38,30 @@ public function getAllLadders() return $ladders; } + /** + * Only return ladders that have not migrated to new client. Legacy QM client can pull ladders not yet migrated. + */ + public function getAllNonMigratedLadders() + { + $ladders = \App\Ladder::where('is_migrated_to_new_client', 0)->get(); + + foreach ($ladders as $ladder) + { + $ladder["sides"] = $ladder->sides()->get(); + $rules = $ladder->qmLadderRules; + + if ($rules !== null) + { + $ladder["vetoes"] = $rules->map_vetoes; + $ladder["allowed_sides"] = array_map('intval', explode(',', $rules->allowed_sides)); + } + $current = $this->getActiveLadderByDate(Carbon::now()->format('m-Y'), $ladder->abbreviation); + if ($current !== null) + $ladder["current"] = $current->short; + } + return $ladders; + } + public function getLadders($private = false) { $ladders = \App\Ladder::where('private', '=', $private)->get(); diff --git a/cncnet-api/app/Http/routes.php b/cncnet-api/app/Http/routes.php index 1ee58135..b45ed9f8 100755 --- a/cncnet-api/app/Http/routes.php +++ b/cncnet-api/app/Http/routes.php @@ -168,6 +168,12 @@ Route::get('/qm/ladder/{ladderAbbrev}/stats', 'ApiQuickMatchController@statsRequest'); }); +// Ladder Endpoints +Route::group(['prefix' => 'api/v2/ladder', 'middleware' => 'cache.long.public'], function () +{ + Route::get('/', 'ApiLadderController@getAllLadders'); +}); + // Ladder Endpoints Route::group(['prefix' => 'api/v1/ladder', 'middleware' => 'cache.long.public'], function () { diff --git a/cncnet-api/database/migrations/2022_11_04_231841_LadderColumnForNewApi.php b/cncnet-api/database/migrations/2022_11_04_231841_LadderColumnForNewApi.php new file mode 100644 index 00000000..e68084ca --- /dev/null +++ b/cncnet-api/database/migrations/2022_11_04_231841_LadderColumnForNewApi.php @@ -0,0 +1,40 @@ +tinyInteger("is_migrated_to_new_client")->default(0); + }); + + //migrate all ladders living inside of YR client + $migrate_ladders = ['yr', 'ra2', 'sfj', 'blitz', 'ra2-test', 'yr-test']; + + foreach ($migrate_ladders as $abbreviation) + { + $ladder = \App\Ladder::where('abbreviation', $abbreviation)->first(); + $ladder->is_migrated_to_new_client = 1; + $ladder->save(); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}