From daae58dab8cd7c10aa7cb177f6099aa9e7dad865 Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Sun, 25 Feb 2024 18:08:49 +0330 Subject: [PATCH] feat: add create product command validatior --- .../obj/rider.project.restore.info | 2 +- .../Product.Application.csproj | 1 + .../CreateProductCommandHandler.cs | 9 +++- .../CreateProductCommandValidator.cs | 24 +++++++++- .../net7.0/Product.Application.assets.cache | Bin 1943 -> 2402 bytes ...Application.csproj.AssemblyReference.cache | Bin 74883 -> 75315 bytes ...oduct.Application.csproj.nuget.dgspec.json | 4 ++ .../obj/project.assets.json | 43 ++++++++++++++++++ .../obj/project.nuget.cache | 3 +- .../obj/project.packagespec.json | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- .../obj/rider.project.restore.info | 2 +- 18 files changed, 90 insertions(+), 14 deletions(-) diff --git a/Src/Product.API/obj/rider.project.restore.info b/Src/Product.API/obj/rider.project.restore.info index 1af2077..0ea6103 100644 --- a/Src/Product.API/obj/rider.project.restore.info +++ b/Src/Product.API/obj/rider.project.restore.info @@ -1 +1 @@ -16980846711034705 \ No newline at end of file +17088716062710207 \ No newline at end of file diff --git a/Src/Product.Application/Product.Application.csproj b/Src/Product.Application/Product.Application.csproj index dac2cc7..38f8a1f 100644 --- a/Src/Product.Application/Product.Application.csproj +++ b/Src/Product.Application/Product.Application.csproj @@ -7,6 +7,7 @@ + diff --git a/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandHandler.cs b/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandHandler.cs index 52e60f1..678bf40 100644 --- a/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandHandler.cs +++ b/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandHandler.cs @@ -1,11 +1,18 @@ +using FluentValidation; using MediatR; namespace Product.Application.Product.Commands; public sealed class CreateProductCommandHandler : IRequestHandler { - public Task Handle(CreateProductCommand request, CancellationToken cancellationToken) + private readonly IValidator _validator; + public CreateProductCommandHandler(IValidator validator) { + _validator = validator; + } + public Task Handle(CreateProductCommand command, CancellationToken cancellationToken) + { + _validator.ValidateAndThrow(command); throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandValidator.cs b/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandValidator.cs index 9850f5e..6b55e72 100644 --- a/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandValidator.cs +++ b/Src/Product.Application/Product/Commands/CreateProduct/CreateProductCommandValidator.cs @@ -1,6 +1,26 @@ +using FluentValidation; + namespace Product.Application.Product.Commands; -public class CreateProductCommandValidator +public class CreateProductCommandValidator : AbstractValidator { - + 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."); + } } \ No newline at end of file diff --git a/Src/Product.Application/obj/Debug/net7.0/Product.Application.assets.cache b/Src/Product.Application/obj/Debug/net7.0/Product.Application.assets.cache index 405520e160848cdde239ec46db22c93c10ec2166..9d36e65c1c836044165170d8277788f0844abc4f 100644 GIT binary patch literal 2402 zcmd5;&2G~`5Kd`+2&KR251fj`1##G|BSGmgYM_c}QN&LUT+qhewx-THc-K{P=$$hU z&^|yPfIC+X`2EICg4_;SlEvg_!7%wbuu%)&Eey999ZPXHaKD&zCan{m zKHD27N&FINvz}2%^uy#P!QhjQhqb{)8GLi*lE9R?6J;#Hq>R1YOeINErea4X)pQtJ z*b`i|=?I5oYaVO?Y!Pe;tOB+Sc5_k?U`h%E#&I?Zcm>WUN*a`P?Bxi%du^nDA|6-IcmubZ zMUxR*>`UQl>^>xg*N1N*(z7SAd#0X^H>V4cCe>+9bo#?mDG@*i}Gy`%sD delta 352 zcmaDPG@aitz}wxCn}LBra4SP8hxDudIXk$1KDl0E>Ep1^v`byOvE=h#E{|Q!yI!#Z z6@kFyIA+g@Z@DK<7n%H-HDPiNBge!aB9o0+=1tCIloy4lK_!_d=QFiWPGk<89LdZB z)D$~enuUAf4<4YVmAsrlwM;C zN(xQZXIVHofK9$0n^s|ZRo5O#aROZ895Y3;-$~R388U diff --git a/Src/Product.Application/obj/Debug/net7.0/Product.Application.csproj.AssemblyReference.cache b/Src/Product.Application/obj/Debug/net7.0/Product.Application.csproj.AssemblyReference.cache index 1252bd143343d81f9403fdf251f57752c550d8ae..113564ae9d3f8d14129250c359e88d1e0d605f66 100644 GIT binary patch delta 335 zcmZoZ$+Gzj3kMtHas~zl#@NY@e4dlDjKhj~OPnD?8^{DYJz8hO4|kwezOwo(ucKq<*|JV%luq z;TDjv_jyu|cl2fTyx89B`kQ#FTbJ1!Up002%f*c)GiNdxa+^0X9^WuWuUzf$TEWF^ zON@WLUs|wh7vZTd%81Cwl4JW#j<5v-YXSE&W{& uJ}`!$J5xs?EVZZ@=x= 11.9.0", "MediatR >= 12.1.1" ] }, @@ -149,6 +188,10 @@ "net7.0": { "targetAlias": "net7.0", "dependencies": { + "FluentValidation": { + "target": "Package", + "version": "[11.9.0, )" + }, "MediatR": { "target": "Package", "version": "[12.1.1, )" diff --git a/Src/Product.Application/obj/project.nuget.cache b/Src/Product.Application/obj/project.nuget.cache index 6dea78d..11dfe0e 100644 --- a/Src/Product.Application/obj/project.nuget.cache +++ b/Src/Product.Application/obj/project.nuget.cache @@ -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" diff --git a/Src/Product.Application/obj/project.packagespec.json b/Src/Product.Application/obj/project.packagespec.json index 1c6f41b..03b4543 100644 --- a/Src/Product.Application/obj/project.packagespec.json +++ b/Src/Product.Application/obj/project.packagespec.json @@ -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"}} \ No newline at end of file +"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"}} \ No newline at end of file diff --git a/Src/Product.Application/obj/rider.project.restore.info b/Src/Product.Application/obj/rider.project.restore.info index 3ccb1b8..6a127e3 100644 --- a/Src/Product.Application/obj/rider.project.restore.info +++ b/Src/Product.Application/obj/rider.project.restore.info @@ -1 +1 @@ -16980846711026383 \ No newline at end of file +17088716062586781 \ No newline at end of file diff --git a/Src/Product.Domain/obj/rider.project.restore.info b/Src/Product.Domain/obj/rider.project.restore.info index 2c8bf9b..e4d4724 100644 --- a/Src/Product.Domain/obj/rider.project.restore.info +++ b/Src/Product.Domain/obj/rider.project.restore.info @@ -1 +1 @@ -16980846711016059 \ No newline at end of file +17088716062584938 \ No newline at end of file diff --git a/Src/Product.Infrastructure/obj/rider.project.restore.info b/Src/Product.Infrastructure/obj/rider.project.restore.info index 1398889..8582a15 100644 --- a/Src/Product.Infrastructure/obj/rider.project.restore.info +++ b/Src/Product.Infrastructure/obj/rider.project.restore.info @@ -1 +1 @@ -16980846710948453 \ No newline at end of file +17088716062589583 \ No newline at end of file diff --git a/Src/Product.Ioc/obj/rider.project.restore.info b/Src/Product.Ioc/obj/rider.project.restore.info index a5a7e87..4e50649 100644 --- a/Src/Product.Ioc/obj/rider.project.restore.info +++ b/Src/Product.Ioc/obj/rider.project.restore.info @@ -1 +1 @@ -16980846711025474 \ No newline at end of file +17088716062591402 \ No newline at end of file diff --git a/Tests/Product.Api.Tests/obj/rider.project.restore.info b/Tests/Product.Api.Tests/obj/rider.project.restore.info index b84c850..b629624 100644 --- a/Tests/Product.Api.Tests/obj/rider.project.restore.info +++ b/Tests/Product.Api.Tests/obj/rider.project.restore.info @@ -1 +1 @@ -16982528223799853 \ No newline at end of file +17088716063485879 \ No newline at end of file diff --git a/Tests/Product.Application.Tests/obj/rider.project.restore.info b/Tests/Product.Application.Tests/obj/rider.project.restore.info index b76c05f..0c5a41b 100644 --- a/Tests/Product.Application.Tests/obj/rider.project.restore.info +++ b/Tests/Product.Application.Tests/obj/rider.project.restore.info @@ -1 +1 @@ -16982527597733111 \ No newline at end of file +17088716063478327 \ No newline at end of file diff --git a/Tests/Product.Domain.Tests/obj/rider.project.restore.info b/Tests/Product.Domain.Tests/obj/rider.project.restore.info index 89816e4..c929c48 100644 --- a/Tests/Product.Domain.Tests/obj/rider.project.restore.info +++ b/Tests/Product.Domain.Tests/obj/rider.project.restore.info @@ -1 +1 @@ -16982527748488714 \ No newline at end of file +17088716063485559 \ No newline at end of file diff --git a/Tests/Product.Infrastructure.Tests/obj/rider.project.restore.info b/Tests/Product.Infrastructure.Tests/obj/rider.project.restore.info index 4ae67d9..2159824 100644 --- a/Tests/Product.Infrastructure.Tests/obj/rider.project.restore.info +++ b/Tests/Product.Infrastructure.Tests/obj/rider.project.restore.info @@ -1 +1 @@ -16982527967448123 \ No newline at end of file +17088716063484379 \ No newline at end of file