feat: add Person search endpoint with SearchPersons method

This commit is contained in:
2026-06-09 01:29:57 +03:30
parent 9a42b96f41
commit e2afe8af9a
2 changed files with 37 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ namespace Complex.Application.PersonService
public ResultDto<string> InsertPerson(PersonDto person);
public ResultDto<bool> EditPerson(PersonDto person);
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj);
public ResultDto<List<PersonDto>> SearchPersons(string? searchTerm);
}
public class PersonService : IPersonService
{
@@ -26,6 +27,33 @@ namespace Complex.Application.PersonService
_mapper = mapper;
}
public ResultDto<List<PersonDto>> 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<List<PersonDto>>
{
Data = result,
IsSuccess = true,
RowCount = result.Count
};
}
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj)
{
var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber);

View File

@@ -37,5 +37,14 @@ namespace Complex.EndPoint.Controllers
var persons = _personService.GetAllPersons(personSearchObj);
return persons;
}
[HttpPost]
public ResultDto<List<PersonDto>> SearchPersons([FromBody] PersonSearchRequest request)
{
return _personService.SearchPersons(request.SearchTerm);
}
}
public class PersonSearchRequest
{
public string? SearchTerm { get; set; }
}
}