26 lines
757 B
C#
26 lines
757 B
C#
using System.Text.RegularExpressions;
|
|
using CPATapi.Server.Interfaces;
|
|
using CPATapi.Server.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CPATapi.Server.Controllers;
|
|
|
|
[Route("[controller]")]
|
|
[ApiController]
|
|
public class SearchController(ITapiDirectoryRepository tapiDirectory) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
[ProducesResponseType<IEnumerable<TapiContact>>(StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> SearchAsync([FromQuery] string query)
|
|
{
|
|
if (query == null)
|
|
{
|
|
return Ok(new List<TapiContact>());
|
|
}
|
|
|
|
var args = Regex.Split(query, "\\s").Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray();
|
|
|
|
return Ok(await tapiDirectory.SearchAsync(args));
|
|
}
|
|
}
|