From 40b7c65ae9868fa4a3603af91d3818993cb647ba Mon Sep 17 00:00:00 2001 From: alexp8 Date: Fri, 4 Nov 2022 19:32:54 -0400 Subject: [PATCH 1/2] ladder client migration --- .../Controllers/v2/ApiLadderController.php | 44 +++++++++++++++++++ .../app/Http/Services/LadderService.php | 24 ++++++++++ cncnet-api/app/Http/routes.php | 6 +++ ...022_11_04_231841_LadderColumnForNewApi.php | 40 +++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 cncnet-api/app/Http/Controllers/v2/ApiLadderController.php create mode 100644 cncnet-api/database/migrations/2022_11_04_231841_LadderColumnForNewApi.php 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..275d1b1e --- /dev/null +++ b/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php @@ -0,0 +1,44 @@ +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->getAllNonMigratedLadders(); + } + + 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() + { + // + } +} From 8fd30cb031862608bdd9431a074a925a189aaff8 Mon Sep 17 00:00:00 2001 From: alexp8 Date: Fri, 4 Nov 2022 19:38:10 -0400 Subject: [PATCH 2/2] commit --- cncnet-api/app/Http/Controllers/ApiLadderController.php | 2 +- cncnet-api/app/Http/Controllers/v2/ApiLadderController.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) 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 index 275d1b1e..ae8149e3 100644 --- a/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php +++ b/cncnet-api/app/Http/Controllers/v2/ApiLadderController.php @@ -4,9 +4,6 @@ use Illuminate\Http\Request; use \App\Http\Services\LadderService; -use \App\Http\Services\GameService; -use \App\Http\Services\PlayerService; -use \App\Http\Services\AuthService; class ApiLadderController extends Controller { @@ -29,7 +26,7 @@ public function getLadder(Request $request, $game = null) public function getAllLadders(Request $request) { - return $this->ladderService->getAllNonMigratedLadders(); + return $this->ladderService->getAllLadders(); } public function getCurrentLadders(Request $request)