-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(infraestructure): add dtos for create and update for transports
- Loading branch information
1 parent
b94f2b7
commit c278884
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/CreateTransportDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/DistributionCenter.Infraestructure/DTOs/Concretes/Transports/UpdateTransportDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |