2025-12-30 11:20:54 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2025-12-30 12:19:02 +00:00
|
|
|
using DoliMiddlewareApi.Dtos;
|
2025-12-29 15:37:46 +00:00
|
|
|
using DoliMiddlewareApi.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace DoliMiddlewareApi.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class InvoicesController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly DolibarrApiClient _dolibarrClient;
|
|
|
|
|
|
|
|
|
|
public InvoicesController(DolibarrApiClient dolibarrClient)
|
|
|
|
|
{
|
|
|
|
|
_dolibarrClient = dolibarrClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2025-12-30 12:45:58 +00:00
|
|
|
[ProducesResponseType(typeof(List<InvoiceDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
2025-12-30 12:19:02 +00:00
|
|
|
public async Task<ActionResult<List<InvoiceDto>>> GetInvoices(
|
2025-12-29 15:58:53 +00:00
|
|
|
[FromQuery] int limit = 50,
|
2025-12-30 11:20:54 +00:00
|
|
|
[FromQuery] [Range(1, int.MaxValue)] int page = 1,
|
2025-12-29 15:58:53 +00:00
|
|
|
[FromQuery] string? status = null)
|
2025-12-29 15:37:46 +00:00
|
|
|
{
|
2025-12-29 15:58:53 +00:00
|
|
|
var invoices = await _dolibarrClient.GetInvoicesAsync(limit, page, status);
|
2025-12-29 15:37:46 +00:00
|
|
|
return Ok(invoices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id:int}")]
|
2025-12-30 12:45:58 +00:00
|
|
|
[ProducesResponseType(typeof(InvoiceDetailDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
|
|
|
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
2025-12-30 12:19:02 +00:00
|
|
|
public async Task<ActionResult<InvoiceDetailDto>> GetInvoice(int id)
|
2025-12-29 15:37:46 +00:00
|
|
|
{
|
|
|
|
|
var invoice = await _dolibarrClient.GetInvoiceAsync(id);
|
|
|
|
|
return Ok(invoice);
|
|
|
|
|
}
|
2025-12-29 15:58:53 +00:00
|
|
|
}
|