diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetAuditLogsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetAuditLogsFunction.cs index 805cbda2..e1d0c585 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetAuditLogsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetAuditLogsFunction.cs @@ -10,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Admin public class GetAuditLogsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly IMaintenanceRepository _maintenanceRepo; - public GetAuditLogsFunction(ILogger logger, TableStorageService storageService) + public GetAuditLogsFunction(ILogger logger, IMaintenanceRepository maintenanceRepo) { _logger = logger; - _storageService = storageService; + _maintenanceRepo = maintenanceRepo; } [Function("GetAuditLogs")] @@ -33,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Admin _logger.LogInformation($"Fetching audit logs for tenant {tenantId} by user {userIdentifier}"); // Get audit logs from storage - var logs = await _storageService.GetAuditLogsAsync(tenantId, maxResults: 100); + var logs = await _maintenanceRepo.GetAuditLogsAsync(tenantId, maxResults: 100); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetGlobalAuditLogsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetGlobalAuditLogsFunction.cs index bd2b4455..c1180548 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetGlobalAuditLogsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Admin/GetGlobalAuditLogsFunction.cs @@ -1,6 +1,6 @@ using System.Net; using AutopilotMonitor.Functions.Helpers; -using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -10,14 +10,14 @@ namespace AutopilotMonitor.Functions.Functions.Admin public class GetGlobalAuditLogsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly IMaintenanceRepository _maintenanceRepo; public GetGlobalAuditLogsFunction( ILogger logger, - TableStorageService storageService) + IMaintenanceRepository maintenanceRepo) { _logger = logger; - _storageService = storageService; + _maintenanceRepo = maintenanceRepo; } [Function("GetGlobalAuditLogs")] @@ -33,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Admin _logger.LogInformation($"Fetching all audit logs across all tenants (User: {userEmail})"); - var logs = await _storageService.GetAllAuditLogsAsync(maxResults: 100); + var logs = await _maintenanceRepo.GetAllAuditLogsAsync(maxResults: 100); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Feedback/FeedbackFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Feedback/FeedbackFunction.cs index 4903d4e5..26f94f91 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Feedback/FeedbackFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Feedback/FeedbackFunction.cs @@ -6,6 +6,7 @@ using AutopilotMonitor.Functions.Extensions; using AutopilotMonitor.Functions.Helpers; using AutopilotMonitor.Functions.Services; using AutopilotMonitor.Shared; +using AutopilotMonitor.Shared.DataAccess; using AutopilotMonitor.Shared.Models; using Azure; using Azure.Data.Tables; @@ -23,7 +24,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback private readonly AdminConfigurationService _adminConfigService; private readonly TenantAdminsService _tenantAdminsService; private readonly TelegramNotificationService _telegramNotificationService; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; private readonly TableClient _feedbackTableClient; public FeedbackFunction( @@ -32,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback AdminConfigurationService adminConfigService, TenantAdminsService tenantAdminsService, TelegramNotificationService telegramNotificationService, - TableStorageService storageService, + ISessionRepository sessionRepo, IConfiguration configuration) { _logger = logger; @@ -40,7 +41,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback _adminConfigService = adminConfigService; _tenantAdminsService = tenantAdminsService; _telegramNotificationService = telegramNotificationService; - _storageService = storageService; + _sessionRepo = sessionRepo; var connectionString = configuration["AzureTableStorageConnectionString"]; var serviceClient = new TableServiceClient(connectionString); @@ -78,7 +79,7 @@ namespace AutopilotMonitor.Functions.Functions.Feedback return await WriteJson(req, new { eligible = false }); // 5. Sessions check — at least 1 session exists - var sessionPage = await _storageService.GetSessionsAsync(tenantId, maxResults: 1); + var sessionPage = await _sessionRepo.GetSessionsAsync(tenantId, maxResults: 1); if (sessionPage.Sessions.Count == 0) return await WriteJson(req, new { eligible = false }); diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Infrastructure/AuthFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Infrastructure/AuthFunction.cs index 42dcd176..5e64780e 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Infrastructure/AuthFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Infrastructure/AuthFunction.cs @@ -1,6 +1,7 @@ using System.Net; using AutopilotMonitor.Functions.Extensions; using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Functions.Worker; @@ -18,7 +19,7 @@ public class AuthFunction private readonly GlobalAdminService _globalAdminService; private readonly TenantConfigurationService _tenantConfigService; private readonly TenantAdminsService _tenantAdminsService; - private readonly TableStorageService _storageService; + private readonly IMetricsRepository _metricsRepo; private readonly PreviewWhitelistService _previewWhitelistService; private readonly TelegramNotificationService _telegramNotificationService; private readonly GlobalNotificationService _globalNotificationService; @@ -28,7 +29,7 @@ public class AuthFunction GlobalAdminService globalAdminService, TenantConfigurationService tenantConfigService, TenantAdminsService tenantAdminsService, - TableStorageService storageService, + IMetricsRepository metricsRepo, PreviewWhitelistService previewWhitelistService, TelegramNotificationService telegramNotificationService, GlobalNotificationService globalNotificationService) @@ -37,7 +38,7 @@ public class AuthFunction _globalAdminService = globalAdminService; _tenantConfigService = tenantConfigService; _tenantAdminsService = tenantAdminsService; - _storageService = storageService; + _metricsRepo = metricsRepo; _previewWhitelistService = previewWhitelistService; _telegramNotificationService = telegramNotificationService; _globalNotificationService = globalNotificationService; @@ -172,7 +173,7 @@ public class AuthFunction bool canManageBootstrapTokens = memberRole?.CanManageBootstrapTokens ?? false; // Record user login activity for metrics tracking - _ = _storageService.RecordUserLoginAsync(tenantId, upn, displayName, objectId) + _ = _metricsRepo.RecordUserLoginAsync(tenantId, upn, displayName, objectId) .ContinueWith(t => _logger.LogWarning(t.Exception?.InnerException, "Fire-and-forget RecordUserLoginAsync failed"), TaskContinuationOptions.OnlyOnFaulted); var userInfo = new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Progress/ProgressPortalFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Progress/ProgressPortalFunction.cs index 39c53d7e..2f1abab6 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Progress/ProgressPortalFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Progress/ProgressPortalFunction.cs @@ -2,6 +2,7 @@ using System.Net; using System.Web; using AutopilotMonitor.Functions.Helpers; using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -16,16 +17,16 @@ namespace AutopilotMonitor.Functions.Functions.Progress; public class ProgressPortalFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; private readonly GlobalAdminService _globalAdminService; public ProgressPortalFunction( ILogger logger, - TableStorageService storageService, + ISessionRepository sessionRepo, GlobalAdminService globalAdminService) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; _globalAdminService = globalAdminService; } @@ -46,7 +47,7 @@ public class ProgressPortalFunction _logger.LogInformation("ProgressGetSessions: Fetching sessions for tenant {TenantId}", tenantId); - var page = await _storageService.GetSessionsAsync(tenantId, maxResults: 100); + var page = await _sessionRepo.GetSessionsAsync(tenantId, maxResults: 100); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new @@ -137,7 +138,7 @@ public class ProgressPortalFunction sessionPrefix, userIdentifier, requestedTenantId); } - var events = await _storageService.GetSessionEventsAsync(requestedTenantId, sessionId); + var events = await _sessionRepo.GetSessionEventsAsync(requestedTenantId, sessionId); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Rules/GetRuleResultsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Rules/GetRuleResultsFunction.cs index 4d2ee230..5c897d42 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Rules/GetRuleResultsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Rules/GetRuleResultsFunction.cs @@ -2,6 +2,7 @@ using System.Net; using System.Web; using AutopilotMonitor.Functions.Helpers; using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -16,18 +17,24 @@ namespace AutopilotMonitor.Functions.Functions.Rules public class GetRuleResultsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly IRuleRepository _ruleRepo; + private readonly IMaintenanceRepository _maintenanceRepo; + private readonly ISessionRepository _sessionRepo; private readonly AnalyzeRuleService _analyzeRuleService; private readonly GlobalAdminService _globalAdminService; public GetRuleResultsFunction( ILogger logger, - TableStorageService storageService, + IRuleRepository ruleRepo, + IMaintenanceRepository maintenanceRepo, + ISessionRepository sessionRepo, AnalyzeRuleService analyzeRuleService, GlobalAdminService globalAdminService) { _logger = logger; - _storageService = storageService; + _ruleRepo = ruleRepo; + _maintenanceRepo = maintenanceRepo; + _sessionRepo = sessionRepo; _analyzeRuleService = analyzeRuleService; _globalAdminService = globalAdminService; } @@ -66,15 +73,15 @@ namespace AutopilotMonitor.Functions.Functions.Rules { try { - var ruleEngine = new RuleEngine(_analyzeRuleService, _storageService, _logger); + var ruleEngine = new RuleEngine(_analyzeRuleService, _ruleRepo, _sessionRepo, _logger); var freshResults = await ruleEngine.AnalyzeSessionAsync(effectiveTenantId, sessionId, reanalyze: true); // Delete existing results so stale entries don't persist after re-analysis - await _storageService.DeleteSessionRuleResultsAsync(effectiveTenantId, sessionId); + await _maintenanceRepo.DeleteSessionRuleResultsAsync(effectiveTenantId, sessionId); foreach (var result in freshResults) { - await _storageService.StoreRuleResultAsync(result); + await _ruleRepo.StoreRuleResultAsync(result); } _logger.LogInformation($"On-demand re-analysis for session {sessionId}: {freshResults.Count} issue(s) detected"); @@ -85,7 +92,7 @@ namespace AutopilotMonitor.Functions.Functions.Rules } } - var results = await _storageService.GetRuleResultsAsync(effectiveTenantId, sessionId); + var results = await _ruleRepo.GetRuleResultsAsync(effectiveTenantId, sessionId); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new