All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 16m35s
69 lines
2.3 KiB
C#
69 lines
2.3 KiB
C#
using Core.Interfaces;
|
|
using Domain.Entities;
|
|
using Domain.Generics;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers.Stock
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class LSProductController : ControllerBase
|
|
{
|
|
private readonly ILSProductDom _service;
|
|
|
|
public LSProductController(ILSProductDom service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
[HttpPost("search")]
|
|
public async Task<ActionResult<PagedResult<ELSProduct>>> Search([FromBody] LSProductSearchParams searchParams)
|
|
{
|
|
var result = await _service.SearchAsync(searchParams);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<ELSProduct>> GetById(int id)
|
|
{
|
|
var product = await _service.GetByIdAsync(id);
|
|
if (product == null)
|
|
return NotFound($"No se encontró el producto con ID {id}.");
|
|
return Ok(product);
|
|
}
|
|
|
|
[HttpPost("create")]
|
|
public async Task<ActionResult<ELSProduct>> Create([FromBody] ELSProduct model)
|
|
{
|
|
var created = await _service.CreateAsync(model);
|
|
return CreatedAtAction(nameof(GetById), new { id = created.Id }, created);
|
|
}
|
|
|
|
[HttpPut("update")]
|
|
public async Task<IActionResult> Update([FromBody] ELSProduct model)
|
|
{
|
|
var success = await _service.UpdateAsync(model);
|
|
if (!success)
|
|
return NotFound("No se pudo actualizar el producto.");
|
|
return Ok();
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task<IActionResult> Delete(int id)
|
|
{
|
|
var success = await _service.DeleteAsync(id);
|
|
if (!success)
|
|
return NotFound("No se pudo eliminar el producto.");
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost("exportfiltered")]
|
|
public async Task<IActionResult> ExportFiltered([FromBody] LSProductSearchParams searchParams)
|
|
{
|
|
var content = await _service.ExportToExcelAsync(searchParams);
|
|
var fileName = $"productos_{DateTime.Now:yyyyMMddHHmm}.xlsx";
|
|
return File(content, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
|
|
}
|
|
}
|
|
}
|