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>(StatusCodes.Status200OK)] public async Task SearchAsync([FromQuery] string query) { if (query == null) { return Ok(new List()); } var args = Regex.Split(query, "\\s").Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray(); return Ok(await tapiDirectory.SearchAsync(args)); } }