88 lines
2.0 KiB
C#
88 lines
2.0 KiB
C#
using FluentValidation;
|
|
using Heimdall.Application.DTOs;
|
|
|
|
namespace Heimdall.Application.Validators;
|
|
|
|
public class CreateSiteValidator : AbstractValidator<CreateSiteRequest>
|
|
{
|
|
public CreateSiteValidator()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty()
|
|
.MaximumLength(200);
|
|
|
|
RuleFor(x => x.Address)
|
|
.MaximumLength(500)
|
|
.When(x => x.Address is not null);
|
|
|
|
RuleFor(x => x.Timezone)
|
|
.Must(tz => string.IsNullOrEmpty(tz) || IsValidTimezone(tz))
|
|
.WithMessage("Invalid timezone. Use IANA timezone format (e.g., 'Europe/Paris').");
|
|
}
|
|
|
|
private static bool IsValidTimezone(string timezone)
|
|
{
|
|
try
|
|
{
|
|
_ = TimeZoneInfo.FindSystemTimeZoneById(timezone);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class RegisterAgentValidator : AbstractValidator<RegisterAgentRequest>
|
|
{
|
|
public RegisterAgentValidator()
|
|
{
|
|
RuleFor(x => x.Token)
|
|
.NotEmpty()
|
|
.MaximumLength(500);
|
|
|
|
RuleFor(x => x.Hostname)
|
|
.NotEmpty()
|
|
.MaximumLength(255);
|
|
|
|
RuleFor(x => x.Version)
|
|
.MaximumLength(50);
|
|
}
|
|
}
|
|
|
|
public class LoginRequestValidator : AbstractValidator<LoginRequest>
|
|
{
|
|
public LoginRequestValidator()
|
|
{
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty()
|
|
.EmailAddress()
|
|
.MaximumLength(200);
|
|
|
|
RuleFor(x => x.Password)
|
|
.NotEmpty()
|
|
.MaximumLength(200);
|
|
}
|
|
}
|
|
|
|
public class RegisterRequestValidator : AbstractValidator<RegisterRequest>
|
|
{
|
|
public RegisterRequestValidator()
|
|
{
|
|
RuleFor(x => x.Email)
|
|
.NotEmpty()
|
|
.EmailAddress()
|
|
.MaximumLength(200);
|
|
|
|
RuleFor(x => x.Password)
|
|
.NotEmpty()
|
|
.MinimumLength(12)
|
|
.MaximumLength(200);
|
|
|
|
RuleFor(x => x.DisplayName)
|
|
.NotEmpty()
|
|
.MaximumLength(200);
|
|
}
|
|
}
|