Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ladder client migration #127

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cncnet-api/app/Http/Controllers/ApiLadderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions cncnet-api/app/Http/Controllers/v2/ApiLadderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Controllers\v2;

use Illuminate\Http\Request;
use \App\Http\Services\LadderService;

class ApiLadderController extends Controller
{
private $ladderService;

public function __construct()
{
$this->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);
}
}
24 changes: 24 additions & 0 deletions cncnet-api/app/Http/Services/LadderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions cncnet-api/app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class LadderColumnForNewApi extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("ladders", function (Blueprint $table)
{
$table->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()
{
//
}
}