diff --git a/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs b/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs index b9e9fe0..649ef2b 100644 --- a/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs +++ b/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs @@ -6,7 +6,7 @@ public class CreateSupplierDto public string? Email { get; set; } public string? Phone { get; set; } public string? Address { get; set; } - public int ZipCode { get; set; } + public string? ZipCode { get; set; } public string? City { get; set; } public int DeliveryDelay { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs b/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs index b69b72b..0deefef 100644 --- a/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs +++ b/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs @@ -7,7 +7,7 @@ public class UpdateSupplierDto public string? Email { get; set; } public string? Phone { get; set; } public string? Address { get; set; } - public int ZipCode { get; set; } + public string? ZipCode { get; set; } public string? City { get; set; } public int DeliveryDelay { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..879b7b6 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs @@ -0,0 +1,20 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("api/deliveryNotes"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync(ct), ct); + } + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..98eb447 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs @@ -0,0 +1,35 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.DeliveryNotes; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class GetDeliveryNoteRequest +{ + public int DeliveryNoteId { get; set; } +} +public class GetDeliveryNoteEndpoint( + DeliveryNotesRepository deliveryNotesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct) + { + DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct); + + if (deliveryNote == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await Send.OkAsync(mapper.Map(deliveryNote), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs new file mode 100644 index 0000000..d47d639 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs @@ -0,0 +1,39 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Request; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Deliverers; +using PyroFetes.Specifications.DeliveryNotes; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class PatchRealDeliveryDateEndpoint( + DeliveryNotesRepository deliveryNotesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/deliveryNote/{@id}", x=> new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct) + { + DeliveryNote? deliveryNoteToPath = + await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id),ct); + + if (deliveryNoteToPath == null) + { + await Send.NotFoundAsync(ct); + return; + } + + deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate; + + await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct); + + await Send.OkAsync(mapper.Map(deliveryNoteToPath), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Models/Supplier.cs b/PyroFetes/Models/Supplier.cs index f131804..4e02663 100644 --- a/PyroFetes/Models/Supplier.cs +++ b/PyroFetes/Models/Supplier.cs @@ -9,7 +9,7 @@ public class Supplier [Required, MaxLength(100)] public string? Email { get; set; } [Required, MaxLength(30)] public string? Phone { get; set; } [Required, MaxLength(100)] public string? Address { get; set; } - [Required] public int ZipCode { get; set; } + [Required,MaxLength(5),MinLength(5)] public string? ZipCode { get; set; } [Required, MaxLength(100)] public string? City { get; set; } [Required] public int DeliveryDelay { get; set; } diff --git a/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs b/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs new file mode 100644 index 0000000..2fc0494 --- /dev/null +++ b/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.DeliveryNotes; + +public sealed class GetDeliveryNoteByIdSpec : Specification +{ + public GetDeliveryNoteByIdSpec(int deliveryNoteId) + { + Query + .Where(x => x.Id == deliveryNoteId); + } +} \ No newline at end of file