46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Features\Consoles\Data\ConsoleData;
|
|
use App\Features\Consoles\Models\Console;
|
|
use App\Features\Games\Data\DashboardStatsData;
|
|
use App\Features\Games\Data\GameData;
|
|
use App\Features\Games\Repositories\GameRepository;
|
|
use App\Features\Games\Repositories\RomFileRepository;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function __construct(
|
|
private GameRepository $gameRepository,
|
|
private RomFileRepository $romFileRepository
|
|
) {}
|
|
|
|
public function __invoke(Request $request): Response
|
|
{
|
|
$user = $request->user();
|
|
|
|
$stats = new DashboardStatsData(
|
|
totalGames: $this->gameRepository->count(),
|
|
totalConsoles: Console::count(),
|
|
totalRoms: $this->romFileRepository->count(),
|
|
userSaves: $user->saveFiles()->count(),
|
|
);
|
|
|
|
$recentGames = $this->gameRepository->getRecent(10)
|
|
->map(fn ($game) => GameData::fromModel($game));
|
|
|
|
$consoles = Console::withCount('games')->get()
|
|
->map(fn ($console) => ConsoleData::fromModel($console));
|
|
|
|
return Inertia::render('Dashboard/Index', [
|
|
'stats' => $stats,
|
|
'recentGames' => $recentGames,
|
|
'consoles' => $consoles,
|
|
]);
|
|
}
|
|
}
|