2025-04-04 14:58:44 -03:00
|
|
|
|
using Core.Interfaces;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2025-04-04 21:44:20 -03:00
|
|
|
|
using System.Reflection;
|
2025-04-04 14:58:44 -03:00
|
|
|
|
|
|
|
|
|
|
namespace phronCare.API.Controllers.Sales
|
|
|
|
|
|
{
|
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
public class CustomerController : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ICustomerDom _customerService;
|
|
|
|
|
|
public CustomerController(ICustomerDom customerService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_customerService = customerService ?? throw new ArgumentNullException(nameof(customerService));
|
|
|
|
|
|
}
|
2025-04-06 01:19:47 -03:00
|
|
|
|
[HttpGet("all")]
|
2025-04-06 01:35:31 -03:00
|
|
|
|
public async Task<IActionResult> GetAll([FromQuery] int page = 1, [FromQuery] int pageSize = 50)
|
2025-04-04 14:58:44 -03:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-04-06 01:35:31 -03:00
|
|
|
|
var result = await _customerService.GetAllAsync(page, pageSize);
|
2025-04-04 14:58:44 -03:00
|
|
|
|
return Ok(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-04-06 01:35:31 -03:00
|
|
|
|
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
|
|
|
|
return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
2025-04-04 14:58:44 -03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-04 21:44:20 -03:00
|
|
|
|
[HttpGet("search")]
|
2025-04-06 01:19:47 -03:00
|
|
|
|
public async Task<IActionResult> Search(
|
|
|
|
|
|
[FromQuery] string? name,
|
|
|
|
|
|
[FromQuery] string? email,
|
|
|
|
|
|
[FromQuery] string? document,
|
|
|
|
|
|
[FromQuery] int page = 1,
|
|
|
|
|
|
[FromQuery] int pageSize = 50)
|
2025-04-04 21:44:20 -03:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-04-06 01:19:47 -03:00
|
|
|
|
var result = await _customerService.SearchAsync(name, email, document, page, pageSize);
|
2025-04-04 21:44:20 -03:00
|
|
|
|
return Ok(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
|
|
|
|
return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-06 01:19:47 -03:00
|
|
|
|
//[HttpGet("search")]
|
|
|
|
|
|
//public async Task<IActionResult> Search([FromQuery] string? name, [FromQuery] string? email, [FromQuery] string? document)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// try
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var result = await _customerService.SearchAsync(name, email, document);
|
|
|
|
|
|
// return Ok(result);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
|
|
|
|
// return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2025-04-04 21:44:20 -03:00
|
|
|
|
|
2025-04-04 14:58:44 -03:00
|
|
|
|
}
|
|
|
|
|
|
}
|