CS2-125: Added FluentValidation lib and AuthDto validation

This commit is contained in:
Харченко Владимир 2021-12-27 17:35:49 +05:00
parent 46c244a7d7
commit 9f4e7764be
3 changed files with 25 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.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<AsbCloudDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));
services.AddFluentValidation();
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
services.AddScoped<IFileShareService, GoogleDriveService>();
@ -73,6 +78,9 @@ namespace AsbCloudInfrastructure
// TelemetryData services
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
services.AddTransient<ITelemetryDataService<TelemetryDataSpinDto>, TelemetryDataSpinService>();
// Validation rules
services.AddTransient<IValidator<AuthDto>, AuthDtoValidator>();
return services;
}

View File

@ -0,0 +1,16 @@
using AsbCloudApp.Data;
using FluentValidation;
namespace AsbCloudInfrastructure.Validators.ValidatorsDto
{
public class AuthDtoValidator : AbstractValidator<AuthDto>
{
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);
}
}
}