Skip to main content

Validators

Input Validation Rules & Constraints

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.

FieldRuleConstraint
EmailNot emptyRequired
EmailValid email formatStandard email regex
PasswordNot emptyRequired
PasswordMinimum length≥ 8 characters
FirstNameNot emptyRequired
LastNameNot emptyRequired

LoginRequestValidator

Validates user login requests.

FieldRuleConstraint
EmailNot emptyRequired
PasswordNot emptyRequired

VerifyEmailRequestValidator

Validates email verification code submissions.

FieldRuleConstraint
EmailNot emptyRequired
EmailValid email formatStandard email regex
CodeNot emptyRequired

ResendCodeRequestValidator

Validates verification code resend requests.

FieldRuleConstraint
EmailNot emptyRequired
EmailValid email formatStandard email regex

Sun Source Validators

CreateSunSourceRequestValidator

Validates new sun source creation with strict geolocation and capacity bounds.

FieldRuleConstraint
NameNot emptyRequired
NameMaximum length≤ 100 characters
ConnectionTypeNot emptyRequired
LatitudeInclusive range−90.0 to 90.0
LongitudeInclusive range−180.0 to 180.0
CapacityInclusive range0 to 1,000,000 watts

UpdateSunSourceRequestValidator

Validates sun source updates — less strict than creation since only provided fields are applied.

FieldRuleConstraint
NameMaximum length≤ 100 characters (when provided)
DescriptionMaximum length≤ 500 characters (when provided)
CurrencyMaximum length≤ 3 characters (ISO 4217)

Power Group Validators

CreatePowerGroupRequestValidator

FieldRuleConstraint
NameNot emptyRequired
NameMaximum length≤ 100 characters
DescriptionMaximum length≤ 500 characters (when provided)

UpdatePowerGroupRequestValidator

FieldRuleConstraint
NameNot emptyRequired
NameMaximum length≤ 100 characters
DescriptionMaximum length≤ 500 characters (when provided)

ROI Validators

CreateKwhPriceRequestValidator

Validates new electricity price record creation.

FieldRuleConstraint
PricePerKwhGreater than or equal to≥ 0.0
EffectiveFromNot emptyRequired

UpdateKwhPriceRequestValidator

Validates electricity price record updates.

FieldRuleConstraint
PricePerKwhGreater than or equal to≥ 0.0
EffectiveFromNot emptyRequired

Validation Constants Summary

A consolidated reference of all numeric constraints applied across the validator suite:

ConstraintValueApplied To
Latitude range−90 to +90CreateSunSourceRequest.Latitude
Longitude range−180 to +180CreateSunSourceRequest.Longitude
Capacity range0 to 1,000,000 WCreateSunSourceRequest.Capacity
Name max length100 charactersSun source name, power group name
Description max length500 charactersSun source description, power group description
Currency max length3 charactersSun source currency (ISO 4217)
Password min length8 charactersRegistration password
Price minimum0.0KWh price per unit