| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using RackPeek.Domain.Helpers;
- using RackPeek.Domain.Resources.Models;
- namespace RackPeek.Domain.Resources.Hardware.Laptops;
- public class UpdateLaptopUseCase(IHardwareRepository repository) : IUseCase
- {
- public async Task ExecuteAsync(
- string name,
- string? model = null,
- int? ramGb = null,
- int? ramMts = null,
- string? notes = null
- )
- {
- // ToDo validate / normalize all inputs
- name = Normalize.HardwareName(name);
- ThrowIfInvalid.ResourceName(name);
- var laptop = await repository.GetByNameAsync(name) as Laptop;
- if (laptop == null)
- throw new NotFoundException($"Laptop '{name}' not found.");
- if (!string.IsNullOrWhiteSpace(model))
- laptop.Model = model;
- // ---- RAM ----
- if (ramGb.HasValue)
- {
- ThrowIfInvalid.RamGb(ramGb);
- laptop.Ram ??= new Ram();
- laptop.Ram.Size = ramGb.Value;
- }
- if (ramMts.HasValue)
- {
- laptop.Ram ??= new Ram();
- laptop.Ram.Mts = ramMts.Value;
- }
- if (notes != null)
- {
- laptop.Notes = notes;
- }
- await repository.UpdateAsync(laptop);
- }
- }
|