File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
backend/ServiceSimulation/Api Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 88
99 <ItemGroup >
1010 <PackageReference Include =" AutoMapper" Version =" 11.0.1" />
11+ <PackageReference Include =" FluentValidation.AspNetCore" Version =" 10.4.0" />
1112 <PackageReference Include =" Microsoft.AspNetCore.Cors" Version =" 2.2.0" />
1213 <PackageReference Include =" Swashbuckle.AspNetCore" Version =" 6.3.1" />
1314 </ItemGroup >
Original file line number Diff line number Diff line change 33using Bll . Domain . Entities ;
44using Bll . Domain . Factories ;
55using Bll . Domain . Interfaces ;
6- using Bll . Domain . Models ;
76using Bll . Domain . Services ;
7+ using FluentValidation . AspNetCore ;
8+ using System . Reflection ;
89
910var builder = WebApplication . CreateBuilder ( args ) ;
1011
11- builder . Services . AddControllers ( ) ;
12+ builder . Services . AddControllers ( ) . AddFluentValidation ( fv =>
13+ {
14+ fv . RegisterValidatorsFromAssembly ( Assembly . GetExecutingAssembly ( ) ) ;
15+ } ) ;
1216builder . Services . AddEndpointsApiExplorer ( ) ;
1317builder . Services . AddSwaggerGen ( ) ;
1418
3741} ) ;
3842#endregion
3943
44+
4045var app = builder . Build ( ) ;
4146
4247if ( app . Environment . IsDevelopment ( ) )
Original file line number Diff line number Diff line change 1+ using FluentValidation ;
2+ using Bll . Domain . Models ;
3+ using Api . enums ;
4+
5+ namespace Api . Validation
6+ {
7+ public class InputParametersValidator : AbstractValidator < InputParameters >
8+ {
9+ public InputParametersValidator ( )
10+ {
11+ RuleFor ( p => p . NumberOfSources ) . NotEmpty ( ) . InclusiveBetween ( 1 , 100 ) ;
12+ RuleFor ( p => p . NumberOfDevices ) . NotEmpty ( ) . InclusiveBetween ( 1 , 100 ) ;
13+ RuleFor ( p => p . AmountOfRequests ) . NotEmpty ( ) . InclusiveBetween ( 1 , 5000 ) ;
14+ RuleFor ( p => p . BufferSize ) . NotEmpty ( ) . InclusiveBetween ( 1 , 100 ) ;
15+ RuleFor ( p => p . LambdaForDevice ) . NotEmpty ( ) . ExclusiveBetween ( 0 , 10000 ) ;
16+ RuleFor ( p => p . NumberOfSources ) . NotEmpty ( ) . ExclusiveBetween ( 0 , 10000 ) ;
17+ RuleFor ( p => p . ModelingTime ) . NotEmpty ( ) . ExclusiveBetween ( 0 , 10000 ) ;
18+ RuleFor ( p => p . SimulationType ) . IsInEnum ( ) ;
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments