UpdateDesktopGpuUseCase.cs 776 B

12345678910111213141516171819202122
  1. using RackPeek.Domain.Helpers;
  2. using RackPeek.Domain.Resources.Hardware.Models;
  3. namespace RackPeek.Domain.Resources.Hardware.Laptops.Gpus;
  4. public class UpdateLaptopGpuUseCase(IHardwareRepository repository) : IUseCase
  5. {
  6. public async Task ExecuteAsync(string name, int index, Gpu updated)
  7. {
  8. ThrowIfInvalid.ResourceName(name);
  9. var laptop = await repository.GetByNameAsync(name) as Laptop
  10. ?? throw new InvalidOperationException($"Laptop '{name}' not found.");
  11. if (laptop.Gpus == null || index < 0 || index >= laptop.Gpus.Count)
  12. throw new InvalidOperationException($"GPU index {index} not found on Laptop '{name}'.");
  13. laptop.Gpus[index] = updated;
  14. await repository.UpdateAsync(laptop);
  15. }
  16. }