using Microsoft.AspNetCore.Mvc; namespace Distribution.Features.Sale; [ApiController] [Route("api/sales")] public class SaleController(SaleService service) : ControllerBase { [HttpGet] public async Task 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 GetById(Guid id) { var result = await service.GetByIdAsync(id); return result is null ? NotFound() : Ok(result); } [HttpGet("store/{storeId:guid}")] public async Task GetByStore(Guid storeId) { var result = await service.GetByStoreIdAsync(storeId); return result is null ? Forbid() : Ok(result); } [HttpPost] public async Task 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); } }