First Commit
This commit is contained in:
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AiProvider;
|
||||
use App\Services\PromptGenerationService;
|
||||
use App\Services\PromptProjectService;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PromptProjectService $promptProjectService,
|
||||
private readonly PromptGenerationService $promptGenerationService
|
||||
) {}
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
$userId = auth()->id();
|
||||
$user = auth()->user();
|
||||
|
||||
$stats = [
|
||||
'projects' => $this->promptProjectService->index()['total'] ?? 0,
|
||||
'generations' => $this->promptGenerationService->index()->total() ?? 0,
|
||||
'providers' => AiProvider::count(),
|
||||
'tokens' => $user && $user->role === 'superadmin'
|
||||
? \App\Models\PromptGeneration::sum('tokens_used') ?? 0
|
||||
: \App\Models\PromptGeneration::where('user_id', $userId)->sum('tokens_used') ?? 0,
|
||||
];
|
||||
|
||||
$recentGenerationsQuery = \App\Models\PromptGeneration::with(['project', 'model'])
|
||||
->latest()
|
||||
->limit(5);
|
||||
|
||||
if (!$user || $user->role !== 'superadmin') {
|
||||
$recentGenerationsQuery->where('user_id', $userId);
|
||||
}
|
||||
|
||||
$recentGenerations = $recentGenerationsQuery->get();
|
||||
|
||||
return view('dashboard', compact('stats', 'recentGenerations'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user