Merge branch 'Validation' into dev

This commit is contained in:
Харченко Владимир 2022-01-10 16:01:06 +05:00
commit 42c5974d68
3 changed files with 27 additions and 0 deletions

View File

@ -18,6 +18,7 @@
<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.95.4" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.3.6" />
<PackageReference Include="Google.Apis.Drive.v3" Version="1.55.0.2481" />
<PackageReference Include="itext7" Version="7.2.0" />
<PackageReference Include="Mapster" Version="7.2.0" />

View File

@ -5,10 +5,13 @@ using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Analysis;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.WellOperationService;
using AsbCloudInfrastructure.Validators;
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<AsbCloudDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));
services.AddFluentValidation();
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
services.AddScoped<IFileShareService, GoogleDriveService>();
@ -74,6 +79,9 @@ namespace AsbCloudInfrastructure
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
// Validation rules
services.AddTransient<IValidator<AuthDto>, AuthDtoValidator>();
return services;
}

View File

@ -0,0 +1,18 @@
using AsbCloudApp.Data;
using FluentValidation;
namespace AsbCloudInfrastructure.Validators
{
public class AuthDtoValidator : AbstractValidator<AuthDto>
{
public AuthDtoValidator()
{
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 символов");
}
}
}