| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using RackPeek.Domain.Helpers;
- using RackPeek.Domain.Persistence;
- namespace RackPeek.Domain.Resources.Desktops;
- public record DesktopDescription(
- string Name,
- string? Model,
- int CpuCount,
- string? RamSummary,
- int DriveCount,
- int NicCount,
- int GpuCount,
- Dictionary<string, string> Labels
- );
- public class DescribeDesktopUseCase(IResourceCollection repository) : IUseCase {
- public async Task<DesktopDescription> ExecuteAsync(string name) {
- name = Normalize.HardwareName(name);
- ThrowIfInvalid.ResourceName(name);
- var desktop = await repository.GetByNameAsync(name) as Desktop;
- if (desktop == null)
- throw new NotFoundException($"Desktop '{name}' not found.");
- var ramSummary = desktop.Ram == null
- ? "None"
- : $"{desktop.Ram.Size} GB @ {desktop.Ram.Mts} MT/s";
- return new DesktopDescription(
- desktop.Name,
- desktop.Model,
- desktop.Cpus?.Count ?? 0,
- ramSummary,
- desktop.Drives?.Count ?? 0,
- desktop.Ports?.Count ?? 0,
- desktop.Gpus?.Count ?? 0,
- desktop.Labels
- );
- }
- }
|