fix: formateo y eliminar estado invalido cancelled

This commit is contained in:
javiermengual 2026-02-03 17:19:53 +01:00
parent c1c7d4bb37
commit 9e888ee985
10 changed files with 37 additions and 39 deletions

View File

@ -8,7 +8,7 @@ namespace DoliMiddlewareApi.Controllers;
[ApiController]
[Route("api/[controller]")]
[Authorize]
[Authorize]
public class ClientsController(ClientService clientService) : ControllerBase
{
@ -18,12 +18,12 @@ public class ClientsController(ClientService clientService) : ControllerBase
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<List<ClientDto>>> GetClientes(
[FromQuery] int limit = 50,
[FromQuery] [Range(1, int.MaxValue)] int page = 1)
[FromQuery][Range(1, int.MaxValue)] int page = 1)
{
var clients = await clientService.GetClientsAsync(limit, page);
return Ok(clients);
}
}

View File

@ -9,7 +9,7 @@ namespace DoliMiddlewareApi.Controllers;
[ApiController]
[Route("api/[controller]")]
[Authorize]
[Authorize]
public class InvoicesController(InvoiceService invoiceService) : ControllerBase
{
[HttpGet]
@ -18,9 +18,9 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<List<InvoiceDto>>> GetInvoices(
[FromQuery] int limit = 50,
[FromQuery] [Range(1, int.MaxValue)] int page = 1,
[FromQuery][Range(1, int.MaxValue)] int page = 1,
[FromQuery] string? status = null,
[FromQuery] [StringLength(100)] string? search = null)
[FromQuery][StringLength(100)] string? search = null)
{
var invoices = await invoiceService.GetInvoicesAsync(limit, page, status, search);
return Ok(invoices);
@ -43,7 +43,7 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<int>> CreateInvoice([FromBody] CreateInvoiceDto createInvoiceDto)
{
var invoiceId= await invoiceService.CreateInvoiceAsync(createInvoiceDto);
var invoiceId = await invoiceService.CreateInvoiceAsync(createInvoiceDto);
return CreatedAtAction(nameof(GetInvoice), new { id = invoiceId }, invoiceId);
}

View File

@ -13,5 +13,5 @@ public class ClientResponse
// Contacto
public string? email { get; set; }
public string? phone { get; set; }
}

View File

@ -3,5 +3,5 @@ namespace DoliMiddlewareApi.Dtos.Dolibarr;
public class InvoiceDetailResponse : InvoiceResponse
{
public List<InvoiceLineResponse>? Lines { get; set; }
}

View File

@ -6,20 +6,20 @@ public class CreateInvoiceDto
{
[Required]
public int ClientId { get; set; }
[Required]
public DateTime Date { get; set; }
public DateTime? ExpireDate { get; set; }
[StringLength(100)]
public string? Reference { get; set; }
public string? NotePublic { get; set; }
public string? NotePrivate { get; set; }
public string Status { get; set; } = "draft";
[Required]
[MinLength(1)]
public List<CreateInvoiceLineDto> Lines { get; set; } = new();

View File

@ -5,19 +5,19 @@ namespace DoliMiddlewareApi.Dtos.command;
public class CreateInvoiceLineDto
{
[Required]
[StringLength(500)]
[StringLength(500)]
public string? Description { get; set; }
[Required]
[Range(0.01, double.MaxValue)]
[Range(0.01, double.MaxValue)]
public decimal Quantity { get; set; }
[Required]
[Range(0, double.MaxValue)]
[Range(0, double.MaxValue)]
public decimal UnitPrice { get; set; }
[Range(0, 100)]
[Range(0, 100)]
public decimal TaxRate { get; set; } = 0;
}

View File

@ -6,11 +6,11 @@ public class CreateTokenDto
{
[Required]
[StringLength(100)]
public string Username{get;set;}="";
public string Username { get; set; } = "";
[Required]
[StringLength(255)]
public string Password{get;set;}="";
public string Password { get; set; } = "";
}

View File

@ -93,7 +93,6 @@ public static class InvoiceMapper
"0" => "draft",
"1" => "unpaid",
"2" => "paid",
"3" => "cancelled",
_ => "unknown"
};
}
@ -105,8 +104,7 @@ public static class InvoiceMapper
"draft" => "0",
"unpaid" => "1",
"paid" => "2",
"cancelled" => "3",
_ => throw new BadRequestException($"Estado inválido: {status}. Valores válidos: draft, unpaid, paid, cancelled")
_ => throw new BadRequestException($"Estado inválido: {status}. Valores válidos: draft, unpaid, paid")
};
}
}

View File

@ -65,10 +65,10 @@ public class DolibarrApiClient(HttpClient httpClient, DolibarrTokenCacheService
request.Headers.Add("DOLAPIKEY", dolibarrToken);
}
}
private async Task EnsureSuccessOrThrowAsync(HttpResponseMessage response, string endpoint)
{
if (response.IsSuccessStatusCode) return;

View File

@ -33,7 +33,7 @@ public class InvoiceService(IDolibarrApiClient apiClient)
if (!string.IsNullOrWhiteSpace(search))
{
search=search.Trim().ToUpperInvariant();
search = search.Trim().ToUpperInvariant();
var filter = $"(t.ref:like:'%{search}%')";
endpoint += $"&sqlfilters={Uri.EscapeDataString(filter)}";
}