From 9f4e7764be10f38b4ee2bd2d1473bbb1b779160c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=80=D1=87=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=92?= =?UTF-8?q?=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80?= Date: Mon, 27 Dec 2021 17:35:49 +0500 Subject: [PATCH 1/3] CS2-125: Added FluentValidation lib and AuthDto validation --- .../AsbCloudInfrastructure.csproj | 1 + AsbCloudInfrastructure/DependencyInjection.cs | 8 ++++++++ .../Validators/ValidatorsDto/AuthDtoValidator.cs | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index 3d8d3d99..5a40baf6 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -18,6 +18,7 @@ + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 7eef6f57..0bdf0d75 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -5,10 +5,13 @@ using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Analysis; using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services.WellOperationService; +using AsbCloudInfrastructure.Validators.ValidatorsDto; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; +using FluentValidation; +using FluentValidation.AspNetCore; namespace AsbCloudInfrastructure { @@ -28,6 +31,8 @@ namespace AsbCloudInfrastructure services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))); + services.AddFluentValidation(); + services.AddScoped(provider => provider.GetService()); services.AddScoped(); @@ -73,6 +78,9 @@ namespace AsbCloudInfrastructure // TelemetryData services services.AddTransient, TelemetryDataSaubService>(); services.AddTransient, TelemetryDataSpinService>(); + + // Validation rules + services.AddTransient, AuthDtoValidator>(); return services; } diff --git a/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs b/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs new file mode 100644 index 00000000..d8009ba4 --- /dev/null +++ b/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs @@ -0,0 +1,16 @@ +using AsbCloudApp.Data; +using FluentValidation; + +namespace AsbCloudInfrastructure.Validators.ValidatorsDto +{ + public class AuthDtoValidator : AbstractValidator + { + public AuthDtoValidator() + { + RuleFor(x => x.Login).NotNull(); + RuleFor(x => x.Login).Length(0, 50); + RuleFor(x => x.Password).NotNull(); + RuleFor(x => x.Password).Length(0, 50); + } + } +} \ No newline at end of file From 42ed7f6ec73a796ce073695ce4ae50a453147748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=80=D1=87=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=92?= =?UTF-8?q?=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80?= Date: Tue, 28 Dec 2021 16:24:08 +0500 Subject: [PATCH 2/3] CS2-125: Enlarged Dto validation --- AsbCloudInfrastructure/DependencyInjection.cs | 2 +- .../ValidatorsDto/AuthDtoValidator.cs | 16 ---------------- .../dtoValidators/AuthDtoValidator.cs | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 17 deletions(-) delete mode 100644 AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs create mode 100644 AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 0bdf0d75..01dba6f0 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -5,7 +5,7 @@ using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Analysis; using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services.WellOperationService; -using AsbCloudInfrastructure.Validators.ValidatorsDto; +using AsbCloudInfrastructure.Validators.DtoValidators; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs b/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs deleted file mode 100644 index d8009ba4..00000000 --- a/AsbCloudInfrastructure/Validators/ValidatorsDto/AuthDtoValidator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using AsbCloudApp.Data; -using FluentValidation; - -namespace AsbCloudInfrastructure.Validators.ValidatorsDto -{ - public class AuthDtoValidator : AbstractValidator - { - public AuthDtoValidator() - { - RuleFor(x => x.Login).NotNull(); - RuleFor(x => x.Login).Length(0, 50); - RuleFor(x => x.Password).NotNull(); - RuleFor(x => x.Password).Length(0, 50); - } - } -} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs b/AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs new file mode 100644 index 00000000..4d783e36 --- /dev/null +++ b/AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs @@ -0,0 +1,18 @@ +using AsbCloudApp.Data; +using FluentValidation; + +namespace AsbCloudInfrastructure.Validators.DtoValidators +{ + public class AuthDtoValidator : AbstractValidator + { + public AuthDtoValidator() // Описание доступных для валидации методов https://docs.fluentvalidation.net/en/latest/built-in-validators.html + { + RuleFor(x => x.Login).NotNull().WithMessage("Логин не должен быть пустым"); + RuleFor(x => x.Login).NotEmpty().WithMessage("Логин не должен быть пустым"); + RuleFor(x => x.Login).Length(0, 50).WithMessage("Допустимая длина логина от 1 до 50 символов"); + RuleFor(x => x.Password).NotNull().WithMessage("Пароль не должен быть пустым"); + RuleFor(x => x.Password).NotEmpty().WithMessage("Пароль не должен быть пустым"); + RuleFor(x => x.Password).Length(0, 50).WithMessage("Допустимая длина пароля от 1 до 50 символов"); + } + } +} \ No newline at end of file From 831ef72be420826939c07b759d6d7f9bb5e78b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B0=D1=80=D1=87=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=92?= =?UTF-8?q?=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80?= Date: Mon, 10 Jan 2022 16:00:09 +0500 Subject: [PATCH 3/3] Removed dtoValidators folder --- AsbCloudInfrastructure/DependencyInjection.cs | 2 +- .../Validators/{dtoValidators => }/AuthDtoValidator.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename AsbCloudInfrastructure/Validators/{dtoValidators => }/AuthDtoValidator.cs (78%) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 01dba6f0..cd44db08 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -5,7 +5,7 @@ using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Analysis; using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services.WellOperationService; -using AsbCloudInfrastructure.Validators.DtoValidators; +using AsbCloudInfrastructure.Validators; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs b/AsbCloudInfrastructure/Validators/AuthDtoValidator.cs similarity index 78% rename from AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs rename to AsbCloudInfrastructure/Validators/AuthDtoValidator.cs index 4d783e36..e5ee7116 100644 --- a/AsbCloudInfrastructure/Validators/dtoValidators/AuthDtoValidator.cs +++ b/AsbCloudInfrastructure/Validators/AuthDtoValidator.cs @@ -1,11 +1,11 @@ using AsbCloudApp.Data; using FluentValidation; -namespace AsbCloudInfrastructure.Validators.DtoValidators +namespace AsbCloudInfrastructure.Validators { public class AuthDtoValidator : AbstractValidator { - public AuthDtoValidator() // Описание доступных для валидации методов https://docs.fluentvalidation.net/en/latest/built-in-validators.html + public AuthDtoValidator() { RuleFor(x => x.Login).NotNull().WithMessage("Логин не должен быть пустым"); RuleFor(x => x.Login).NotEmpty().WithMessage("Логин не должен быть пустым");