refactor: use ivalidatableobject api
This commit is contained in:
@@ -1,8 +1,21 @@
|
|||||||
|
|
||||||
namespace FiscalOS.API.Login;
|
namespace FiscalOS.API.Login;
|
||||||
|
|
||||||
public record LoginRequest(
|
public record LoginRequest : IValidatableObject
|
||||||
[Required]
|
{
|
||||||
string Username,
|
public string Username { get; init; } = string.Empty;
|
||||||
[Required]
|
public string Password { get; init; } = string.Empty;
|
||||||
string Password
|
|
||||||
);
|
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