phronCare/phronCare.API/Controllers/Sales/CustomerController.cs
Leandro Hernan Rojas 3962d889fd
All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 5m23s
Add Pagination in API Customer
2025-04-06 01:19:47 -03:00

66 lines
2.1 KiB
C#

using Core.Interfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Reflection;
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));
}
[HttpGet("all")]
public async Task<IActionResult> GetAll()
{
try
{
var result = await _customerService.GetAllAsync();
return Ok(result);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
[HttpGet("search")]
public async Task<IActionResult> Search(
[FromQuery] string? name,
[FromQuery] string? email,
[FromQuery] string? document,
[FromQuery] int page = 1,
[FromQuery] int pageSize = 50)
{
try
{
var result = await _customerService.SearchAsync(name, email, document, page, pageSize);
return Ok(result);
}
catch (Exception ex)
{
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
return StatusCode(500, $"{methodName} Message: {ex.Message}");
}
}
//[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}");
// }
//}
}
}