Skip to content

Commit

Permalink
feat: add create product command validatior
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed Feb 25, 2024
1 parent b390a92 commit daae58d
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Src/Product.API/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16980846711034705
17088716062710207
1 change: 1 addition & 0 deletions Src/Product.Application/Product.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="MediatR" Version="12.1.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using FluentValidation;
using MediatR;

namespace Product.Application.Product.Commands;

public sealed class CreateProductCommandHandler : IRequestHandler<CreateProductCommand>
{
public Task Handle(CreateProductCommand request, CancellationToken cancellationToken)
private readonly IValidator<CreateProductCommand> _validator;
public CreateProductCommandHandler(IValidator<CreateProductCommand> validator)
{
_validator = validator;
}
public Task Handle(CreateProductCommand command, CancellationToken cancellationToken)
{
_validator.ValidateAndThrow(command);
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
using FluentValidation;

namespace Product.Application.Product.Commands;

public class CreateProductCommandValidator
public class CreateProductCommandValidator : AbstractValidator<CreateProductCommand>
{

public CreateProductCommandValidator()
{

RuleFor(command => command.Title)
.NotEmpty()
.NotNull()
.WithMessage("The title can't be empty.");

RuleFor(command => command.Description)
.NotEmpty()
.NotNull()
.WithMessage("The description can't be empty.");

RuleFor(command => command.CategoryId)
.NotEqual(0)
.NotEmpty()
.NotNull()
.WithMessage("The category identifier can't be empty.");
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"net7.0": {
"targetAlias": "net7.0",
"dependencies": {
"FluentValidation": {
"target": "Package",
"version": "[11.9.0, )"
},
"MediatR": {
"target": "Package",
"version": "[12.1.1, )"
Expand Down
43 changes: 43 additions & 0 deletions Src/Product.Application/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
"version": 3,
"targets": {
"net7.0": {
"FluentValidation/11.9.0": {
"type": "package",
"compile": {
"lib/net7.0/FluentValidation.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net7.0/FluentValidation.dll": {
"related": ".xml"
}
}
},
"MediatR/12.1.1": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -51,6 +64,31 @@
}
},
"libraries": {
"FluentValidation/11.9.0": {
"sha512": "VneVlTvwYDkfHV5av3QrQ0amALgrLX6LV94wlYyEsh0B/klJBW7C8y2eAtj5tOZ3jH6CAVpr4s1ZGgew/QWyig==",
"type": "package",
"path": "fluentvalidation/11.9.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"README.md",
"fluent-validation-icon.png",
"fluentvalidation.11.9.0.nupkg.sha512",
"fluentvalidation.nuspec",
"lib/net5.0/FluentValidation.dll",
"lib/net5.0/FluentValidation.xml",
"lib/net6.0/FluentValidation.dll",
"lib/net6.0/FluentValidation.xml",
"lib/net7.0/FluentValidation.dll",
"lib/net7.0/FluentValidation.xml",
"lib/net8.0/FluentValidation.dll",
"lib/net8.0/FluentValidation.xml",
"lib/netstandard2.0/FluentValidation.dll",
"lib/netstandard2.0/FluentValidation.xml",
"lib/netstandard2.1/FluentValidation.dll",
"lib/netstandard2.1/FluentValidation.xml"
]
},
"MediatR/12.1.1": {
"sha512": "1AbwzzeS6gn4NdcO6A9LfKS5TXXgAiUQM3J18dREHa7O7TrdCXJ5dNFeRBpzPZY7UWl5Kby+n9pWrPJe3SDiMA==",
"type": "package",
Expand Down Expand Up @@ -109,6 +147,7 @@
},
"projectFileDependencyGroups": {
"net7.0": [
"FluentValidation >= 11.9.0",
"MediatR >= 12.1.1"
]
},
Expand Down Expand Up @@ -149,6 +188,10 @@
"net7.0": {
"targetAlias": "net7.0",
"dependencies": {
"FluentValidation": {
"target": "Package",
"version": "[11.9.0, )"
},
"MediatR": {
"target": "Package",
"version": "[12.1.1, )"
Expand Down
3 changes: 2 additions & 1 deletion Src/Product.Application/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"version": 2,
"dgSpecHash": "dOjFLWHI6F9yGwMa4Fcb7kIkeWN16oW8Vgte7gAFoH06Ca6L0sY5QKAWKePsQAUwt5Nbht2mqx7L68gWMZooIw==",
"dgSpecHash": "FJnjtZBeNcJKOQh06yKLmPe9Qf2dIT/hZxgh/hl2NOc+Pw17D1ZN0ea4YHyI++/BBS87ysV9mmsyUMLDJStPOQ==",
"success": true,
"projectFilePath": "/Users/macbook/Projects/ProductService/Src/Product.Application/Product.Application.csproj",
"expectedPackageFiles": [
"/Users/macbook/.nuget/packages/fluentvalidation/11.9.0/fluentvalidation.11.9.0.nupkg.sha512",
"/Users/macbook/.nuget/packages/mediatr/12.1.1/mediatr.12.1.1.nupkg.sha512",
"/Users/macbook/.nuget/packages/mediatr.contracts/2.0.1/mediatr.contracts.2.0.1.nupkg.sha512",
"/Users/macbook/.nuget/packages/microsoft.extensions.dependencyinjection.abstractions/6.0.0/microsoft.extensions.dependencyinjection.abstractions.6.0.0.nupkg.sha512"
Expand Down
2 changes: 1 addition & 1 deletion Src/Product.Application/obj/project.packagespec.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"restore":{"projectUniqueName":"/Users/macbook/Projects/ProductService/Src/Product.Application/Product.Application.csproj","projectName":"Product.Application","projectPath":"/Users/macbook/Projects/ProductService/Src/Product.Application/Product.Application.csproj","outputPath":"/Users/macbook/Projects/ProductService/Src/Product.Application/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net7.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net7.0":{"targetAlias":"net7.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net7.0":{"targetAlias":"net7.0","dependencies":{"MediatR":{"target":"Package","version":"[12.1.1, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/usr/local/share/dotnet/sdk/7.0.101/RuntimeIdentifierGraph.json"}}
"restore":{"projectUniqueName":"/Users/macbook/Projects/ProductService/Src/Product.Application/Product.Application.csproj","projectName":"Product.Application","projectPath":"/Users/macbook/Projects/ProductService/Src/Product.Application/Product.Application.csproj","outputPath":"/Users/macbook/Projects/ProductService/Src/Product.Application/obj/","projectStyle":"PackageReference","originalTargetFrameworks":["net7.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net7.0":{"targetAlias":"net7.0","projectReferences":{}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net7.0":{"targetAlias":"net7.0","dependencies":{"FluentValidation":{"target":"Package","version":"[11.9.0, )"},"MediatR":{"target":"Package","version":"[12.1.1, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"/usr/local/share/dotnet/sdk/7.0.101/RuntimeIdentifierGraph.json"}}
2 changes: 1 addition & 1 deletion Src/Product.Application/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16980846711026383
17088716062586781
2 changes: 1 addition & 1 deletion Src/Product.Domain/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16980846711016059
17088716062584938
2 changes: 1 addition & 1 deletion Src/Product.Infrastructure/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16980846710948453
17088716062589583
2 changes: 1 addition & 1 deletion Src/Product.Ioc/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16980846711025474
17088716062591402
2 changes: 1 addition & 1 deletion Tests/Product.Api.Tests/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16982528223799853
17088716063485879
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16982527597733111
17088716063478327
2 changes: 1 addition & 1 deletion Tests/Product.Domain.Tests/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16982527748488714
17088716063485559
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16982527967448123
17088716063484379

0 comments on commit daae58d

Please sign in to comment.