Files
QuantEngineByItz/src/dotnet/QuantEngine.Application/Services/CollectionReadModelService.cs
T
kjh2064 dd08e36a2b
Validators (Pushes and Pull Requests) / validate-ui-and-storage (push) Successful in 18s
Validators (Pushes and Pull Requests) / validate-core (push) Failing after 1m46s
refactor(dotnet): normalize collection read model inputs
2026-07-13 01:17:06 +09:00

44 lines
1.7 KiB
C#

using QuantEngine.Application.Interfaces;
using QuantEngine.Core.Interfaces;
namespace QuantEngine.Application.Services;
public sealed class CollectionReadModelService : ICollectionReadModelService
{
private readonly ICollectionReadRepository _repository;
public CollectionReadModelService(ICollectionReadRepository repository)
{
_repository = repository;
}
public Task<CollectionDashboardStateRecord> GetDashboardStateAsync() => _repository.GetDashboardStateAsync();
public Task<List<CollectionRunRecord>> GetRecentRunsAsync(int limit = 20)
=> _repository.GetRecentRunsAsync(NormalizeLimit(limit, 1, 200));
public Task<List<CollectionSnapshotRecord>> GetRunSnapshotsAsync(string runId)
=> _repository.GetRunSnapshotsAsync(RequireValue(runId, nameof(runId)));
public Task<List<CollectionErrorRecord>> GetRunErrorsAsync(string runId, int limit = 50)
=> _repository.GetRunErrorsAsync(RequireValue(runId, nameof(runId)), NormalizeLimit(limit, 1, 200));
public Task<List<CollectionSnapshotRecord>> GetLatestSnapshotsForTickerAsync(string ticker, int limit = 10)
=> _repository.GetLatestSnapshotsForTickerAsync(RequireValue(ticker, nameof(ticker)), NormalizeLimit(limit, 1, 100));
public Task<List<PriceHistorySummaryRecord>> GetPriceHistorySummaryAsync() => _repository.GetPriceHistorySummaryAsync();
private static string RequireValue(string value, string parameterName)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Value is required.", parameterName);
}
return value.Trim();
}
private static int NormalizeLimit(int limit, int min, int max)
=> Math.Clamp(limit, min, max);
}