-
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): adding order dtos and validators
- Loading branch information
1 parent
17fef4f
commit 49f360d
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/DistributionCenter.Infraestructure/DTOs/Concretes/Orders/CreateOrderDto.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,26 @@ | ||
namespace DistributionCenter.Infraestructure.DTOs.Concretes.Orders; | ||
|
||
using Commons.Results; | ||
using Domain.Entities.Concretes; | ||
using Interfaces; | ||
using Validators.Core.Concretes.Orders; | ||
|
||
public class CreateOrderDto : ICreateDto<Order> | ||
{ | ||
public required Guid ClientId { get; init; } | ||
public required Guid OrderStatusId { get; init; } | ||
|
||
public Order ToEntity() | ||
{ | ||
return new Order | ||
{ | ||
ClientId = ClientId, | ||
OrderStatusId = OrderStatusId, | ||
}; | ||
} | ||
|
||
public Result Validate() | ||
{ | ||
return new CreateOrderValidator().Validate(this); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/DistributionCenter.Infraestructure/DTOs/Concretes/Orders/UpdateOrderDto.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,27 @@ | ||
namespace DistributionCenter.Infraestructure.DTOs.Concretes.Orders; | ||
|
||
using Commons.Results; | ||
using Domain.Entities.Concretes; | ||
using Interfaces; | ||
using Validators.Core.Concretes.Orders; | ||
|
||
public class UpdateOrderDto: IUpdateDto<Order> | ||
{ | ||
public Guid? ClientId { get; init; } | ||
public Guid? OrderStatusId { get; init; } | ||
|
||
public Order FromEntity(Order client) | ||
{ | ||
ArgumentNullException.ThrowIfNull(client, nameof(client)); | ||
|
||
client.ClientId = ClientId ?? client.ClientId; | ||
client.OrderStatusId = OrderStatusId ?? client.OrderStatusId; | ||
|
||
return client; | ||
} | ||
|
||
public Result Validate() | ||
{ | ||
return new UpdateOrderValidator().Validate(this); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...stributionCenter.Infraestructure/Validators/Core/Concretes/Orders/CreateOrderValidator.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,17 @@ | ||
namespace DistributionCenter.Infraestructure.Validators.Core.Concretes.Orders; | ||
|
||
using Bases; | ||
using DTOs.Concretes.Orders; | ||
using Extensions; | ||
|
||
public class CreateOrderValidator : BaseFluentValidator<CreateOrderDto> | ||
{ | ||
public CreateOrderValidator() | ||
{ | ||
_ = RuleFor<Guid?>(static x => x.ClientId) | ||
.UuidNotNull("Client id is required"); | ||
|
||
_ = RuleFor<Guid?>(static x => x.OrderStatusId) | ||
.UuidNotNull("Order status id is required"); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...stributionCenter.Infraestructure/Validators/Core/Concretes/Orders/UpdateOrderValidator.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,17 @@ | ||
namespace DistributionCenter.Infraestructure.Validators.Core.Concretes.Orders; | ||
|
||
using Bases; | ||
using DTOs.Concretes.Orders; | ||
using Extensions; | ||
|
||
public class UpdateOrderValidator : BaseFluentValidator<UpdateOrderDto> | ||
{ | ||
public UpdateOrderValidator() | ||
{ | ||
_ = RuleFor(static x => x.ClientId) | ||
.UuidNotNull("Client id is required"); | ||
|
||
_ = RuleFor(static x => x.OrderStatusId) | ||
.UuidNotNull("Order status id is required"); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/DistributionCenter.Infraestructure/Validators/Extensions/ValidationExtensions.Uuid.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,13 @@ | ||
namespace DistributionCenter.Infraestructure.Validators.Extensions; | ||
|
||
using Components.Builders.Interfaces; | ||
|
||
public static partial class ValidationExtensionsUuid | ||
{ | ||
public static IValidationBuilder<Guid?> UuidNotNull(this IValidationBuilder<Guid?> builder, string message) | ||
{ | ||
ArgumentNullException.ThrowIfNull(builder, nameof(builder)); | ||
|
||
return builder.When(static x => x.HasValue).AddRule(static x => x != Guid.Empty, message)!; | ||
} | ||
} |