dc7e7a70fc
Introduced FlatPaymentController under Distribution.Features.Payment, providing GET and POST endpoints at /api/payments. Supports listing, retrieving, and creating payments with filtering and error handling. Business logic is delegated to PaymentService.
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Distribution.Features.Payment;
|
|
|
|
[ApiController]
|
|
[Route("api/payments")]
|
|
public class FlatPaymentController(PaymentService service) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAll(
|
|
[FromQuery] Guid? storeId,
|
|
[FromQuery] Guid? saleId,
|
|
[FromQuery] int page = 1,
|
|
[FromQuery] int pageSize = 20)
|
|
{
|
|
var result = await service.GetAllAsync(storeId, saleId, page, pageSize);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> GetById(Guid id)
|
|
{
|
|
var result = await service.GetByIdAsync(id);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create(CreateFlatPaymentRequest request, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var inner = new CreatePaymentRequest(request.Amount, request.Method);
|
|
var result = await service.CreateAsync(request.SaleId, inner, ct);
|
|
return result is null ? NotFound(new { error = "Sale not found or access denied" }) : Ok(result);
|
|
}
|
|
catch (InvalidOperationException ex) { return BadRequest(new { error = ex.Message }); }
|
|
}
|
|
}
|