GetSystemSummaryUseCase.cs 1.2 KB

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