diff --git a/src/Backend/AutopilotMonitor.Functions/DataAccess/TableStorage/TableSessionRepository.cs b/src/Backend/AutopilotMonitor.Functions/DataAccess/TableStorage/TableSessionRepository.cs index 5eb89389..30910d6c 100644 --- a/src/Backend/AutopilotMonitor.Functions/DataAccess/TableStorage/TableSessionRepository.cs +++ b/src/Backend/AutopilotMonitor.Functions/DataAccess/TableStorage/TableSessionRepository.cs @@ -78,6 +78,9 @@ namespace AutopilotMonitor.Functions.DataAccess.TableStorage return result; } + public Task> GetSessionEventsAsync(string tenantId, string sessionId, int maxResults = 1000) + => _storage.GetSessionEventsAsync(tenantId, sessionId, maxResults); + public Task> SearchSessionsAsync(string? tenantId, SessionSearchFilter filter) => _storage.SearchSessionsAsync(tenantId, filter); diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/GetPlatformStatsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/GetPlatformStatsFunction.cs index 97817870..9bd94aba 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/GetPlatformStatsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/GetPlatformStatsFunction.cs @@ -1,5 +1,5 @@ using System.Net; -using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/MetricsSummaryFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/MetricsSummaryFunction.cs index 328a52b3..375d0c7d 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/MetricsSummaryFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Metrics/MetricsSummaryFunction.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,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Metrics; public class MetricsSummaryFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly IMetricsRepository _metricsRepo; - public MetricsSummaryFunction(ILogger logger, TableStorageService storageService) + public MetricsSummaryFunction(ILogger logger, IMetricsRepository metricsRepo) { _logger = logger; - _storageService = storageService; + _metricsRepo = metricsRepo; } [Function("MetricsSummary")] @@ -25,7 +25,7 @@ public class MetricsSummaryFunction try { var tenantId = TenantHelper.GetTenantId(req); - var summary = await _storageService.GetMetricsSummaryAsync(tenantId); + var summary = await _metricsRepo.GetMetricsSummaryAsync(tenantId); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new { success = true, summary }); @@ -46,7 +46,7 @@ public class MetricsSummaryFunction { try { - var summary = await _storageService.GetMetricsSummaryAsync(null); + var summary = await _metricsRepo.GetMetricsSummaryAsync(null); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new { success = true, summary }); diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetAllSessionsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetAllSessionsFunction.cs index 22250af3..2bed50a2 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetAllSessionsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetAllSessionsFunction.cs @@ -1,6 +1,6 @@ using System.Net; using AutopilotMonitor.Functions.Helpers; -using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using AutopilotMonitor.Shared.Models; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; @@ -11,14 +11,14 @@ namespace AutopilotMonitor.Functions.Functions.Sessions public class GetAllSessionsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; public GetAllSessionsFunction( ILogger logger, - TableStorageService storageService) + ISessionRepository sessionRepo) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; } [Function("GetAllSessions")] @@ -47,12 +47,12 @@ namespace AutopilotMonitor.Functions.Functions.Sessions } _logger.LogInformation("Fetching sessions for tenant {TenantId} (User: {UserEmail}, cursor: {Cursor})", tenantIdFilter, userEmail, cursor ?? "none"); - page = await _storageService.GetSessionsAsync(tenantIdFilter, maxResults: 100, cursor: cursor); + page = await _sessionRepo.GetSessionsAsync(tenantIdFilter, maxResults: 100, cursor: cursor); } else { _logger.LogInformation("Fetching all sessions across all tenants (User: {UserEmail}, cursor: {Cursor})", userEmail, cursor ?? "none"); - page = await _storageService.GetAllSessionsAsync(maxResults: 100, cursor: cursor); + page = await _sessionRepo.GetAllSessionsAsync(maxResults: 100, cursor: cursor); } var response = req.CreateResponse(HttpStatusCode.OK); diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionEventsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionEventsFunction.cs index ea096211..d6d2262d 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionEventsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionEventsFunction.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; @@ -11,16 +12,16 @@ namespace AutopilotMonitor.Functions.Functions.Sessions public class GetSessionEventsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; private readonly GlobalAdminService _globalAdminService; public GetSessionEventsFunction( ILogger logger, - TableStorageService storageService, + ISessionRepository sessionRepo, GlobalAdminService globalAdminService) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; _globalAdminService = globalAdminService; } @@ -92,7 +93,7 @@ namespace AutopilotMonitor.Functions.Functions.Sessions } // Get events from storage using the requested tenant ID - 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/Sessions/GetSessionFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionFunction.cs index 4464d0d3..a3f823c8 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionFunction.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; @@ -11,16 +12,16 @@ namespace AutopilotMonitor.Functions.Functions.Sessions public class GetSessionFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; private readonly GlobalAdminService _globalAdminService; public GetSessionFunction( ILogger logger, - TableStorageService storageService, + ISessionRepository sessionRepo, GlobalAdminService globalAdminService) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; _globalAdminService = globalAdminService; } @@ -78,7 +79,7 @@ namespace AutopilotMonitor.Functions.Functions.Sessions } } - var session = await _storageService.GetSessionAsync(effectiveTenantId, sessionId); + var session = await _sessionRepo.GetSessionAsync(effectiveTenantId, sessionId); if (session == null) { var notFound = req.CreateResponse(HttpStatusCode.NotFound); diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionsFunction.cs index ad4afd54..979ca08d 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/GetSessionsFunction.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,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Sessions public class GetSessionsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; - public GetSessionsFunction(ILogger logger, TableStorageService storageService) + public GetSessionsFunction(ILogger logger, ISessionRepository sessionRepo) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; } [Function("GetSessions")] @@ -33,7 +33,7 @@ namespace AutopilotMonitor.Functions.Functions.Sessions _logger.LogInformation("Fetching sessions for tenant {TenantId} (cursor: {Cursor})", tenantId, cursor ?? "none"); - var page = await _storageService.GetSessionsAsync(tenantId, maxResults: 100, cursor: cursor); + var page = await _sessionRepo.GetSessionsAsync(tenantId, maxResults: 100, cursor: cursor); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByCveFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByCveFunction.cs index 27cebd16..1e5ba483 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByCveFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByCveFunction.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,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Sessions; public class SearchSessionsByCveFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; - public SearchSessionsByCveFunction(ILogger logger, TableStorageService storageService) + public SearchSessionsByCveFunction(ILogger logger, ISessionRepository sessionRepo) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; } [Function("SearchSessionsByCve")] diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByEventFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByEventFunction.cs index 92bc87db..a18acb12 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByEventFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsByEventFunction.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,12 +10,12 @@ namespace AutopilotMonitor.Functions.Functions.Sessions; public class SearchSessionsByEventFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; - public SearchSessionsByEventFunction(ILogger logger, TableStorageService storageService) + public SearchSessionsByEventFunction(ILogger logger, ISessionRepository sessionRepo) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; } [Function("SearchSessionsByEvent")] @@ -54,7 +54,7 @@ public class SearchSessionsByEventFunction var limit = int.TryParse(query["limit"], out var lim) ? Math.Min(lim, 100) : 50; - var sessions = await _storageService.SearchSessionsByEventAsync(tenantId, eventType, null, null, null, limit); + var sessions = await _sessionRepo.SearchSessionsByEventAsync(tenantId, eventType, null, null, null, limit); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsFunction.cs b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsFunction.cs index d077290b..88153032 100644 --- a/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsFunction.cs +++ b/src/Backend/AutopilotMonitor.Functions/Functions/Sessions/SearchSessionsFunction.cs @@ -1,6 +1,6 @@ using System.Net; using AutopilotMonitor.Functions.Helpers; -using AutopilotMonitor.Functions.Services; +using AutopilotMonitor.Shared.DataAccess; using AutopilotMonitor.Shared.Models; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; @@ -11,12 +11,12 @@ namespace AutopilotMonitor.Functions.Functions.Sessions; public class SearchSessionsFunction { private readonly ILogger _logger; - private readonly TableStorageService _storageService; + private readonly ISessionRepository _sessionRepo; - public SearchSessionsFunction(ILogger logger, TableStorageService storageService) + public SearchSessionsFunction(ILogger logger, ISessionRepository sessionRepo) { _logger = logger; - _storageService = storageService; + _sessionRepo = sessionRepo; } [Function("SearchSessions")] @@ -82,7 +82,7 @@ public class SearchSessionsFunction if (deviceProperties.Count > 0) filter.DeviceProperties = deviceProperties; - var sessions = await _storageService.SearchSessionsAsync(tenantId, filter); + var sessions = await _sessionRepo.SearchSessionsAsync(tenantId, filter); var response = req.CreateResponse(HttpStatusCode.OK); await response.WriteAsJsonAsync(new diff --git a/src/Shared/AutopilotMonitor.Shared/DataAccess/ISessionRepository.cs b/src/Shared/AutopilotMonitor.Shared/DataAccess/ISessionRepository.cs index 96dad8aa..bfdcaea6 100644 --- a/src/Shared/AutopilotMonitor.Shared/DataAccess/ISessionRepository.cs +++ b/src/Shared/AutopilotMonitor.Shared/DataAccess/ISessionRepository.cs @@ -35,6 +35,7 @@ namespace AutopilotMonitor.Shared.DataAccess // --- Events --- Task StoreEventAsync(EnrollmentEvent evt); + Task> GetSessionEventsAsync(string tenantId, string sessionId, int maxResults = 1000); // --- Search --- Task> SearchSessionsAsync(string? tenantId, SessionSearchFilter filter);