UpdateSystemUseCase.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using RackPeek.Domain.Resources.SystemResources;
  2. namespace RackPeek.Domain.Resources.Services.UseCases;
  3. public class UpdateServiceUseCase(IServiceRepository repository)
  4. {
  5. public async Task ExecuteAsync(
  6. string name,
  7. string? ip = null,
  8. int? port = null,
  9. string? protocol = null,
  10. string? url = null,
  11. string? runsOn = null
  12. )
  13. {
  14. var service = await repository.GetByNameAsync(name);
  15. if (service is null)
  16. throw new InvalidOperationException($"Service '{name}' not found.");
  17. if (!string.IsNullOrWhiteSpace(ip))
  18. {
  19. service.Network ??= new Network();
  20. service.Network.Ip = ip;
  21. }
  22. if (!string.IsNullOrWhiteSpace(protocol))
  23. {
  24. service.Network ??= new Network();
  25. service.Network.Protocol = protocol;
  26. }
  27. if (!string.IsNullOrWhiteSpace(url))
  28. {
  29. service.Network ??= new Network();
  30. service.Network.Url = url;
  31. }
  32. if (port.HasValue)
  33. {
  34. service.Network ??= new Network();
  35. service.Network.Port = port.Value;
  36. }
  37. if (!string.IsNullOrWhiteSpace(runsOn))
  38. service.RunsOn = runsOn;
  39. await repository.UpdateAsync(service);
  40. }
  41. }