diff --git a/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/CreateTransportDto.cs b/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/CreateTransportDto.cs new file mode 100644 index 0000000..8bd61f2 --- /dev/null +++ b/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/CreateTransportDto.cs @@ -0,0 +1,28 @@ +namespace DistributionCenter.Infraestructure.DTOs.Concretes.Transports; + +using DistributionCenter.Commons.Results; +using DistributionCenter.Domain.Entities.Concretes; +using DistributionCenter.Infraestructure.DTOs.Interfaces; +using DistributionCenter.Infraestructure.Validators.Core.Concretes.Transports; + +public class CreateTransportDto : ICreateDto +{ + public required string Name { get; init; } + public required int Capacity { get; init; } + public required int AvailableUnits { get; init; } + + public Transport ToEntity() + { + return new Transport + { + Name = Name, + Capacity = Capacity, + AvailableUnits = AvailableUnits + }; + } + + public Result Validate() + { + return new CreateTransportValidator().Validate(this); + } +} diff --git a/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/UpdateTransportDto.cs b/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/UpdateTransportDto.cs new file mode 100644 index 0000000..f8ca447 --- /dev/null +++ b/src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/UpdateTransportDto.cs @@ -0,0 +1,29 @@ +namespace DistributionCenter.Infraestructure.DTOs.Concretes.Transports; + +using DistributionCenter.Commons.Results; +using DistributionCenter.Domain.Entities.Concretes; +using DistributionCenter.Infraestructure.DTOs.Interfaces; +using DistributionCenter.Infraestructure.Validators.Core.Concretes.Transports; + +public class UpdateTransportDto : IUpdateDto +{ + public required string? Name { get; init; } + public required int? Capacity { get; init; } + public required int? AvailableUnits { get; init; } + + public Transport FromEntity(Transport entity) + { + ArgumentNullException.ThrowIfNull(entity, nameof(entity)); + + entity.Name = Name ?? entity.Name; + entity.Capacity = Capacity ?? entity.Capacity; + entity.AvailableUnits = AvailableUnits ?? entity.AvailableUnits; + + return entity; + } + + public Result Validate() + { + return new UpdateTransportValidator().Validate(this); + } +}