UpdateDesktopGpuUseCase.cs 1.0 KB

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