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.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Distribution.Features.Sale;
|
|
|
|
[ApiController]
|
|
[Route("api/sales")]
|
|
public class SaleController(SaleService service) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAll(
|
|
[FromQuery] Guid? rideId,
|
|
[FromQuery] int page = 1,
|
|
[FromQuery] int pageSize = 20) =>
|
|
Ok(await service.GetAllAsync(rideId, page, pageSize));
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> GetById(Guid id)
|
|
{
|
|
var result = await service.GetByIdAsync(id);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpGet("store/{storeId:guid}")]
|
|
public async Task<IActionResult> GetByStore(Guid storeId)
|
|
{
|
|
var result = await service.GetByStoreIdAsync(storeId);
|
|
return result is null ? Forbid() : Ok(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create(CreateSaleRequest request, CancellationToken ct)
|
|
{
|
|
var result = await service.CreateAsync(request, ct);
|
|
return result is null ? Forbid() : CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
|
|
}
|
|
|
|
[HttpPatch("{id:guid}/cancel")]
|
|
public async Task<IActionResult> Cancel(Guid id, CancellationToken ct)
|
|
{
|
|
try
|
|
{
|
|
var result = await service.CancelAsync(id, ct);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
catch (InvalidOperationException ex) { return Conflict(new { error = ex.Message }); }
|
|
}
|
|
}
|