30 lines
946 B
C#
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 }); }
|
|
}
|
|
}
|