feat: add Person search endpoint with SearchPersons method
This commit is contained in:
@@ -15,6 +15,7 @@ namespace Complex.Application.PersonService
|
|||||||
public ResultDto<string> InsertPerson(PersonDto person);
|
public ResultDto<string> InsertPerson(PersonDto person);
|
||||||
public ResultDto<bool> EditPerson(PersonDto person);
|
public ResultDto<bool> EditPerson(PersonDto person);
|
||||||
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj);
|
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj);
|
||||||
|
public ResultDto<List<PersonDto>> SearchPersons(string? searchTerm);
|
||||||
}
|
}
|
||||||
public class PersonService : IPersonService
|
public class PersonService : IPersonService
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,33 @@ namespace Complex.Application.PersonService
|
|||||||
_mapper = mapper;
|
_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)
|
public ResultDto<List<PersonDto>> GetAllPersons(PersonDto personSearchObj)
|
||||||
{
|
{
|
||||||
var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber);
|
var persons = _complexDBContext.ComplexPersons.Where(u => u.ComplexId == personSearchObj.ComplexId).Select(cp => cp.PersonMobileNumber);
|
||||||
|
|||||||
@@ -37,5 +37,14 @@ namespace Complex.EndPoint.Controllers
|
|||||||
var persons = _personService.GetAllPersons(personSearchObj);
|
var persons = _personService.GetAllPersons(personSearchObj);
|
||||||
return persons;
|
return persons;
|
||||||
}
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public ResultDto<List<PersonDto>> SearchPersons([FromBody] PersonSearchRequest request)
|
||||||
|
{
|
||||||
|
return _personService.SearchPersons(request.SearchTerm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class PersonSearchRequest
|
||||||
|
{
|
||||||
|
public string? SearchTerm { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user