| 123456789101112131415161718192021222324252627282930 |
- using RackPeek.Domain.Helpers;
- using RackPeek.Domain.Resources.Models;
- namespace RackPeek.Domain.Resources.Hardware.Laptops.Drives;
- public class AddLaptopDriveUseCase(IHardwareRepository repository) : IUseCase
- {
- public async Task ExecuteAsync(
- string name,
- string? type,
- int? size)
- {
- // ToDo pass in properties as inputs, construct the entity in the usecase, ensure optional inputs are nullable
- // ToDo validate / normalize all inputs
- name = Normalize.HardwareName(name);
- ThrowIfInvalid.ResourceName(name);
- var laptop = await repository.GetByNameAsync(name) as Laptop
- ?? throw new NotFoundException($"Laptop '{name}' not found.");
- laptop.Drives ??= new List<Drive>();
- laptop.Drives.Add(new Drive
- {
- Type = type,
- Size = size
- });
- await repository.UpdateAsync(laptop);
- }
- }
|