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). [HttpGet] public async Task List([FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListAsync(page, pageSize, 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)); }