RemoveSystemDriveUseCase.cs 822 B

1234567891011121314151617181920212223
  1. using System.ComponentModel.DataAnnotations;
  2. using RackPeek.Domain.Helpers;
  3. using RackPeek.Domain.Resources.SystemResources;
  4. namespace RackPeek.Domain.Resources.SystemResources.UseCases;
  5. public class RemoveSystemDriveUseCase(ISystemRepository repository) : IUseCase
  6. {
  7. public async Task ExecuteAsync(string systemName, int index)
  8. {
  9. ThrowIfInvalid.ResourceName(systemName);
  10. var system = await repository.GetByNameAsync(systemName)
  11. ?? throw new NotFoundException($"System '{systemName}' not found.");
  12. if (system.Drives == null || index < 0 || index >= system.Drives.Count)
  13. throw new NotFoundException($"Drive index {index} not found on system '{systemName}'.");
  14. system.Drives.RemoveAt(index);
  15. await repository.UpdateAsync(system);
  16. }
  17. }