62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using IdokladSdk.Models.ReceivedInvoice;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Idoklad.Services;
|
|
|
|
namespace Idoklad.Controllers;
|
|
|
|
/// <summary>
|
|
/// Received (incoming) invoices agenda. Requires iDoklad credentials (headers or environment
|
|
/// defaults).
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("received-invoices")]
|
|
[Produces("application/json")]
|
|
[Tags("ReceivedInvoices")]
|
|
public sealed class ReceivedInvoicesController : ControllerBase
|
|
{
|
|
private readonly ReceivedInvoicesService _service;
|
|
|
|
public ReceivedInvoicesController(ReceivedInvoicesService service) => _service = service;
|
|
|
|
/// <summary>
|
|
/// List received invoices (paged, optionally filtered and sorted).
|
|
/// </summary>
|
|
/// <param name="filter">Optional iDoklad-style filter (see IssuedInvoices for the syntax).</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>DateOfReceiving~desc</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 a received 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 received invoice.</summary>
|
|
[HttpGet("default")]
|
|
public async Task<IActionResult> Default(CancellationToken ct)
|
|
=> Ok(await _service.DefaultAsync(ct));
|
|
|
|
/// <summary>Create a new received invoice.</summary>
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create([FromBody] ReceivedInvoicePostModel model, CancellationToken ct)
|
|
=> Ok(await _service.CreateAsync(model, ct));
|
|
|
|
/// <summary>Update an existing received invoice (the model id identifies the invoice).</summary>
|
|
[HttpPatch]
|
|
public async Task<IActionResult> Update([FromBody] ReceivedInvoicePatchModel model, CancellationToken ct)
|
|
=> Ok(await _service.UpdateAsync(model, ct));
|
|
|
|
/// <summary>Delete a received invoice by id.</summary>
|
|
[HttpDelete("{id:int}")]
|
|
public async Task<IActionResult> Delete(int id, CancellationToken ct)
|
|
=> Ok(await _service.DeleteAsync(id, ct));
|
|
}
|