From 2b91e3b791239ef0cefa2a3f22209c43283e7b74 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 1 Feb 2026 06:12:09 -0600 Subject: [PATCH] refactor: use ivalidatableobject api --- src/FiscalOS.API/Login/Request.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/FiscalOS.API/Login/Request.cs b/src/FiscalOS.API/Login/Request.cs index d793832..4f1ebf3 100644 --- a/src/FiscalOS.API/Login/Request.cs +++ b/src/FiscalOS.API/Login/Request.cs @@ -1,8 +1,21 @@ + namespace FiscalOS.API.Login; -public record LoginRequest( - [Required] - string Username, - [Required] - string Password -); \ No newline at end of file +public record LoginRequest : IValidatableObject +{ + public string Username { get; init; } = string.Empty; + public string Password { get; init; } = string.Empty; + + public IEnumerable 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)]); + } + } +} \ No newline at end of file