using IdokladSdk.Models.IssuedInvoice; using Microsoft.AspNetCore.Mvc; using Idoklad.Services; namespace Idoklad.Controllers; /// /// Issued (outgoing) invoices agenda. Requires iDoklad credentials (headers or environment /// defaults). /// [ApiController] [Route("issued-invoices")] [Produces("application/json")] [Tags("IssuedInvoices")] public sealed class IssuedInvoicesController : ControllerBase { private readonly IssuedInvoicesService _service; public IssuedInvoicesController(IssuedInvoicesService service) => _service = service; /// /// List issued invoices (paged, optionally filtered and sorted). /// /// /// Optional iDoklad-style filter, e.g. (DateOfTaxing~gte~2024-01-01),(IsPaid~eq~false). /// Operators: eq, neq, gt, gte, lt, lte, ct (contains), nct (not contains). /// /// How multiple conditions combine: and (default) or or. /// Optional sort, e.g. DateOfIssue~desc,Id~asc. [HttpGet] public async Task List( [FromQuery] int page = 1, [FromQuery] int pageSize = 20, [FromQuery] string? filter = null, [FromQuery] string? filtertype = null, [FromQuery] string? sort = null, CancellationToken ct = default) => Ok(await _service.ListAsync(page, pageSize, filter, filtertype, sort, ct)); /// Get an issued invoice detail by id. [HttpGet("{id:int}")] public async Task Detail(int id, CancellationToken ct) => Ok(await _service.DetailAsync(id, ct)); /// Get a pre-filled default model for creating a new issued invoice. [HttpGet("default")] public async Task Default(CancellationToken ct) => Ok(await _service.DefaultAsync(ct)); /// Create a new issued invoice. [HttpPost] public async Task Create([FromBody] IssuedInvoicePostModel model, CancellationToken ct) => Ok(await _service.CreateAsync(model, ct)); /// Update an existing issued invoice (the model id identifies the invoice). [HttpPatch] public async Task Update([FromBody] IssuedInvoicePatchModel model, CancellationToken ct) => Ok(await _service.UpdateAsync(model, ct)); /// Create a copy (draft) of an existing issued invoice. [HttpPost("{id:int}/copy")] public async Task Copy(int id, CancellationToken ct) => Ok(await _service.CopyAsync(id, ct)); /// Delete an issued invoice by id. [HttpDelete("{id:int}")] public async Task Delete(int id, CancellationToken ct) => Ok(await _service.DeleteAsync(id, ct)); }