From 70f19208a0705564db65a0a0febda0fc5ee68e23 Mon Sep 17 00:00:00 2001 From: Roman Eriksen Date: Thu, 11 Sep 2025 12:45:12 +0200 Subject: [PATCH] Fixed get condition on name --- exercise.wwwapi/Endpoints/UserEndpoints.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/exercise.wwwapi/Endpoints/UserEndpoints.cs b/exercise.wwwapi/Endpoints/UserEndpoints.cs index 1f96a03..d61c216 100644 --- a/exercise.wwwapi/Endpoints/UserEndpoints.cs +++ b/exercise.wwwapi/Endpoints/UserEndpoints.cs @@ -33,14 +33,21 @@ public static void ConfigureAuthApi(this WebApplication app) [Authorize] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] - private static async Task GetUsers(IRepository service, string? firstName, ClaimsPrincipal user) + private static async Task GetUsers(IRepository service, string? name, ClaimsPrincipal user) { IEnumerable results = await service.Get(); - UsersSuccessDTO userData = new UsersSuccessDTO() { - Users = !string.IsNullOrEmpty(firstName) - ? results.Where(i => i.Email.Contains(firstName)).ToList() - : results.ToList() }; - ResponseDTO response = new ResponseDTO() + string? search = name?.Trim().ToLower(); + UsersSuccessDTO userData = new UsersSuccessDTO() + { + Users = !string.IsNullOrWhiteSpace(name) + ? results.Where(i => + (i.FirstName.ToLower().Contains(search)) || + (i.LastName.ToLower().Contains(search)) || + ($"{i.FirstName ?? ""} {i.LastName ?? ""}".ToLower().Contains(search)) + ).ToList() + : results.ToList() + }; + ResponseDTO response = new ResponseDTO() { Message = "success", Data = userData