UpdateDesktopDriveUseCase.cs 790 B

12345678910111213141516171819202122
  1. using RackPeek.Domain.Helpers;
  2. using RackPeek.Domain.Resources.Hardware.Models;
  3. namespace RackPeek.Domain.Resources.Hardware.Laptops.Drives;
  4. public class UpdateLaptopDriveUseCase(IHardwareRepository repository) : IUseCase
  5. {
  6. public async Task ExecuteAsync(string name, int index, Drive 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.Drives == null || index < 0 || index >= laptop.Drives.Count)
  12. throw new InvalidOperationException($"Drive index {index} not found on Laptop '{name}'.");
  13. laptop.Drives[index] = updated;
  14. await repository.UpdateAsync(laptop);
  15. }
  16. }