Files
ERP_Distribution/Distribution/Features/Payment/PaymentController.cs
T
Kalana B. Thilakarathna 9adfff48a7 auth layer implemented
2026-10-09 09:37:05 +05:30

30 lines
946 B
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Distribution.Features.Payment;
[ApiController]
[Route("api/invoices/{invoiceId:guid}/payments")]
public class PaymentController(PaymentService service) : ControllerBase
{
[HttpGet]
[Authorize("invoice.view")]
public async Task<IActionResult> GetByInvoice(Guid invoiceId)
{
var result = await service.GetByInvoiceIdAsync(invoiceId);
return result is null ? NotFound() : Ok(result);
}
[HttpPost]
[Authorize("payment.manage")]
public async Task<IActionResult> Create(Guid invoiceId, CreatePaymentRequest request, CancellationToken ct)
{
try
{
var result = await service.CreateAsync(invoiceId, request, ct);
return result is null ? NotFound() : Ok(result);
}
catch (InvalidOperationException ex) { return BadRequest(new { error = ex.Message }); }
}
}