First commit
This commit is contained in:
54
app/Http/Controllers/Admin/DashboardController.php
Normal file
54
app/Http/Controllers/Admin/DashboardController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\AuditLog;
|
||||
use App\Models\Category;
|
||||
use App\Models\ChatLog;
|
||||
use App\Models\Document;
|
||||
use App\Models\DocumentVersion;
|
||||
use App\Models\KnowledgeItem;
|
||||
use App\Services\Ollama\OllamaService;
|
||||
use App\Services\Qdrant\QdrantService;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index(
|
||||
OllamaService $ollamaService,
|
||||
QdrantService $qdrantService
|
||||
): View {
|
||||
$stats = [
|
||||
'total_documents' => Document::count(),
|
||||
'active_documents' => Document::where('is_active', true)->count(),
|
||||
'processing_documents' => Document::where('status', 'processing')->count(),
|
||||
'failed_documents' => Document::whereIn('status', ['failed', 'extraction_failed'])->count(),
|
||||
'total_categories' => Category::where('is_active', true)->count(),
|
||||
'total_knowledge_items' => KnowledgeItem::where('is_active', true)->count(),
|
||||
'total_chats_today' => ChatLog::whereDate('created_at', today())->count(),
|
||||
'unanswered_chats' => ChatLog::where('has_answer', false)->count(),
|
||||
'flagged_chats' => ChatLog::where('is_flagged', true)->count(),
|
||||
];
|
||||
|
||||
$recentActivity = AuditLog::with('user')
|
||||
->latest('created_at')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$recentChats = ChatLog::with('category')
|
||||
->latest()
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
// Health check (cache 60 saat supaya tidak lambat setiap load)
|
||||
$health = cache()->remember('service_health', 60, function () use ($ollamaService, $qdrantService) {
|
||||
return [
|
||||
'ollama' => $ollamaService->healthCheck(),
|
||||
'qdrant' => $qdrantService->healthCheck(),
|
||||
];
|
||||
});
|
||||
|
||||
return view('admin.dashboard', compact('stats', 'recentActivity', 'recentChats', 'health'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user