UpdateSystemUseCase.cs 1012 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using RackPeek.Domain.Helpers;
  2. namespace RackPeek.Domain.Resources.SystemResources.UseCases;
  3. public class UpdateSystemUseCase(ISystemRepository repository) : IUseCase
  4. {
  5. public async Task ExecuteAsync(
  6. string name,
  7. string? type = null,
  8. string? os = null,
  9. int? cores = null,
  10. int? ram = null,
  11. string? runsOn = null
  12. )
  13. {
  14. ThrowIfInvalid.ResourceName(name);
  15. var system = await repository.GetByNameAsync(name);
  16. if (system is null)
  17. throw new InvalidOperationException($"System '{name}' not found.");
  18. if (!string.IsNullOrWhiteSpace(type))
  19. system.Type = type;
  20. if (!string.IsNullOrWhiteSpace(os))
  21. system.Os = os;
  22. if (cores.HasValue)
  23. system.Cores = cores.Value;
  24. if (ram.HasValue)
  25. system.Ram = ram.Value;
  26. if (!string.IsNullOrWhiteSpace(runsOn))
  27. system.RunsOn = runsOn;
  28. await repository.UpdateAsync(system);
  29. }
  30. }