GetSystemSummaryUseCase.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace RackPeek.Domain.Resources.SystemResources.UseCases;
  2. public sealed class SystemSummary
  3. {
  4. public int TotalSystems { get; }
  5. public IReadOnlyDictionary<string, int> SystemsByType { get; }
  6. public IReadOnlyDictionary<string, int> SystemsByOs { get; }
  7. public SystemSummary(
  8. int totalSystems,
  9. IReadOnlyDictionary<string, int> systemsByType,
  10. IReadOnlyDictionary<string, int> systemsByOs)
  11. {
  12. TotalSystems = totalSystems;
  13. SystemsByType = systemsByType;
  14. SystemsByOs = systemsByOs;
  15. }
  16. }
  17. public class GetSystemSummaryUseCase(ISystemRepository repository) : IUseCase
  18. {
  19. public async Task<SystemSummary> ExecuteAsync()
  20. {
  21. var totalSystemsTask = repository.GetSystemCountAsync();
  22. var systemsByTypeTask = repository.GetSystemTypeCountAsync();
  23. var systemsByOsTask = repository.GetSystemOsCountAsync();
  24. await Task.WhenAll(
  25. totalSystemsTask,
  26. systemsByTypeTask,
  27. systemsByOsTask
  28. );
  29. return new SystemSummary(
  30. totalSystemsTask.Result,
  31. systemsByTypeTask.Result,
  32. systemsByOsTask.Result
  33. );
  34. }
  35. }