Skip to content

Commit

Permalink
feat(infraestructure): add dtos for create and update for transports
Browse files Browse the repository at this point in the history
  • Loading branch information
JeferssonCL committed Sep 17, 2024
1 parent b94f2b7 commit c278884
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Transport>
{
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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Transport>
{
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);
}
}

0 comments on commit c278884

Please sign in to comment.