diff --git a/DoliMiddlewareApi/Controllers/ClientsController.cs b/DoliMiddlewareApi/Controllers/ClientsController.cs index 9cf2987..4f276a7 100644 --- a/DoliMiddlewareApi/Controllers/ClientsController.cs +++ b/DoliMiddlewareApi/Controllers/ClientsController.cs @@ -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>> 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); } - - - + + + } diff --git a/DoliMiddlewareApi/Controllers/InvoicesController.cs b/DoliMiddlewareApi/Controllers/InvoicesController.cs index 162f147..8ad227f 100644 --- a/DoliMiddlewareApi/Controllers/InvoicesController.cs +++ b/DoliMiddlewareApi/Controllers/InvoicesController.cs @@ -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>> 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> CreateInvoice([FromBody] CreateInvoiceDto createInvoiceDto) { - var invoiceId= await invoiceService.CreateInvoiceAsync(createInvoiceDto); + var invoiceId = await invoiceService.CreateInvoiceAsync(createInvoiceDto); return CreatedAtAction(nameof(GetInvoice), new { id = invoiceId }, invoiceId); } diff --git a/DoliMiddlewareApi/Dtos/Dolibarr/ClientResponse.cs b/DoliMiddlewareApi/Dtos/Dolibarr/ClientResponse.cs index 2eba2e9..940e497 100644 --- a/DoliMiddlewareApi/Dtos/Dolibarr/ClientResponse.cs +++ b/DoliMiddlewareApi/Dtos/Dolibarr/ClientResponse.cs @@ -13,5 +13,5 @@ public class ClientResponse // Contacto public string? email { get; set; } public string? phone { get; set; } - + } \ No newline at end of file diff --git a/DoliMiddlewareApi/Dtos/Dolibarr/InvoiceDetailResponse.cs b/DoliMiddlewareApi/Dtos/Dolibarr/InvoiceDetailResponse.cs index 0d4eb6b..3c2f9d1 100644 --- a/DoliMiddlewareApi/Dtos/Dolibarr/InvoiceDetailResponse.cs +++ b/DoliMiddlewareApi/Dtos/Dolibarr/InvoiceDetailResponse.cs @@ -3,5 +3,5 @@ namespace DoliMiddlewareApi.Dtos.Dolibarr; public class InvoiceDetailResponse : InvoiceResponse { public List? Lines { get; set; } - + } \ No newline at end of file diff --git a/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs b/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs index 186ad7b..0d7fefa 100644 --- a/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs +++ b/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs @@ -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 Lines { get; set; } = new(); diff --git a/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs b/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs index c9f6849..38080b0 100644 --- a/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs +++ b/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs @@ -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; - - + + } \ No newline at end of file diff --git a/DoliMiddlewareApi/Dtos/command/CreateTokenDto.cs b/DoliMiddlewareApi/Dtos/command/CreateTokenDto.cs index a915c62..d975f76 100644 --- a/DoliMiddlewareApi/Dtos/command/CreateTokenDto.cs +++ b/DoliMiddlewareApi/Dtos/command/CreateTokenDto.cs @@ -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; } = ""; + + + } \ No newline at end of file diff --git a/DoliMiddlewareApi/Mappers/InvoiceMapper.cs b/DoliMiddlewareApi/Mappers/InvoiceMapper.cs index 848a7c7..a6df167 100644 --- a/DoliMiddlewareApi/Mappers/InvoiceMapper.cs +++ b/DoliMiddlewareApi/Mappers/InvoiceMapper.cs @@ -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") }; } } \ No newline at end of file diff --git a/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs b/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs index c0c8ed7..c19c3ba 100644 --- a/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs +++ b/DoliMiddlewareApi/Services/Clients/DolibarrApiClient.cs @@ -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; diff --git a/DoliMiddlewareApi/Services/InvoiceService.cs b/DoliMiddlewareApi/Services/InvoiceService.cs index 79a4211..c7fcac3 100644 --- a/DoliMiddlewareApi/Services/InvoiceService.cs +++ b/DoliMiddlewareApi/Services/InvoiceService.cs @@ -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)}"; }