From daded5658286453c2c72528893484a5307531257 Mon Sep 17 00:00:00 2001 From: javiermengual Date: Fri, 2 Jan 2026 18:15:41 +0100 Subject: [PATCH] feat: Creo los DTOS para el POST de facturas , tambien organizo un poco en command y query los DTOS --- .../Controllers/InvoicesController.cs | 4 ++- .../Dtos/command/CreateInvoiceDto.cs | 25 +++++++++++++++++++ .../Dtos/command/CreateInvoiceLineDto.cs | 23 +++++++++++++++++ .../Dtos/{ => query}/InvoiceDetailDto.cs | 0 .../Dtos/{ => query}/InvoiceDto.cs | 0 .../Dtos/{ => query}/InvoiceLineDto.cs | 0 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs create mode 100644 DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs rename DoliMiddlewareApi/Dtos/{ => query}/InvoiceDetailDto.cs (100%) rename DoliMiddlewareApi/Dtos/{ => query}/InvoiceDto.cs (100%) rename DoliMiddlewareApi/Dtos/{ => query}/InvoiceLineDto.cs (100%) diff --git a/DoliMiddlewareApi/Controllers/InvoicesController.cs b/DoliMiddlewareApi/Controllers/InvoicesController.cs index 4d6e3d6..b99cc86 100644 --- a/DoliMiddlewareApi/Controllers/InvoicesController.cs +++ b/DoliMiddlewareApi/Controllers/InvoicesController.cs @@ -18,6 +18,7 @@ public class InvoicesController : ControllerBase [HttpGet] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task>> GetInvoices( [FromQuery] int limit = 50, @@ -30,9 +31,10 @@ public class InvoicesController : ControllerBase [HttpGet("{id:int}")] [ProducesResponseType(typeof(InvoiceDetailDto), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] - public async Task> GetInvoice(int id) + public async Task> GetInvoice([Range(1, int.MaxValue)] int id) { var invoice = await _invoiceService.GetInvoiceAsync(id); return Ok(invoice); diff --git a/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs b/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs new file mode 100644 index 0000000..e534444 --- /dev/null +++ b/DoliMiddlewareApi/Dtos/command/CreateInvoiceDto.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; + +namespace DoliMiddlewareApi.Dtos.command; + +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; } + + [Required] + [MinLength(1)] + public List Lines { get; set; } = new(); +} + diff --git a/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs b/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs new file mode 100644 index 0000000..c9f6849 --- /dev/null +++ b/DoliMiddlewareApi/Dtos/command/CreateInvoiceLineDto.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; + +namespace DoliMiddlewareApi.Dtos.command; + +public class CreateInvoiceLineDto +{ + [Required] + [StringLength(500)] + public string? Description { get; set; } + + [Required] + [Range(0.01, double.MaxValue)] + public decimal Quantity { get; set; } + + [Required] + [Range(0, double.MaxValue)] + public decimal UnitPrice { get; set; } + + [Range(0, 100)] + public decimal TaxRate { get; set; } = 0; + + +} \ No newline at end of file diff --git a/DoliMiddlewareApi/Dtos/InvoiceDetailDto.cs b/DoliMiddlewareApi/Dtos/query/InvoiceDetailDto.cs similarity index 100% rename from DoliMiddlewareApi/Dtos/InvoiceDetailDto.cs rename to DoliMiddlewareApi/Dtos/query/InvoiceDetailDto.cs diff --git a/DoliMiddlewareApi/Dtos/InvoiceDto.cs b/DoliMiddlewareApi/Dtos/query/InvoiceDto.cs similarity index 100% rename from DoliMiddlewareApi/Dtos/InvoiceDto.cs rename to DoliMiddlewareApi/Dtos/query/InvoiceDto.cs diff --git a/DoliMiddlewareApi/Dtos/InvoiceLineDto.cs b/DoliMiddlewareApi/Dtos/query/InvoiceLineDto.cs similarity index 100% rename from DoliMiddlewareApi/Dtos/InvoiceLineDto.cs rename to DoliMiddlewareApi/Dtos/query/InvoiceLineDto.cs