UpdateDesktopGpuUseCase.cs 992 B

1234567891011121314151617181920212223242526
  1. using RackPeek.Domain.Helpers;
  2. using RackPeek.Domain.Resources.Hardware.Models;
  3. namespace RackPeek.Domain.Resources.Hardware.Desktops.Gpus;
  4. public class UpdateDesktopGpuUseCase(IHardwareRepository repository) : IUseCase
  5. {
  6. public async Task ExecuteAsync(string name, int index, Gpu updated)
  7. {
  8. // ToDo pass in properties as inputs, construct the entity in the usecase, ensure optional inputs are nullable
  9. // ToDo validate / normalize all inputs
  10. name = Normalize.HardwareName(name);
  11. ThrowIfInvalid.ResourceName(name);
  12. var desktop = await repository.GetByNameAsync(name) as Desktop
  13. ?? throw new NotFoundException($"Desktop '{name}' not found.");
  14. if (desktop.Gpus == null || index < 0 || index >= desktop.Gpus.Count)
  15. throw new NotFoundException($"GPU index {index} not found on desktop '{name}'.");
  16. desktop.Gpus[index] = updated;
  17. await repository.UpdateAsync(desktop);
  18. }
  19. }