refactor: use ivalidatableobject api
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
|
||||
namespace FiscalOS.API.Login;
|
||||
|
||||
public record LoginRequest(
|
||||
[Required]
|
||||
string Username,
|
||||
[Required]
|
||||
string Password
|
||||
);
|
||||
public record LoginRequest : IValidatableObject
|
||||
{
|
||||
public string Username { get; init; } = string.Empty;
|
||||
public string Password { get; init; } = string.Empty;
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Username))
|
||||
{
|
||||
yield return new("The Username field is required.", [nameof(Username)]);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Password))
|
||||
{
|
||||
yield return new("The Password field is required.", [nameof(Password)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user