31 lines
825 B
C#
31 lines
825 B
C#
using CPATapi.Server.Interfaces;
|
|
using CPATapi.Server.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace CPATapi.Server.Controllers;
|
|
|
|
[Route("[controller]")]
|
|
[ApiController]
|
|
public class CallerIdController(ITapiDirectoryRepository tapiDirectory) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
[Route("{number}")]
|
|
[ProducesResponseType<TapiContact>(StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> CallerIdAsync([FromRoute] string number)
|
|
{
|
|
if (number.Length >= 5)
|
|
{
|
|
var minMatch = number[^5..];
|
|
number = "%" + minMatch;
|
|
}
|
|
|
|
var result = await tapiDirectory.SearchByNumberAsync(number);
|
|
if (result != null)
|
|
{
|
|
return Ok(result);
|
|
}
|
|
return NotFound();
|
|
}
|
|
}
|