Validators
Overview
All input validation is performed using FluentValidation in the Ampra.Application/Validators/ directory. Validators are registered in the DI container and executed automatically by controller model binding. Validation failures return 400 Bad Request with a structured error body.
Error response format:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"FieldName": ["Error message 1", "Error message 2"]
}
}
Authentication Validators
RegisterRequestValidator
Validates new user registration requests.
| Field | Rule | Constraint |
|---|---|---|
Email | Not empty | Required |
Email | Valid email format | Standard email regex |
Password | Not empty | Required |
Password | Minimum length | ≥ 8 characters |
FirstName | Not empty | Required |
LastName | Not empty | Required |
LoginRequestValidator
Validates user login requests.
| Field | Rule | Constraint |
|---|---|---|
Email | Not empty | Required |
Password | Not empty | Required |
VerifyEmailRequestValidator
Validates email verification code submissions.
| Field | Rule | Constraint |
|---|---|---|
Email | Not empty | Required |
Email | Valid email format | Standard email regex |
Code | Not empty | Required |
ResendCodeRequestValidator
Validates verification code resend requests.
| Field | Rule | Constraint |
|---|---|---|
Email | Not empty | Required |
Email | Valid email format | Standard email regex |
Sun Source Validators
CreateSunSourceRequestValidator
Validates new sun source creation with strict geolocation and capacity bounds.
| Field | Rule | Constraint |
|---|---|---|
Name | Not empty | Required |
Name | Maximum length | ≤ 100 characters |
ConnectionType | Not empty | Required |
Latitude | Inclusive range | −90.0 to 90.0 |
Longitude | Inclusive range | −180.0 to 180.0 |
Capacity | Inclusive range | 0 to 1,000,000 watts |
UpdateSunSourceRequestValidator
Validates sun source updates — less strict than creation since only provided fields are applied.
| Field | Rule | Constraint |
|---|---|---|
Name | Maximum length | ≤ 100 characters (when provided) |
Description | Maximum length | ≤ 500 characters (when provided) |
Currency | Maximum length | ≤ 3 characters (ISO 4217) |
Power Group Validators
CreatePowerGroupRequestValidator
| Field | Rule | Constraint |
|---|---|---|
Name | Not empty | Required |
Name | Maximum length | ≤ 100 characters |
Description | Maximum length | ≤ 500 characters (when provided) |
UpdatePowerGroupRequestValidator
| Field | Rule | Constraint |
|---|---|---|
Name | Not empty | Required |
Name | Maximum length | ≤ 100 characters |
Description | Maximum length | ≤ 500 characters (when provided) |
ROI Validators
CreateKwhPriceRequestValidator
Validates new electricity price record creation.
| Field | Rule | Constraint |
|---|---|---|
PricePerKwh | Greater than or equal to | ≥ 0.0 |
EffectiveFrom | Not empty | Required |
UpdateKwhPriceRequestValidator
Validates electricity price record updates.
| Field | Rule | Constraint |
|---|---|---|
PricePerKwh | Greater than or equal to | ≥ 0.0 |
EffectiveFrom | Not empty | Required |
Validation Constants Summary
A consolidated reference of all numeric constraints applied across the validator suite:
| Constraint | Value | Applied To |
|---|---|---|
| Latitude range | −90 to +90 | CreateSunSourceRequest.Latitude |
| Longitude range | −180 to +180 | CreateSunSourceRequest.Longitude |
| Capacity range | 0 to 1,000,000 W | CreateSunSourceRequest.Capacity |
| Name max length | 100 characters | Sun source name, power group name |
| Description max length | 500 characters | Sun source description, power group description |
| Currency max length | 3 characters | Sun source currency (ISO 4217) |
| Password min length | 8 characters | Registration password |
| Price minimum | 0.0 | KWh price per unit |