Skip to content

Commit

Permalink
refactor: migrate the Random Set route to a controller method (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland authored Sep 2, 2024
1 parent 0088e4e commit 3c9ae47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
13 changes: 13 additions & 0 deletions app/Platform/Controllers/GameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Http\Controller;
use App\Models\Game;
use App\Models\System;
use App\Platform\Requests\GameRequest;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -106,4 +107,16 @@ public function destroy(Game $game): void
{
$this->authorize('delete', $game);
}

public function random(): RedirectResponse
{
$this->authorize('viewAny', Game::class);

$randomGameWithAchievements = Game::whereNotIn('ConsoleID', System::getNonGameSystems())
->where('achievements_published', '>=', 6)
->inRandomOrder()
->firstOrFail();

return redirect(route('game.show', ['game' => $randomGameWithAchievements]));
}
}
2 changes: 2 additions & 0 deletions app/Platform/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Models\GameHash;
use App\Platform\Controllers\AchievementController;
use App\Platform\Controllers\GameController;
use App\Platform\Controllers\GameHashController;
use App\Platform\Controllers\PlayerAchievementController;
use App\Platform\Controllers\PlayerGameController;
Expand Down Expand Up @@ -63,6 +64,7 @@ protected function mapWebRoutes(): void
// Route::get('game/{game}/badges', [GameBadgeController::class, 'index'])->name('game.badge.index');
// Route::get('game/{game}/assets', [GameAssetsController::class, 'index'])->name('game.asset.index');
// Route::get('game/{game}/players', [GamePlayerController::class, 'index'])->name('game.player.index');
Route::get('game/random', [GameController::class, 'random'])->name('game.random');

// Route::get('create', CreateController::class)->name('create');
// Route::resource('developers', DeveloperController::class)->only('index');
Expand Down
23 changes: 0 additions & 23 deletions resources/views/pages/game/random.blade.php

This file was deleted.

0 comments on commit 3c9ae47

Please sign in to comment.