using Microsoft.AspNetCore.Mvc; namespace Distribution.Features.Payment; [ApiController] [Route("api/invoices/{invoiceId:guid}/payments")] public class PaymentController(PaymentService service) : ControllerBase { [HttpGet] public async Task GetByInvoice(Guid invoiceId) { var result = await service.GetByInvoiceIdAsync(invoiceId); return result is null ? NotFound() : Ok(result); } [HttpPost] public async Task 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 }); } } }