All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (pull_request) Successful in 18m57s
- Se agregan DeliveryNoteDto y DeliveryNoteItemDto - Se implementa proyección a DTO en PhSDeliveryNoteRepository - Se extiende IPhSDeliveryNoteRepository con métodos DTO - Se ajusta DeliveryNoteService para trabajar con DTO - Se actualiza DeliveryNoteController para devolver DTO - Se elimina exposición directa de EDeliveryNote en la API Closes #23
70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using Domain.Dtos.Sales;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Reflection;
|
|
|
|
namespace phronCare.API.Controllers.Sales
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class DeliveryNoteController : ControllerBase
|
|
{
|
|
private readonly IDeliveryNoteDom _deliveryNoteService;
|
|
|
|
public DeliveryNoteController(IDeliveryNoteDom deliveryNoteService)
|
|
{
|
|
_deliveryNoteService = deliveryNoteService ?? throw new ArgumentNullException(nameof(deliveryNoteService));
|
|
}
|
|
|
|
[HttpGet("{id:int}")]
|
|
public async Task<ActionResult<DeliveryNoteDto>> GetById(int id)
|
|
{
|
|
try
|
|
{
|
|
var deliveryNote = await _deliveryNoteService.GetDtoByIdAsync(id);
|
|
if (deliveryNote == null)
|
|
return NotFound($"Remito con ID {id} no encontrado.");
|
|
|
|
return Ok(deliveryNote);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
[HttpGet("number/{deliveryNoteNumber}")]
|
|
public async Task<ActionResult<DeliveryNoteDto>> GetByDeliveryNoteNumber(string deliveryNoteNumber)
|
|
{
|
|
try
|
|
{
|
|
var deliveryNote = await _deliveryNoteService.GetDtoByDeliveryNoteNumberAsync(deliveryNoteNumber);
|
|
if (deliveryNote == null)
|
|
return NotFound($"Remito con número {deliveryNoteNumber} no encontrado.");
|
|
|
|
return Ok(deliveryNote);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
[HttpGet("by-quote/{quoteId:int}")]
|
|
public async Task<ActionResult<IEnumerable<DeliveryNoteDto>>> GetByQuoteId(int quoteId)
|
|
{
|
|
try
|
|
{
|
|
var deliveryNotes = await _deliveryNoteService.GetDtosByQuoteIdAsync(quoteId);
|
|
return Ok(deliveryNotes);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var methodName = MethodBase.GetCurrentMethod()?.Name ?? "UnknownMethod";
|
|
return StatusCode(500, $"{methodName} Message: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|