From e2afe8af9a524bb7344b5fa27e6f7e6e63e9d419 Mon Sep 17 00:00:00 2001 From: alireza Date: Tue, 9 Jun 2026 01:29:57 +0330 Subject: [PATCH] feat: add Person search endpoint with SearchPersons method --- .../Services/PersonService/PersonService.cs | 28 +++++++++++++++++++ .../Controllers/PersonController.cs | 9 ++++++ 2 files changed, 37 insertions(+) diff --git a/Complex.Application/Services/PersonService/PersonService.cs b/Complex.Application/Services/PersonService/PersonService.cs index 6eaeed4..a70d08c 100644 --- a/Complex.Application/Services/PersonService/PersonService.cs +++ b/Complex.Application/Services/PersonService/PersonService.cs @@ -15,6 +15,7 @@ namespace Complex.Application.PersonService public ResultDto InsertPerson(PersonDto person); public ResultDto EditPerson(PersonDto person); public ResultDto> GetAllPersons(PersonDto personSearchObj); + public ResultDto> SearchPersons(string? searchTerm); } public class PersonService : IPersonService { @@ -26,6 +27,33 @@ namespace Complex.Application.PersonService _mapper = mapper; } + public ResultDto> SearchPersons(string? searchTerm) + { + var query = _complexDBContext.Persons.AsQueryable(); + if (!string.IsNullOrEmpty(searchTerm)) + { + query = query.Where(p => + p.FirstName.Contains(searchTerm) || + p.LastName.Contains(searchTerm) || + p.Id.Contains(searchTerm)); + } + var result = query.Select(p => new PersonDto + { + MobileNumber = p.Id, + FirstName = p.FirstName, + LastName = p.LastName, + Gender = p.Gender, + Avatar = p.Avatar + }).ToList(); + + return new ResultDto> + { + Data = result, + IsSuccess = true, + RowCount = result.Count + }; + } + public ResultDto> GetAllPersons(PersonDto personSearchObj) { var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber); diff --git a/Complex.EndPoint/Controllers/PersonController.cs b/Complex.EndPoint/Controllers/PersonController.cs index f0f0d61..009143c 100644 --- a/Complex.EndPoint/Controllers/PersonController.cs +++ b/Complex.EndPoint/Controllers/PersonController.cs @@ -37,5 +37,14 @@ namespace Complex.EndPoint.Controllers var persons = _personService.GetAllPersons(personSearchObj); return persons; } + [HttpPost] + public ResultDto> SearchPersons([FromBody] PersonSearchRequest request) + { + return _personService.SearchPersons(request.SearchTerm); + } + } + public class PersonSearchRequest + { + public string? SearchTerm { get; set; } } }