Migrate Session and Metrics Functions to DAL repository interfaces

Replace direct TableStorageService injection with ISessionRepository,
IMetricsRepository, and IMaintenanceRepository in 10 Function files.
Add GetSessionEventsAsync to ISessionRepository interface.

Migration in progress — more functions and services to follow.

https://claude.ai/code/session_01NHWJfPaa8TQHuPzMD7gG63
This commit is contained in:
Claude
2026-03-27 06:29:17 +00:00
parent 36554c5ca4
commit 5b4e4238f3
11 changed files with 46 additions and 40 deletions
@@ -78,6 +78,9 @@ namespace AutopilotMonitor.Functions.DataAccess.TableStorage
return result;
}
public Task<List<EnrollmentEvent>> GetSessionEventsAsync(string tenantId, string sessionId, int maxResults = 1000)
=> _storage.GetSessionEventsAsync(tenantId, sessionId, maxResults);
public Task<List<SessionSummary>> SearchSessionsAsync(string? tenantId, SessionSearchFilter filter)
=> _storage.SearchSessionsAsync(tenantId, filter);
@@ -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;
@@ -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<MetricsSummaryFunction> _logger;
private readonly TableStorageService _storageService;
private readonly IMetricsRepository _metricsRepo;
public MetricsSummaryFunction(ILogger<MetricsSummaryFunction> logger, TableStorageService storageService)
public MetricsSummaryFunction(ILogger<MetricsSummaryFunction> 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 });
@@ -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<GetAllSessionsFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
public GetAllSessionsFunction(
ILogger<GetAllSessionsFunction> 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);
@@ -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<GetSessionEventsFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
private readonly GlobalAdminService _globalAdminService;
public GetSessionEventsFunction(
ILogger<GetSessionEventsFunction> 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
@@ -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<GetSessionFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
private readonly GlobalAdminService _globalAdminService;
public GetSessionFunction(
ILogger<GetSessionFunction> 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);
@@ -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<GetSessionsFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
public GetSessionsFunction(ILogger<GetSessionsFunction> logger, TableStorageService storageService)
public GetSessionsFunction(ILogger<GetSessionsFunction> 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
@@ -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<SearchSessionsByCveFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
public SearchSessionsByCveFunction(ILogger<SearchSessionsByCveFunction> logger, TableStorageService storageService)
public SearchSessionsByCveFunction(ILogger<SearchSessionsByCveFunction> logger, ISessionRepository sessionRepo)
{
_logger = logger;
_storageService = storageService;
_sessionRepo = sessionRepo;
}
[Function("SearchSessionsByCve")]
@@ -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<SearchSessionsByEventFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
public SearchSessionsByEventFunction(ILogger<SearchSessionsByEventFunction> logger, TableStorageService storageService)
public SearchSessionsByEventFunction(ILogger<SearchSessionsByEventFunction> 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
@@ -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<SearchSessionsFunction> _logger;
private readonly TableStorageService _storageService;
private readonly ISessionRepository _sessionRepo;
public SearchSessionsFunction(ILogger<SearchSessionsFunction> logger, TableStorageService storageService)
public SearchSessionsFunction(ILogger<SearchSessionsFunction> 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
@@ -35,6 +35,7 @@ namespace AutopilotMonitor.Shared.DataAccess
// --- Events ---
Task<bool> StoreEventAsync(EnrollmentEvent evt);
Task<List<EnrollmentEvent>> GetSessionEventsAsync(string tenantId, string sessionId, int maxResults = 1000);
// --- Search ---
Task<List<SessionSummary>> SearchSessionsAsync(string? tenantId, SessionSearchFilter filter);