using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc.RazorPages; using QuantEngine.Core.Interfaces; using QuantEngine.Web.Services; namespace QuantEngine.Web.Pages.Admin.Dashboard; [Authorize(AuthenticationSchemes = AdminAuthDefaults.Scheme)] public class IndexModel : PageModel { private readonly IWorkspaceRepository _workspaceRepository; private readonly ICollectionRepository _collectionRepository; private readonly IWebHostEnvironment _environment; private readonly ILogger _logger; public int? ActiveUsersCount { get; set; } public int? RecentRunsCount { get; set; } public bool IsDatabaseConnected { get; set; } public string EnvironmentName => _environment.EnvironmentName; public IndexModel( IWorkspaceRepository workspaceRepository, ICollectionRepository collectionRepository, IWebHostEnvironment environment, ILogger logger) { _workspaceRepository = workspaceRepository; _collectionRepository = collectionRepository; _environment = environment; _logger = logger; } public async Task OnGetAsync() { try { var accounts = await _workspaceRepository.GetAccountsAsync(); ActiveUsersCount = accounts.Count(a => string.Equals(a.IsActive, "true", StringComparison.OrdinalIgnoreCase)); var dashboard = await _collectionRepository.GetDashboardStateAsync(); RecentRunsCount = string.IsNullOrEmpty(dashboard?.LastRunId) ? 0 : 1; // These two queries only complete if the DB round-trip actually // succeeded, so reaching this line is the real signal -- do not // hardcode a static "정상"/"연결됨" badge independent of it. IsDatabaseConnected = true; } catch (Exception ex) { _logger.LogError(ex, "Dashboard data loading failed"); IsDatabaseConnected = false; } } }