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