Skip to content

Commit efbd9cc

Browse files
author
Rocco De Luca
committed
FluentValidation e Rate Limiting implementati
1 parent 44324ec commit efbd9cc

15 files changed

+104
-1246
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace IndustrialSecureApi.Features.Sensors.Dtos;
2+
3+
public record CreateSensorReadingDto
4+
{
5+
public string Tag { get; init; } = string.Empty;
6+
public double Value { get; init; }
7+
public DateTime Timestamp { get; init; }
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FluentValidation;
2+
using IndustrialSecureApi.Features.Sensors.Dtos;
3+
4+
namespace IndustrialSecureApi.Features.Sensors.Validators;
5+
6+
public class CreateSensorReadingDtoValidator : AbstractValidator<CreateSensorReadingDto>
7+
{
8+
public CreateSensorReadingDtoValidator()
9+
{
10+
RuleFor(x => x.Tag)
11+
.NotEmpty().WithMessage("Tag è obbligatorio")
12+
.MaximumLength(100).WithMessage("Tag non può superare 100 caratteri");
13+
14+
RuleFor(x => x.Value)
15+
.GreaterThanOrEqualTo(-50).WithMessage("Value deve essere >= -50")
16+
.LessThanOrEqualTo(200).WithMessage("Value deve essere <= 200");
17+
18+
RuleFor(x => x.Timestamp)
19+
.NotEmpty().WithMessage("Timestamp è obbligatorio");
20+
}
21+
}

src/IndustrialSecureApi/IndustrialSecureApi.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
13+
<PackageReference Include="FluentValidation" Version="12.1.1" />
14+
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.1" />
1215
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
1316
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
1417
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />

src/IndustrialSecureApi/Infrastructure/ApplicationDbContext.cs renamed to src/IndustrialSecureApi/Infrastructure/Data/ApplicationDbContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
33
using Microsoft.EntityFrameworkCore;
44
using System.Linq;
5-
using IndustrialSecureApi.Infrastructure;
65
using IndustrialSecureApi.Features.Sensors;
76
using System.Text.Json;
87

src/IndustrialSecureApi/Infrastructure/ApplicationUser.cs renamed to src/IndustrialSecureApi/Infrastructure/Models/ApplicationUser.cs

File renamed without changes.
File renamed without changes.

src/IndustrialSecureApi/Features/Sensors/SensorReading.cs renamed to src/IndustrialSecureApi/Infrastructure/Models/SensorReading.cs

File renamed without changes.

src/IndustrialSecureApi/Infrastructure/UserRefreshToken.cs renamed to src/IndustrialSecureApi/Infrastructure/Models/UserRefreshToken.cs

File renamed without changes.

src/IndustrialSecureApi/Infrastructure/DataSeeder.cs renamed to src/IndustrialSecureApi/Infrastructure/Seeders/DataSeeder.cs

File renamed without changes.

0 commit comments

Comments
 (0)