fix: formateo y eliminar estado invalido cancelled
This commit is contained in:
parent
c1c7d4bb37
commit
9e888ee985
|
|
@ -8,7 +8,7 @@ namespace DoliMiddlewareApi.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class ClientsController(ClientService clientService) : ControllerBase
|
public class ClientsController(ClientService clientService) : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -18,12 +18,12 @@ public class ClientsController(ClientService clientService) : ControllerBase
|
||||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<List<ClientDto>>> GetClientes(
|
public async Task<ActionResult<List<ClientDto>>> GetClientes(
|
||||||
[FromQuery] int limit = 50,
|
[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);
|
var clients = await clientService.GetClientsAsync(limit, page);
|
||||||
return Ok(clients);
|
return Ok(clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace DoliMiddlewareApi.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class InvoicesController(InvoiceService invoiceService) : ControllerBase
|
public class InvoicesController(InvoiceService invoiceService) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|
@ -18,9 +18,9 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase
|
||||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<List<InvoiceDto>>> GetInvoices(
|
public async Task<ActionResult<List<InvoiceDto>>> GetInvoices(
|
||||||
[FromQuery] int limit = 50,
|
[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] string? status = null,
|
||||||
[FromQuery] [StringLength(100)] string? search = null)
|
[FromQuery][StringLength(100)] string? search = null)
|
||||||
{
|
{
|
||||||
var invoices = await invoiceService.GetInvoicesAsync(limit, page, status, search);
|
var invoices = await invoiceService.GetInvoicesAsync(limit, page, status, search);
|
||||||
return Ok(invoices);
|
return Ok(invoices);
|
||||||
|
|
@ -43,7 +43,7 @@ public class InvoicesController(InvoiceService invoiceService) : ControllerBase
|
||||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)]
|
||||||
public async Task<ActionResult<int>> CreateInvoice([FromBody] CreateInvoiceDto createInvoiceDto)
|
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);
|
return CreatedAtAction(nameof(GetInvoice), new { id = invoiceId }, invoiceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,5 +13,5 @@ public class ClientResponse
|
||||||
// Contacto
|
// Contacto
|
||||||
public string? email { get; set; }
|
public string? email { get; set; }
|
||||||
public string? phone { get; set; }
|
public string? phone { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -3,5 +3,5 @@ namespace DoliMiddlewareApi.Dtos.Dolibarr;
|
||||||
public class InvoiceDetailResponse : InvoiceResponse
|
public class InvoiceDetailResponse : InvoiceResponse
|
||||||
{
|
{
|
||||||
public List<InvoiceLineResponse>? Lines { get; set; }
|
public List<InvoiceLineResponse>? Lines { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,20 +6,20 @@ public class CreateInvoiceDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime Date { get; set; }
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
public DateTime? ExpireDate { get; set; }
|
public DateTime? ExpireDate { get; set; }
|
||||||
|
|
||||||
[StringLength(100)]
|
[StringLength(100)]
|
||||||
public string? Reference { get; set; }
|
public string? Reference { get; set; }
|
||||||
|
|
||||||
public string? NotePublic { get; set; }
|
public string? NotePublic { get; set; }
|
||||||
public string? NotePrivate { get; set; }
|
public string? NotePrivate { get; set; }
|
||||||
|
|
||||||
public string Status { get; set; } = "draft";
|
public string Status { get; set; } = "draft";
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[MinLength(1)]
|
[MinLength(1)]
|
||||||
public List<CreateInvoiceLineDto> Lines { get; set; } = new();
|
public List<CreateInvoiceLineDto> Lines { get; set; } = new();
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,19 @@ namespace DoliMiddlewareApi.Dtos.command;
|
||||||
public class CreateInvoiceLineDto
|
public class CreateInvoiceLineDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(500)]
|
[StringLength(500)]
|
||||||
public string? Description { get; set; }
|
public string? Description { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Range(0.01, double.MaxValue)]
|
[Range(0.01, double.MaxValue)]
|
||||||
public decimal Quantity { get; set; }
|
public decimal Quantity { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[Range(0, double.MaxValue)]
|
[Range(0, double.MaxValue)]
|
||||||
public decimal UnitPrice { get; set; }
|
public decimal UnitPrice { get; set; }
|
||||||
|
|
||||||
[Range(0, 100)]
|
[Range(0, 100)]
|
||||||
public decimal TaxRate { get; set; } = 0;
|
public decimal TaxRate { get; set; } = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -6,11 +6,11 @@ public class CreateTokenDto
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(100)]
|
[StringLength(100)]
|
||||||
public string Username{get;set;}="";
|
public string Username { get; set; } = "";
|
||||||
[Required]
|
[Required]
|
||||||
[StringLength(255)]
|
[StringLength(255)]
|
||||||
public string Password{get;set;}="";
|
public string Password { get; set; } = "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +93,6 @@ public static class InvoiceMapper
|
||||||
"0" => "draft",
|
"0" => "draft",
|
||||||
"1" => "unpaid",
|
"1" => "unpaid",
|
||||||
"2" => "paid",
|
"2" => "paid",
|
||||||
"3" => "cancelled",
|
|
||||||
_ => "unknown"
|
_ => "unknown"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -105,8 +104,7 @@ public static class InvoiceMapper
|
||||||
"draft" => "0",
|
"draft" => "0",
|
||||||
"unpaid" => "1",
|
"unpaid" => "1",
|
||||||
"paid" => "2",
|
"paid" => "2",
|
||||||
"cancelled" => "3",
|
_ => throw new BadRequestException($"Estado inválido: {status}. Valores válidos: draft, unpaid, paid")
|
||||||
_ => throw new BadRequestException($"Estado inválido: {status}. Valores válidos: draft, unpaid, paid, cancelled")
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,10 +65,10 @@ public class DolibarrApiClient(HttpClient httpClient, DolibarrTokenCacheService
|
||||||
request.Headers.Add("DOLAPIKEY", dolibarrToken);
|
request.Headers.Add("DOLAPIKEY", dolibarrToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async Task EnsureSuccessOrThrowAsync(HttpResponseMessage response, string endpoint)
|
private async Task EnsureSuccessOrThrowAsync(HttpResponseMessage response, string endpoint)
|
||||||
{
|
{
|
||||||
if (response.IsSuccessStatusCode) return;
|
if (response.IsSuccessStatusCode) return;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class InvoiceService(IDolibarrApiClient apiClient)
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(search))
|
if (!string.IsNullOrWhiteSpace(search))
|
||||||
{
|
{
|
||||||
search=search.Trim().ToUpperInvariant();
|
search = search.Trim().ToUpperInvariant();
|
||||||
var filter = $"(t.ref:like:'%{search}%')";
|
var filter = $"(t.ref:like:'%{search}%')";
|
||||||
endpoint += $"&sqlfilters={Uri.EscapeDataString(filter)}";
|
endpoint += $"&sqlfilters={Uri.EscapeDataString(filter)}";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue