GetSystemSummaryUseCase.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. namespace RackPeek.Domain.Resources.SystemResources.UseCases;
  2. public sealed class SystemSummary
  3. {
  4. public SystemSummary(
  5. int totalSystems,
  6. IReadOnlyDictionary<string, int> systemsByType,
  7. IReadOnlyDictionary<string, int> systemsByOs)
  8. {
  9. TotalSystems = totalSystems;
  10. SystemsByType = systemsByType;
  11. SystemsByOs = systemsByOs;
  12. }
  13. public int TotalSystems { get; }
  14. public IReadOnlyDictionary<string, int> SystemsByType { get; }
  15. public IReadOnlyDictionary<string, int> SystemsByOs { get; }
  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. }