Compare commits
61 Commits
1c898f9144
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a42e1010f | |||
| 2fa74ccba8 | |||
| 65cff130e4 | |||
| e21e2afea4 | |||
| 17978e7c19 | |||
| 6a20676b32 | |||
| e440dcd2b5 | |||
| bee1cfb0e3 | |||
| d709654410 | |||
| 4a82c51133 | |||
| 8a04adeec3 | |||
| db9219e80f | |||
| 9e6834754f | |||
| efa7a0be6f | |||
| 2a439ccbb5 | |||
| 5c6798a647 | |||
|
|
50a5f371dd | ||
| 86c5d6ae7b | |||
| 1c0432a2c4 | |||
| 3e8f36457e | |||
| 5d68ee6992 | |||
|
|
d26284d552 | ||
|
|
d537051bea | ||
|
|
3ad506f869 | ||
|
|
9aac7c39f2 | ||
|
|
b76b668097 | ||
|
|
669938d677 | ||
|
|
165c9b9322 | ||
|
|
0b72549143 | ||
|
|
d64890dec9 | ||
|
|
8325aa0768 | ||
|
|
ee9b4675dd | ||
|
|
f6383265ba | ||
|
|
7bf0b5bfd1 | ||
|
|
bd653c149c | ||
| 0511bb5075 | |||
| 27e8fea7f3 | |||
| 6dba61f742 | |||
|
|
20bbccf883 | ||
|
|
d7cf245d35 | ||
|
|
2385b7b687 | ||
|
|
ae834d1e3c | ||
|
|
c6d4ef2c58 | ||
|
|
60a7c059b4 | ||
|
|
9684dbcbc7 | ||
| bbd8d3d36a | |||
| 7d92f80de3 | |||
| 304c06ed19 | |||
| 97a7c6811c | |||
| f8b3c51435 | |||
| a535f8cfeb | |||
| 65b5e6afe3 | |||
| 33719b708e | |||
| b00ed36557 | |||
| be0a6a4004 | |||
|
|
6bc8281a37 | ||
|
|
9ff5c038b1 | ||
|
|
4bdd8104d8 | ||
|
|
abc843778f | ||
|
|
c0090da9bd | ||
|
|
554ba9b725 |
@@ -5,7 +5,8 @@ public class CreateDeliveryNoteDto
|
|||||||
public string? TrackingNumber { get; set; }
|
public string? TrackingNumber { get; set; }
|
||||||
public DateOnly EstimateDeliveryDate { get; set; }
|
public DateOnly EstimateDeliveryDate { get; set; }
|
||||||
public DateOnly ExpeditionDate { get; set; }
|
public DateOnly ExpeditionDate { get; set; }
|
||||||
public DateOnly RealDeliveryDate { get; set; }
|
|
||||||
|
|
||||||
public int DelivererId { get; set; }
|
public int DelivererId { get; set; }
|
||||||
|
|
||||||
|
public Dictionary<int,int>? ProductQuantities { get; set; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
|
||||||
|
public class GetDeliveryNotePdfDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
@@ -4,21 +4,21 @@ public class CreatePriceDto
|
|||||||
{
|
{
|
||||||
public decimal SellingPrice { get; set; }
|
public decimal SellingPrice { get; set; }
|
||||||
|
|
||||||
public int SupplierId { get; set; }
|
public int? SupplierId { get; set; }
|
||||||
public string? SupplierName { get; set; }
|
public string? SupplierName { get; set; }
|
||||||
public string? SupplierEmail { get; set; }
|
public string? SupplierEmail { get; set; }
|
||||||
public string? SupplierPhone { get; set; }
|
public string? SupplierPhone { get; set; }
|
||||||
public string? SupplierAddress { get; set; }
|
public string? SupplierAddress { get; set; }
|
||||||
public int SupplierZipCode { get; set; }
|
public string? SupplierZipCode { get; set; }
|
||||||
public string? SupplierCity { get; set; }
|
public string? SupplierCity { get; set; }
|
||||||
public int SupplierDeliveryDelay { get; set; }
|
public int SupplierDeliveryDelay { get; set; }
|
||||||
|
|
||||||
public int ProductId { get; set; }
|
public int? ProductId { get; set; }
|
||||||
public int ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public decimal ProductCaliber { get; set; }
|
public int ProductCaliber { get; set; }
|
||||||
public int ProductApprovalNumber { get; set; }
|
public string? ProductApprovalNumber { get; set; }
|
||||||
public decimal ProductWeight { get; set; }
|
public decimal ProductWeight { get; set; }
|
||||||
public decimal ProductNec { get; set; }
|
public decimal ProductNec { get; set; }
|
||||||
public string? ProductImage { get; set; }
|
public string? ProductImage { get; set; }
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
public class PatchPriceSellingPriceDto
|
public class PatchPriceSellingPriceDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int ProductId { get; set; }
|
||||||
|
public int SupplierId { get; set; }
|
||||||
public decimal SellingPrice { get; set; }
|
public decimal SellingPrice { get; set; }
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ public class UpdatePriceDto
|
|||||||
public int SupplierDeliveryDelay { get; set; }
|
public int SupplierDeliveryDelay { get; set; }
|
||||||
|
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
public int ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public decimal ProductCaliber { get; set; }
|
public decimal ProductCaliber { get; set; }
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ public class GetPriceDto
|
|||||||
public string? SupplierEmail { get; set; }
|
public string? SupplierEmail { get; set; }
|
||||||
public string? SupplierPhone { get; set; }
|
public string? SupplierPhone { get; set; }
|
||||||
public string? SupplierAddress { get; set; }
|
public string? SupplierAddress { get; set; }
|
||||||
public int SupplierZipCode { get; set; }
|
public string? SupplierZipCode { get; set; }
|
||||||
public string? SupplierCity { get; set; }
|
public string? SupplierCity { get; set; }
|
||||||
public int SupplierDeliveryDelay { get; set; }
|
public int SupplierDeliveryDelay { get; set; }
|
||||||
|
|
||||||
public int ProductId { get; set; }
|
public int ProductId { get; set; }
|
||||||
public int ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public decimal ProductCaliber { get; set; }
|
public int ProductCaliber { get; set; }
|
||||||
public int ProductApprovalNumber { get; set; }
|
public string? ProductApprovalNumber { get; set; }
|
||||||
public decimal ProductWeight { get; set; }
|
public decimal ProductWeight { get; set; }
|
||||||
public decimal ProductNec { get; set; }
|
public decimal ProductNec { get; set; }
|
||||||
public string? ProductImage { get; set; }
|
public string? ProductImage { get; set; }
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ namespace PyroFetes.DTO.Product.Request;
|
|||||||
|
|
||||||
public class CreateProductDto
|
public class CreateProductDto
|
||||||
{
|
{
|
||||||
public int References { get; set; }
|
public string? References { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public decimal Duration {get; set;}
|
public decimal Duration {get; set;}
|
||||||
public decimal Caliber { get; set; }
|
public int Caliber { get; set; }
|
||||||
public int ApprovalNumber { get; set; }
|
public string? ApprovalNumber { get; set; }
|
||||||
public decimal Weight { get; set; }
|
public decimal Weight { get; set; }
|
||||||
public decimal Nec { get; set; }
|
public decimal Nec { get; set; }
|
||||||
public string? Image { get; set; }
|
public string? Image { get; set; }
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ namespace PyroFetes.DTO.Product.Request;
|
|||||||
public class UpdateProductDto
|
public class UpdateProductDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int References { get; set; }
|
public string? References { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public decimal Duration {get; set;}
|
public decimal Duration {get; set;}
|
||||||
public decimal Caliber { get; set; }
|
public int Caliber { get; set; }
|
||||||
public int ApprovalNumber { get; set; }
|
public string? ApprovalNumber { get; set; }
|
||||||
public decimal Weight { get; set; }
|
public decimal Weight { get; set; }
|
||||||
public decimal Nec { get; set; }
|
public decimal Nec { get; set; }
|
||||||
public string? Image { get; set; }
|
public string? Image { get; set; }
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ namespace PyroFetes.DTO.Product.Response;
|
|||||||
public class GetProductDto
|
public class GetProductDto
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int References { get; set; }
|
public string? References { get; set; }
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public decimal Duration {get; set;}
|
public decimal Duration {get; set;}
|
||||||
public decimal Caliber { get; set; }
|
public int Caliber { get; set; }
|
||||||
public int ApprovalNumber { get; set; }
|
public string? ApprovalNumber { get; set; }
|
||||||
public decimal Weight { get; set; }
|
public decimal Weight { get; set; }
|
||||||
public decimal Nec { get; set; }
|
public decimal Nec { get; set; }
|
||||||
public string? Image { get; set; }
|
public string? Image { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
|
||||||
|
public class GetPurchaseOrderPdfDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Quotation/Request/GetQuotationPdfDto.cs
Normal file
6
PyroFetes/DTO/Quotation/Request/GetQuotationPdfDto.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Quotation.Request;
|
||||||
|
|
||||||
|
public class GetQuotationPdfDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
8
PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs
Normal file
8
PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PyroFetes.DTO.Quotation.Request;
|
||||||
|
|
||||||
|
public class UpdateQuotationDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Message { get; set; }
|
||||||
|
public string? ConditionsSale { get; set; }
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ public class CreateSupplierDto
|
|||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Phone { get; set; }
|
public string? Phone { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
public int ZipCode { get; set; }
|
public string? ZipCode { get; set; }
|
||||||
public string? City { get; set; }
|
public string? City { get; set; }
|
||||||
public int DeliveryDelay { get; set; }
|
public int DeliveryDelay { get; set; }
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ public class UpdateSupplierDto
|
|||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Phone { get; set; }
|
public string? Phone { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
public int ZipCode { get; set; }
|
public string? ZipCode { get; set; }
|
||||||
public string? City { get; set; }
|
public string? City { get; set; }
|
||||||
public int DeliveryDelay { get; set; }
|
public int DeliveryDelay { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using PyroFetes.DTO.Price.Response;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Supplier.Response;
|
namespace PyroFetes.DTO.Supplier.Response;
|
||||||
|
|
||||||
public class GetSupplierDto
|
public class GetSupplierDto
|
||||||
@@ -7,7 +10,9 @@ public class GetSupplierDto
|
|||||||
public string? Email { get; set; }
|
public string? Email { get; set; }
|
||||||
public string? Phone { get; set; }
|
public string? Phone { get; set; }
|
||||||
public string? Address { get; set; }
|
public string? Address { get; set; }
|
||||||
public int ZipCode { get; set; }
|
public string? ZipCode { get; set; }
|
||||||
public string? City { get; set; }
|
public string? City { get; set; }
|
||||||
public int DeliveryDelay { get; set; }
|
public int DeliveryDelay { get; set; }
|
||||||
|
public List<GetProductDto>? Products { get; set; }
|
||||||
|
public List<GetPriceDto>? Prices { get; set; }
|
||||||
}
|
}
|
||||||
30
PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Deliverer.Request;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
public class CreateDelivererEndpoint(
|
||||||
|
DeliverersRepository deliverersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/deliverers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer newDeliverer = new Deliverer()
|
||||||
|
{
|
||||||
|
Transporter = req.Transporter,
|
||||||
|
};
|
||||||
|
|
||||||
|
await deliverersRepository.AddAsync(newDeliverer, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Deliverers/DeleteDelivererEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Deliverers/DeleteDelivererEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
public class DeleteDelivererRequest
|
||||||
|
{
|
||||||
|
public int DelivererId { get; set; }
|
||||||
|
}
|
||||||
|
public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/deliverers/{@id}", x=>new {x.DelivererId});
|
||||||
|
AllowAnonymous();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteDelivererRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
|
||||||
|
|
||||||
|
if (deliverer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await deliverersRepository.DeleteAsync(deliverer, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
PyroFetes/Endpoints/Deliverers/GetAllDelivererEndpoint.cs
Normal file
23
PyroFetes/Endpoints/Deliverers/GetAllDelivererEndpoint.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using AutoMapper.QueryableExtensions;
|
||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository) : EndpointWithoutRequest<List<GetDelivererDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/deliverers");
|
||||||
|
AllowAnonymous();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
PyroFetes/Endpoints/Deliverers/GetDelivererEndpoint.cs
Normal file
39
PyroFetes/Endpoints/Deliverers/GetDelivererEndpoint.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
public class GetDelivererRequest
|
||||||
|
{
|
||||||
|
public int DelivererId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetDelivererEndpoint(
|
||||||
|
DeliverersRepository deliverersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/deliverers/{@id}", x=>new {x.DelivererId});
|
||||||
|
AllowAnonymous();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetDelivererRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
|
||||||
|
|
||||||
|
if (deliverer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
PyroFetes/Endpoints/Deliverers/UpdateDelivererEndpoint.cs
Normal file
39
PyroFetes/Endpoints/Deliverers/UpdateDelivererEndpoint.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Deliverer.Request;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
public class UpdateDelivererEndpoint(
|
||||||
|
DeliverersRepository deliverersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/deliverers/{@id}", x=>new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateDelivererDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (deliverer == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deliverer.Transporter = req.Transporter;
|
||||||
|
|
||||||
|
await deliverersRepository.UpdateAsync(deliverer,ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class CreateDeliveryNoteEndpoint(
|
||||||
|
DeliveryNotesRepository deliveryNotesRepository,
|
||||||
|
DeliverersRepository deliverersRepository,
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
ProductDeliveriesRepository productDeliveriesRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateDeliveryNoteDto, GetDeliveryNoteDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/deliveryNotes");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
|
||||||
|
|
||||||
|
if (deliverer == null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("No deliverer found", 404, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Creating the Delivery Note
|
||||||
|
DeliveryNote newDeliveryNote = new DeliveryNote()
|
||||||
|
{
|
||||||
|
TrackingNumber = req.TrackingNumber,
|
||||||
|
EstimateDeliveryDate = req.EstimateDeliveryDate,
|
||||||
|
ExpeditionDate = req.ExpeditionDate,
|
||||||
|
DelivererId = req.DelivererId,
|
||||||
|
Deliverer = deliverer,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
await deliveryNotesRepository.AddAsync(newDeliveryNote, ct);
|
||||||
|
|
||||||
|
foreach (var productQuantity in req.ProductQuantities!)
|
||||||
|
{
|
||||||
|
Product? product =
|
||||||
|
await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
ProductDelivery productDelivery = new ProductDelivery()
|
||||||
|
{
|
||||||
|
DeliveryNote = newDeliveryNote,
|
||||||
|
Quantity = productQuantity.Value,
|
||||||
|
Product = product,
|
||||||
|
DeliveryNoteId = newDeliveryNote.Id
|
||||||
|
};
|
||||||
|
|
||||||
|
await productDeliveriesRepository.AddAsync(productDelivery, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(newDeliveryNote), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.Endpoints.Quotations;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.DeliveryNotes;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class DeleteDeliveryNoteRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteDeliveryNoteEndpoint(
|
||||||
|
DeliveryNotesRepository deliveryNotesRepository) : Endpoint<DeleteDeliveryNoteRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/deliveryNotes/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (deliveryNote == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await deliveryNotesRepository.DeleteAsync(deliveryNote, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest<List<GetDeliveryNoteDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/deliveryNotes");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync<GetDeliveryNoteDto>(ct), ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs
Normal file
35
PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs
Normal file
@@ -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<GetDeliveryNoteRequest, GetDeliveryNoteDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/deliveryNotes/{@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<GetDeliveryNoteDto>(deliveryNote), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Net.Mime;
|
||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Services.Pdf;
|
||||||
|
using PyroFetes.Specifications.DeliveryNotes;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class GetDeliveryNotePdfEndpoint(
|
||||||
|
DeliveryNotesRepository deliveryNotesRepository,
|
||||||
|
IDeliveryNotePdfService deliveryNotePdfService)
|
||||||
|
: Endpoint<GetDeliveryNotePdfDto, byte[]>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/deliveryNotes/{@Id}/pdf", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
DeliveryNote? deliveryNote = await deliveryNotesRepository
|
||||||
|
.FirstOrDefaultAsync(new GetDeliveryNoteByIdWithProductsSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (deliveryNote == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!);
|
||||||
|
|
||||||
|
await Send.BytesAsync(
|
||||||
|
bytes: bytes,
|
||||||
|
contentType: "application/pdf",
|
||||||
|
fileName: $"bon-de-livraison-{deliveryNote.Id}.pdf",
|
||||||
|
cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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<PatchDeliveryNoteRealDeliveryDateDto, GetDeliveryNoteDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/deliveryNotes/{@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deliveryNoteToPath.RealDeliveryDate != null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Impossible de modifier la date.", 400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate;
|
||||||
|
|
||||||
|
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNoteToPath), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.DeliveryNotes;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||||
|
|
||||||
|
public class UpdateDeliveryNoteEndpoint(
|
||||||
|
DeliveryNotesRepository deliveryNotesRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateDeliveryNoteDto, GetDeliveryNoteDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/deliveryNotes/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateDeliveryNoteDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (deliveryNote == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deliveryNote.TrackingNumber = req.TrackingNumber;
|
||||||
|
deliveryNote.EstimateDeliveryDate = req.EstimateDeliveryDate;
|
||||||
|
deliveryNote.ExpeditionDate = req.ExpeditionDate;
|
||||||
|
deliveryNote.RealDeliveryDate = req.RealDeliveryDate;
|
||||||
|
deliveryNote.DelivererId = req.DelivererId;
|
||||||
|
|
||||||
|
await deliveryNotesRepository.UpdateAsync(deliveryNote, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNote), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
84
PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs
Normal file
84
PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Price.Request;
|
||||||
|
using PyroFetes.DTO.Price.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Prices;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
using PyroFetes.Specifications.Suppliers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Prices;
|
||||||
|
|
||||||
|
public class CreatePriceEndpoint(
|
||||||
|
SuppliersRepository suppliersRepository,
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
PricesRepository pricesRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreatePriceDto, GetPriceDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/prices");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
// Gestion du fournisseur
|
||||||
|
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct);
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
supplier = new Supplier()
|
||||||
|
{
|
||||||
|
Name = req.SupplierName,
|
||||||
|
Email = req.SupplierEmail,
|
||||||
|
Phone = req.SupplierPhone,
|
||||||
|
Address = req.SupplierAddress,
|
||||||
|
City = req.SupplierCity,
|
||||||
|
ZipCode = req.SupplierZipCode,
|
||||||
|
DeliveryDelay = req.SupplierDeliveryDelay
|
||||||
|
};
|
||||||
|
await suppliersRepository.AddAsync(supplier, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestion du produit
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
product = new Product()
|
||||||
|
{
|
||||||
|
Reference = req.ProductReferences,
|
||||||
|
Name = req.ProductName,
|
||||||
|
Duration = req.ProductDuration,
|
||||||
|
Caliber = req.ProductCaliber,
|
||||||
|
ApprovalNumber = req.ProductApprovalNumber,
|
||||||
|
Weight = req.ProductWeight,
|
||||||
|
Nec = req.ProductNec,
|
||||||
|
Image = req.ProductImage,
|
||||||
|
Link = req.ProductLink,
|
||||||
|
MinimalQuantity = req.ProductMinimalQuantity
|
||||||
|
};
|
||||||
|
await productsRepository.AddAsync(product, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifie si le prix existe déjà pour ce fournisseur et produit
|
||||||
|
Price? existingPrice = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct);
|
||||||
|
|
||||||
|
if (existingPrice != null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Le fournisseur a déjà un prix pour ce produit.", 400, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création du prix
|
||||||
|
var priceAdded = new Price()
|
||||||
|
{
|
||||||
|
SellingPrice = req.SellingPrice,
|
||||||
|
SupplierId = supplier.Id,
|
||||||
|
ProductId = product.Id
|
||||||
|
};
|
||||||
|
await pricesRepository.AddAsync(priceAdded, ct);
|
||||||
|
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPriceDto>(priceAdded), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Prices;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Prices;
|
||||||
|
|
||||||
|
public class DeletePriceRequest
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
public int SupplierId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId,req.SupplierId), ct);
|
||||||
|
|
||||||
|
if (price == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await pricesRepository.DeleteAsync(price, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Price.Request;
|
||||||
|
using PyroFetes.DTO.Price.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Prices;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Prices;
|
||||||
|
|
||||||
|
public class PatchPriceEndpoint(
|
||||||
|
PricesRepository pricesRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct);
|
||||||
|
|
||||||
|
if (price == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
price.SellingPrice = req.SellingPrice;
|
||||||
|
|
||||||
|
await pricesRepository.UpdateAsync(price, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPriceDto>(price), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
PyroFetes/Endpoints/Products/DeleteProductEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Products/DeleteProductEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.Endpoints.Deliverers;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Deliverers;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class DeleteProductsRequest
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
}
|
||||||
|
public class DeleteProductEndpoint(ProductsRepository productsRepository) : Endpoint<DeleteProductsRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/products/{@id}", x=>new {x.ProductId});
|
||||||
|
AllowAnonymous();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteProductsRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await productsRepository.DeleteAsync(product, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs
Normal file
21
PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/products");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
PyroFetes/Endpoints/Products/GetProductEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Products/GetProductEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class GetProductRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetProductEndpoint(
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetProductRequest, GetProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/products/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class PatchProductMinimalStockEndpoint(
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto, GetProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
product.MinimalQuantity = req.MinimalQuantity;
|
||||||
|
await productsRepository.UpdateAsync(product, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs
Normal file
46
PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Products;
|
||||||
|
|
||||||
|
public class UpdateProductEndpoint(
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto, GetProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/products/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
product.Reference = req.References;
|
||||||
|
product.Name = req.Name;
|
||||||
|
product.Duration = req.Duration;
|
||||||
|
product.Caliber = req.Caliber;
|
||||||
|
product.ApprovalNumber = req.ApprovalNumber;
|
||||||
|
product.Weight = req.Weight;
|
||||||
|
product.Nec = req.Nec;
|
||||||
|
product.Image = req.Image;
|
||||||
|
product.Link = req.Link;
|
||||||
|
product.MinimalQuantity = req.MinimalQuantity;
|
||||||
|
|
||||||
|
await productsRepository.UpdateAsync(product, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
|
||||||
|
|
||||||
public class DeletePurchaseOrderRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseOrder = await database.PurchaseOrders
|
|
||||||
.Include(po => po.PurchaseProducts)
|
|
||||||
.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (purchaseOrder == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
|
||||||
{
|
|
||||||
database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.PurchaseOrders.Remove(purchaseOrder);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
|
||||||
|
|
||||||
public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/purchaseOrders");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseOrder = await database.PurchaseOrders
|
|
||||||
.Include(p => p.PurchaseProducts)
|
|
||||||
.Select(purchaseOrder => new GetPurchaseOrderDto()
|
|
||||||
{
|
|
||||||
Id = purchaseOrder.Id,
|
|
||||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
|
||||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
|
||||||
.Select(p => new GetPurchaseProductDto
|
|
||||||
{
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
ProductReferences = p.Product.Reference,
|
|
||||||
ProductName = p.Product.Name,
|
|
||||||
ProductDuration = p.Product.Duration,
|
|
||||||
ProductCaliber = p.Product.Caliber,
|
|
||||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
|
||||||
ProductWeight = p.Product.Weight,
|
|
||||||
ProductNec = p.Product.Nec,
|
|
||||||
ProductImage = p.Product.Image,
|
|
||||||
ProductLink = p.Product.Link,
|
|
||||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
|
||||||
PurchaseOrderId = p.PurchaseOrderId,
|
|
||||||
Quantity = p.Quantity,
|
|
||||||
}).ToList()
|
|
||||||
})
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(purchaseOrder, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
|
||||||
|
|
||||||
public class GetPurchaseOrderRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseOrder = await database.PurchaseOrders
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (purchaseOrder == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetPurchaseOrderDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = purchaseOrder.Id,
|
|
||||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
|
||||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
|
||||||
.Select(p => new GetPurchaseProductDto
|
|
||||||
{
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
ProductReferences = p.Product.Reference,
|
|
||||||
ProductName = p.Product.Name,
|
|
||||||
ProductDuration = p.Product.Duration,
|
|
||||||
ProductCaliber = p.Product.Caliber,
|
|
||||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
|
||||||
ProductWeight = p.Product.Weight,
|
|
||||||
ProductNec = p.Product.Nec,
|
|
||||||
ProductImage = p.Product.Image,
|
|
||||||
ProductLink = p.Product.Link,
|
|
||||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
|
||||||
PurchaseOrderId = p.PurchaseOrderId,
|
|
||||||
Quantity = p.Quantity,
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseOrder;
|
|
||||||
|
|
||||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
|
||||||
if (purchaseOrder == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetPurchaseOrderDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = purchaseOrder.Id,
|
|
||||||
PurchaseConditions = purchaseOrder.PurchaseConditions,
|
|
||||||
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
|
|
||||||
.Select(p => new GetPurchaseProductDto
|
|
||||||
{
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
ProductReferences = p.Product.Reference,
|
|
||||||
ProductName = p.Product.Name,
|
|
||||||
ProductDuration = p.Product.Duration,
|
|
||||||
ProductCaliber = p.Product.Caliber,
|
|
||||||
ProductApprovalNumber = p.Product.ApprovalNumber,
|
|
||||||
ProductWeight = p.Product.Weight,
|
|
||||||
ProductNec = p.Product.Nec,
|
|
||||||
ProductImage = p.Product.Image,
|
|
||||||
ProductLink = p.Product.Link,
|
|
||||||
ProductMinimalQuantity = p.Product.MinimalQuantity,
|
|
||||||
PurchaseOrderId = p.PurchaseOrderId,
|
|
||||||
Quantity = p.Quantity,
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||||
|
|
||||||
|
public class DeletePurchaseOrderRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeletePurchaseOrderEndpoint(
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseOrderRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (purchaseOrder == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||||
|
{
|
||||||
|
await purchaseProductsRepository.DeleteRangeAsync(purchaseOrder.PurchaseProducts, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||||
|
|
||||||
|
public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/purchaseOrders");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync<GetPurchaseOrderDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||||
|
|
||||||
|
public class GetPurchaseOrderRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetPurchaseOrderEndpoint(
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (purchaseOrder == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
using System.Net.Mime;
|
||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Services.Pdf;
|
||||||
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||||
|
|
||||||
|
public class GetPurchaseOrderPdfEndpoint(
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
IPurchaseOrderPdfService purchaseOrderPdfService)
|
||||||
|
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/purchaseOrders/{@Id}/pdf", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository
|
||||||
|
.FirstOrDefaultAsync(new GetPurchaseOrderByIdWithProductsSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (purchaseOrder == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!);
|
||||||
|
|
||||||
|
await Send.BytesAsync(
|
||||||
|
bytes: bytes,
|
||||||
|
contentType: "application/pdf",
|
||||||
|
fileName: $"bon-de-commande-{purchaseOrder.Id}.pdf",
|
||||||
|
cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||||
|
|
||||||
|
public class PatchPurchaseOrderPurchaseConditionsEndpoint(
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||||
|
if (purchaseOrder == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
||||||
|
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
|
||||||
|
|
||||||
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/purchaseProducts");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
|
||||||
if (product == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct);
|
|
||||||
|
|
||||||
if (purchaseOrder == null)
|
|
||||||
{
|
|
||||||
purchaseOrder = new Models.PurchaseOrder()
|
|
||||||
{
|
|
||||||
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
|
|
||||||
};
|
|
||||||
database.PurchaseOrders.Add(purchaseOrder);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
var purchaseProduct = new Models.PurchaseProduct()
|
|
||||||
{
|
|
||||||
ProductId = product.Id,
|
|
||||||
PurchaseOrderId = purchaseOrder.Id,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
database.PurchaseProducts.Add(purchaseProduct);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
var responseDto = new GetPurchaseProductDto()
|
|
||||||
{
|
|
||||||
ProductId = product.Id,
|
|
||||||
ProductReferences = product.Reference,
|
|
||||||
ProductName = product.Name,
|
|
||||||
ProductDuration = product.Duration,
|
|
||||||
ProductCaliber = product.Caliber,
|
|
||||||
ProductApprovalNumber = product.ApprovalNumber,
|
|
||||||
ProductWeight = product.Weight,
|
|
||||||
ProductNec = product.Nec,
|
|
||||||
ProductImage = product.Image,
|
|
||||||
ProductLink = product.Link,
|
|
||||||
ProductMinimalQuantity = product.MinimalQuantity,
|
|
||||||
|
|
||||||
PurchaseOrderId = purchaseOrder.Id,
|
|
||||||
PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions,
|
|
||||||
Quantity = purchaseProduct.Quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
|
||||||
|
|
||||||
public class DeletePurchaseProductRequest
|
|
||||||
{
|
|
||||||
public int ProductId { get; set; }
|
|
||||||
public int PurchaseOrderId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseProductRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseProduct = await database.PurchaseProducts
|
|
||||||
.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
|
||||||
|
|
||||||
if (purchaseProduct == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
database.PurchaseProducts.Remove(purchaseProduct);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.PurchaseProduct;
|
|
||||||
|
|
||||||
public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
|
||||||
if (purchaseProduct == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
purchaseProduct.Quantity = req.Quantity;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetPurchaseProductDto responseDto = new()
|
|
||||||
{
|
|
||||||
ProductId = purchaseProduct.ProductId,
|
|
||||||
PurchaseOrderId = purchaseProduct.PurchaseOrderId,
|
|
||||||
Quantity = purchaseProduct.Quantity
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
using PyroFetes.Specifications.PurchaseOrders;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||||
|
|
||||||
|
public class CreatePurchaseProductEndpoint(
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
PurchaseProductsRepository purchaseProductsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/purchaseProducts");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PurchaseOrder? purchaseOrder =
|
||||||
|
await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
|
||||||
|
|
||||||
|
if (purchaseOrder == null)
|
||||||
|
{
|
||||||
|
purchaseOrder = new PurchaseOrder()
|
||||||
|
{
|
||||||
|
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
|
||||||
|
};
|
||||||
|
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
PurchaseProduct purchaseProduct = new PurchaseProduct()
|
||||||
|
{
|
||||||
|
ProductId = product.Id,
|
||||||
|
PurchaseOrderId = purchaseOrder.Id,
|
||||||
|
Quantity = req.Quantity
|
||||||
|
};
|
||||||
|
|
||||||
|
await purchaseProductsRepository.AddAsync(purchaseProduct, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.PurchaseProducts;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||||
|
|
||||||
|
public class DeletePurchaseProductRequest
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
public int PurchaseOrderId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseProduct? purchaseProduct = await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||||
|
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||||
|
|
||||||
|
if (purchaseProduct == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.PurchaseProducts;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||||
|
|
||||||
|
public class PatchPurchaseProductQuantityEndpoint(
|
||||||
|
PurchaseProductsRepository purchaseProductsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
PurchaseProduct? purchaseProduct =
|
||||||
|
await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||||
|
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||||
|
|
||||||
|
if (purchaseProduct == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
purchaseProduct.Quantity = req.Quantity;
|
||||||
|
await purchaseProductsRepository.UpdateAsync(purchaseProduct, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Quotation;
|
|
||||||
|
|
||||||
public class DeleteQuotationRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/quotations/{@Id}", x => new {x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotation = await database.Quotations
|
|
||||||
.Include(q => q.QuotationProducts)
|
|
||||||
.SingleOrDefaultAsync(q => q.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (quotation == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
|
|
||||||
{
|
|
||||||
database.QuotationProducts.RemoveRange(quotation.QuotationProducts);
|
|
||||||
}
|
|
||||||
|
|
||||||
database.Quotations.Remove(quotation);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.Quotation.Response;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Quotation;
|
|
||||||
|
|
||||||
public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetQuotationDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/quotations");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotations = await database.Quotations
|
|
||||||
.Include(q => q.QuotationProducts!)
|
|
||||||
.ThenInclude(qp => qp.Product)
|
|
||||||
.Select(q => new GetQuotationDto
|
|
||||||
{
|
|
||||||
Id = q.Id,
|
|
||||||
Message = q.Message,
|
|
||||||
ConditionsSale = q.ConditionsSale,
|
|
||||||
GetQuotationProductDto = q.QuotationProducts.Select(qp => new GetQuotationProductDto
|
|
||||||
{
|
|
||||||
Quantity = qp.Quantity,
|
|
||||||
QuotationId = q.Id,
|
|
||||||
QuotationMessage = q.Message,
|
|
||||||
QuotationConditionsSale = q.ConditionsSale,
|
|
||||||
ProductId = qp.ProductId,
|
|
||||||
ProductReferences = qp.Product.Reference,
|
|
||||||
ProductName = qp.Product.Name,
|
|
||||||
ProductDuration = qp.Product.Duration,
|
|
||||||
ProductCaliber = qp.Product.Caliber,
|
|
||||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
|
||||||
ProductWeight = qp.Product.Weight,
|
|
||||||
ProductNec = qp.Product.Nec,
|
|
||||||
ProductImage = qp.Product.Image,
|
|
||||||
ProductLink = qp.Product.Link,
|
|
||||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
|
||||||
}).ToList()
|
|
||||||
})
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(quotations, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.Quotation.Response;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Quotation;
|
|
||||||
|
|
||||||
public class GetQuotationRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/quotations/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotation = await database.Quotations
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (quotation == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetQuotationDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = quotation.Id,
|
|
||||||
Message = quotation.Message,
|
|
||||||
ConditionsSale = quotation.ConditionsSale,
|
|
||||||
GetQuotationProductDto = quotation.QuotationProducts
|
|
||||||
.Select(qp => new GetQuotationProductDto
|
|
||||||
{
|
|
||||||
Quantity = qp.Quantity,
|
|
||||||
QuotationId = quotation.Id,
|
|
||||||
QuotationMessage = quotation.Message,
|
|
||||||
QuotationConditionsSale = quotation.ConditionsSale,
|
|
||||||
ProductId = qp.ProductId,
|
|
||||||
ProductReferences = qp.Product.Reference,
|
|
||||||
ProductName = qp.Product.Name,
|
|
||||||
ProductDuration = qp.Product.Duration,
|
|
||||||
ProductCaliber = qp.Product.Caliber,
|
|
||||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
|
||||||
ProductWeight = qp.Product.Weight,
|
|
||||||
ProductNec = qp.Product.Nec,
|
|
||||||
ProductImage = qp.Product.Image,
|
|
||||||
ProductLink = qp.Product.Link,
|
|
||||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
|
||||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
|
||||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
|
||||||
using PyroFetes.DTO.Quotation.Request;
|
|
||||||
using PyroFetes.DTO.Quotation.Response;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Quotation;
|
|
||||||
|
|
||||||
public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
if (quotation == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
quotation.ConditionsSale = req.ConditionsSale;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetQuotationDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = quotation.Id,
|
|
||||||
Message = quotation.Message,
|
|
||||||
ConditionsSale = quotation.ConditionsSale,
|
|
||||||
GetQuotationProductDto = quotation.QuotationProducts.Select(qp => new GetQuotationProductDto
|
|
||||||
{
|
|
||||||
Quantity = qp.Quantity,
|
|
||||||
QuotationId = quotation.Id,
|
|
||||||
QuotationMessage = quotation.Message,
|
|
||||||
QuotationConditionsSale = quotation.ConditionsSale,
|
|
||||||
ProductId = qp.ProductId,
|
|
||||||
ProductReferences = qp.Product.Reference,
|
|
||||||
ProductName = qp.Product.Name,
|
|
||||||
ProductDuration = qp.Product.Duration,
|
|
||||||
ProductCaliber = qp.Product.Caliber,
|
|
||||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
|
||||||
ProductWeight = qp.Product.Weight,
|
|
||||||
ProductNec = qp.Product.Nec,
|
|
||||||
ProductImage = qp.Product.Image,
|
|
||||||
ProductLink = qp.Product.Link,
|
|
||||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Request;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
|
||||||
|
|
||||||
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/quotationProduct");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
|
||||||
if (product == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
|
|
||||||
|
|
||||||
if (quotation == null)
|
|
||||||
{
|
|
||||||
quotation = new Models.Quotation()
|
|
||||||
{
|
|
||||||
Message = req.QuotationMessage ?? "",
|
|
||||||
ConditionsSale = req.QuotationConditionsSale,
|
|
||||||
};
|
|
||||||
database.Quotations.Add(quotation);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
var quotationProduct = new Models.QuotationProduct()
|
|
||||||
{
|
|
||||||
ProductId = product.Id,
|
|
||||||
QuotationId = quotation.Id,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
database.QuotationProducts.Add(quotationProduct);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
var responseDto = new GetQuotationProductDto()
|
|
||||||
{
|
|
||||||
ProductId = product.Id,
|
|
||||||
ProductReferences = product.Reference,
|
|
||||||
ProductName = product.Name,
|
|
||||||
ProductDuration = product.Duration,
|
|
||||||
ProductCaliber = product.Caliber,
|
|
||||||
ProductApprovalNumber = product.ApprovalNumber,
|
|
||||||
ProductWeight = product.Weight,
|
|
||||||
ProductNec = product.Nec,
|
|
||||||
ProductImage = product.Image,
|
|
||||||
ProductLink = product.Link,
|
|
||||||
ProductMinimalQuantity = product.MinimalQuantity,
|
|
||||||
Quantity = quotationProduct.Quantity,
|
|
||||||
QuotationMessage = quotation.Message,
|
|
||||||
QuotationConditionsSale = quotation.ConditionsSale,
|
|
||||||
QuotationId = quotation.Id,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
|
||||||
|
|
||||||
public class DeleteQuotationProductRequest
|
|
||||||
{
|
|
||||||
public int ProductId { get; set; }
|
|
||||||
public int QuotationId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotationProduct = await database.QuotationProducts
|
|
||||||
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
|
||||||
|
|
||||||
if (quotationProduct == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
database.QuotationProducts.Remove(quotationProduct);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Request;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
|
||||||
|
|
||||||
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
|
||||||
if (quotationProduct == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
quotationProduct.Quantity = req.Quantity;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetQuotationProductDto responseDto = new()
|
|
||||||
{
|
|
||||||
ProductId = quotationProduct.ProductId,
|
|
||||||
QuotationId = quotationProduct.QuotationId,
|
|
||||||
Quantity = quotationProduct.Quantity
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Request;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Products;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||||
|
|
||||||
|
public class CreateQuotationProductEndpoint(
|
||||||
|
QuotationProductsRepository quotationProductsRepository,
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
QuotationsRepository quotationsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/quotationProducts");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||||
|
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
quotation = new Quotation()
|
||||||
|
{
|
||||||
|
Message = req.QuotationMessage ?? "",
|
||||||
|
ConditionsSale = req.QuotationConditionsSale,
|
||||||
|
};
|
||||||
|
|
||||||
|
await quotationsRepository.AddAsync(quotation, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
QuotationProduct quotationProduct = new QuotationProduct()
|
||||||
|
{
|
||||||
|
ProductId = product.Id,
|
||||||
|
QuotationId = quotation.Id,
|
||||||
|
Quantity = req.Quantity
|
||||||
|
};
|
||||||
|
|
||||||
|
await quotationProductsRepository.AddAsync(quotationProduct, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.QuotationProducts;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||||
|
|
||||||
|
public class DeleteQuotationProductRequest
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
public int QuotationId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
QuotationProduct? quotationProduct =
|
||||||
|
await quotationProductsRepository.FirstOrDefaultAsync(
|
||||||
|
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||||
|
|
||||||
|
if (quotationProduct == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Request;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.QuotationProducts;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||||
|
|
||||||
|
public class PatchQuotationProductQuantityEndpoint(
|
||||||
|
QuotationProductsRepository quotationProductsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
QuotationProduct? quotationProduct =
|
||||||
|
await quotationProductsRepository.FirstOrDefaultAsync(
|
||||||
|
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||||
|
if (quotationProduct == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
quotationProduct.Quantity = req.Quantity;
|
||||||
|
await quotationProductsRepository.UpdateAsync(quotationProduct, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs
Normal file
43
PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class DeleteQuotationRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteQuotationEndpoint(
|
||||||
|
QuotationsRepository quotationsRepository,
|
||||||
|
QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/quotations/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
|
||||||
|
{
|
||||||
|
await quotationProductsRepository.DeleteRangeAsync(quotation.QuotationProducts, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
await quotationsRepository.DeleteAsync(quotation, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs
Normal file
22
PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository) : EndpointWithoutRequest<List<GetQuotationDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/quotations");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
38
PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class GetQuotationRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetQuotationEndpoint(
|
||||||
|
QuotationsRepository quotationsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/quotations/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
PyroFetes/Endpoints/Quotations/GetQuotationPdfEndpoint.cs
Normal file
42
PyroFetes/Endpoints/Quotations/GetQuotationPdfEndpoint.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Net.Mime;
|
||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Services.Pdf;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class GetQuotationPdfEndpoint(
|
||||||
|
QuotationsRepository quotationRepository,
|
||||||
|
IQuotationPdfService quotationPdfService)
|
||||||
|
: Endpoint<GetQuotationPdfDto, byte[]>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/quotations/{@Id}/pdf", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Quotation? quotation = await quotationRepository
|
||||||
|
.FirstOrDefaultAsync(new GetQuotationByIdWithProductsSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!);
|
||||||
|
|
||||||
|
await Send.BytesAsync(
|
||||||
|
bytes: bytes,
|
||||||
|
contentType: "application/pdf",
|
||||||
|
fileName: $"devis-{quotation.Id}.pdf",
|
||||||
|
cancellation: ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class PatchQuotationConditionsSaleEndpoint(
|
||||||
|
QuotationsRepository quotationsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/quotations/{@Id}/saleConditions", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
quotation.ConditionsSale = req.ConditionsSale;
|
||||||
|
await quotationsRepository.UpdateAsync(quotation, ct);
|
||||||
|
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Quotations;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Quotations;
|
||||||
|
|
||||||
|
public class UpdateQuotationEndpoint(
|
||||||
|
QuotationsRepository quotationsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateQuotationDto, GetQuotationDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/quotations/{@Id}", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateQuotationDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (quotation == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
quotation.ConditionsSale = req.ConditionsSale;
|
||||||
|
quotation.Message = req.Message;
|
||||||
|
await quotationsRepository.UpdateAsync(quotation, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
using PyroFetes.DTO.SettingDTO.Request;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
namespace PyroFetes.Endpoints.Setting;
|
|
||||||
|
|
||||||
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/setting");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var setting = new Models.Setting()
|
|
||||||
{
|
|
||||||
ElectronicSignature = req.ElectronicSignature,
|
|
||||||
Logo = req.Logo
|
|
||||||
};
|
|
||||||
|
|
||||||
database.Settings.Add(setting);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetSettingDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = setting.Id,
|
|
||||||
ElectronicSignature = setting.ElectronicSignature,
|
|
||||||
Logo = setting.Logo
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Setting;
|
|
||||||
|
|
||||||
public class DeleteSettingRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/setting/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (setting == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
database.Settings.Remove(setting);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Setting;
|
|
||||||
|
|
||||||
public class GetSettingRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSettingRequest, GetSettingDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/setting/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var setting = await database.Settings
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (setting == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetSettingDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = setting.Id,
|
|
||||||
ElectronicSignature = setting.ElectronicSignature,
|
|
||||||
Logo = setting.Logo
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Request;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Setting;
|
|
||||||
|
|
||||||
public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (setting == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setting.ElectronicSignature = req.ElectronicSignature;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetSettingDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = setting.Id,
|
|
||||||
ElectronicSignature = setting.ElectronicSignature,
|
|
||||||
Logo = setting.Logo
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Request;
|
|
||||||
using PyroFetes.DTO.SettingDTO.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Setting;
|
|
||||||
|
|
||||||
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/setting/{@Id}/Logo", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (setting == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setting.Logo = req.Logo;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetSettingDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = setting.Id,
|
|
||||||
ElectronicSignature = setting.ElectronicSignature,
|
|
||||||
Logo = setting.Logo
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
31
PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs
Normal file
31
PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
|
public class CreateSettingEndpoint(
|
||||||
|
SettingsRepository settingsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/settings");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Setting setting = new Setting()
|
||||||
|
{
|
||||||
|
ElectronicSignature = req.ElectronicSignature,
|
||||||
|
Logo = req.Logo
|
||||||
|
};
|
||||||
|
|
||||||
|
await settingsRepository.AddAsync(setting, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Settings;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
|
public class DeleteSettingRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint<DeleteSettingRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/settings/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (setting == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await settingsRepository.DeleteAsync(setting, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Settings;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
|
public class GetSettingRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetSettingEndpoint(
|
||||||
|
SettingsRepository settingsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/settings/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (setting == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Settings;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
|
public class PatchSettingElectronicSignatureEndpoint(
|
||||||
|
SettingsRepository settingsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (setting == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting.ElectronicSignature = req.ElectronicSignature;
|
||||||
|
await settingsRepository.UpdateAsync(setting, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Settings;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Settings;
|
||||||
|
|
||||||
|
public class PatchSettingLogoEndpoint(
|
||||||
|
SettingsRepository settingsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/settings/{@Id}/logo", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (setting == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setting.Logo = req.Logo;
|
||||||
|
await settingsRepository.UpdateAsync(setting, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class CreateSupplierEndpoint(
|
||||||
|
SuppliersRepository suppliersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/suppliers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Supplier? supplier = new Supplier()
|
||||||
|
{
|
||||||
|
Name = req.Name,
|
||||||
|
Email = req.Email,
|
||||||
|
Phone = req.Phone,
|
||||||
|
Address = req.Address,
|
||||||
|
City = req.City,
|
||||||
|
ZipCode = req.ZipCode,
|
||||||
|
DeliveryDelay = req.DeliveryDelay
|
||||||
|
};
|
||||||
|
|
||||||
|
await suppliersRepository.AddAsync(supplier, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Suppliers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class DeleteSupplierRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : Endpoint<DeleteSupplierRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/suppliers/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await suppliersRepository.DeleteAsync(supplier, ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs
Normal file
20
PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) : EndpointWithoutRequest<List<GetSupplierDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/suppliers");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await suppliersRepository.ProjectToListAsync<GetSupplierDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Suppliers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class GetSupplierRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetSupplierEndpoint(
|
||||||
|
SuppliersRepository suppliersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/suppliers/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Suppliers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class PatchSupplierDeliveryDelayEndpoint(
|
||||||
|
SuppliersRepository suppliersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||||
|
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs
Normal file
43
PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Suppliers;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Suppliers;
|
||||||
|
|
||||||
|
public class UpdateSupplierEndpoint(
|
||||||
|
SuppliersRepository suppliersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/suppliers/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
supplier.Name = req.Name;
|
||||||
|
supplier.Email = req.Email;
|
||||||
|
supplier.Phone = req.Phone;
|
||||||
|
supplier.Address = req.Address;
|
||||||
|
supplier.City = req.City;
|
||||||
|
supplier.ZipCode = req.ZipCode;
|
||||||
|
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||||
|
|
||||||
|
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using PasswordGenerator;
|
|
||||||
using PyroFetes.DTO.User.Request;
|
|
||||||
using PyroFetes.DTO.User.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
|
||||||
|
|
||||||
public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUserDto, GetUserDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/users");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
|
||||||
|
|
||||||
var user = new Models.User()
|
|
||||||
{
|
|
||||||
Name = req.Name,
|
|
||||||
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
|
||||||
Salt = salt,
|
|
||||||
Email = req.Email,
|
|
||||||
Fonction = req.Fonction
|
|
||||||
};
|
|
||||||
|
|
||||||
database.Users.Add(user);
|
|
||||||
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetUserDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
Name = user.Name,
|
|
||||||
Password = user.Password,
|
|
||||||
Salt = user.Salt,
|
|
||||||
Email = user.Email,
|
|
||||||
Fonction = user.Fonction
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.User.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
|
||||||
|
|
||||||
public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetUserDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/users");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
var users = await database.Users
|
|
||||||
.Select(users => new GetUserDto()
|
|
||||||
{
|
|
||||||
Id = users.Id,
|
|
||||||
Name = users.Name,
|
|
||||||
Password = users.Password,
|
|
||||||
Salt = users.Salt,
|
|
||||||
Email = users.Email,
|
|
||||||
Fonction = users.Fonction
|
|
||||||
})
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(users, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.User.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
|
||||||
|
|
||||||
public class GetUserRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequest, GetUserDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/users/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var user = await database.Users
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetUserDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
Name = user.Name,
|
|
||||||
Password = user.Password,
|
|
||||||
Salt = user.Salt,
|
|
||||||
Email = user.Email,
|
|
||||||
Fonction = user.Fonction
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.User.Request;
|
|
||||||
using PyroFetes.DTO.User.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
|
||||||
|
|
||||||
public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Patch("/api/users/{@Id}/Password", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetUserDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
Name = user.Name,
|
|
||||||
Password = user.Password,
|
|
||||||
Salt = user.Salt,
|
|
||||||
Email = user.Email,
|
|
||||||
Fonction = user.Fonction
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,20 +3,23 @@ using FastEndpoints.Security;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.User.Request;
|
using PyroFetes.DTO.User.Request;
|
||||||
using PyroFetes.DTO.User.Response;
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint<ConnectUserDto, GetTokenDto>
|
public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<ConnectUserDto, GetTokenDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/users/connect");
|
Post("/users/connection");
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
|
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
@@ -26,7 +29,7 @@ public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint<Connect
|
|||||||
|
|
||||||
if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password))
|
if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password))
|
||||||
{
|
{
|
||||||
var jwtToken = JwtBearer.CreateToken(
|
string jwtToken = JwtBearer.CreateToken(
|
||||||
o =>
|
o =>
|
||||||
{
|
{
|
||||||
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||||
46
PyroFetes/Endpoints/Users/CreateUserEndpoint.cs
Normal file
46
PyroFetes/Endpoints/Users/CreateUserEndpoint.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PasswordGenerator;
|
||||||
|
using PyroFetes.DTO.User.Request;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
|
public class CreateUserEndpoint(
|
||||||
|
UsersRepository usersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateUserDto, GetUserDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/users");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||||
|
|
||||||
|
if (ckeckName != null)
|
||||||
|
{
|
||||||
|
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||||
|
|
||||||
|
User user = new User()
|
||||||
|
{
|
||||||
|
Name = req.Name,
|
||||||
|
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
||||||
|
Salt = salt,
|
||||||
|
Email = req.Email,
|
||||||
|
Fonction = req.Fonction
|
||||||
|
};
|
||||||
|
|
||||||
|
await usersRepository.AddAsync(user, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,27 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
public class DeleteUserRequest
|
public class DeleteUserRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUserRequest>
|
public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint<DeleteUserRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/users/{@Id}", x => new {x.Id});
|
Delete("/users/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
@@ -25,8 +29,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
database.Users.Remove(user);
|
await usersRepository.DeleteAsync(user, ct);
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
20
PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs
Normal file
20
PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
|
public class GetAllUsersEndpoint(UsersRepository usersRepository) : EndpointWithoutRequest<List<GetUserDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/users");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await usersRepository.ProjectToListAsync<GetUserDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
PyroFetes/Endpoints/Users/GetUserEndpoint.cs
Normal file
37
PyroFetes/Endpoints/Users/GetUserEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
|
public class GetUserRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetUserEndpoint(
|
||||||
|
UsersRepository usersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/users/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.User.Request;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
|
public class PatchUserPasswordEndpoint(
|
||||||
|
UsersRepository usersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Patch("/users/{@Id}/password", x => new { x.Id });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
|
||||||
|
await usersRepository.UpdateAsync(user, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,26 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using PasswordGenerator;
|
using PasswordGenerator;
|
||||||
using PyroFetes.DTO.User.Request;
|
using PyroFetes.DTO.User.Request;
|
||||||
using PyroFetes.DTO.User.Response;
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.Users;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.User;
|
namespace PyroFetes.Endpoints.Users;
|
||||||
|
|
||||||
public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUserDto, GetUserDto>
|
public class UpdateUserEndpoint(
|
||||||
|
UsersRepository usersRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateUserDto, GetUserDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/api/users/{@Id}", x => new {x.Id});
|
Put("/users/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||||
var ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
@@ -24,7 +30,7 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUs
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ckeckName != null)
|
if (ckeckName != null && ckeckName.Id != user.Id)
|
||||||
{
|
{
|
||||||
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct);
|
||||||
return;
|
return;
|
||||||
@@ -37,18 +43,9 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUs
|
|||||||
user.Salt = salt;
|
user.Salt = salt;
|
||||||
user.Email = req.Email;
|
user.Email = req.Email;
|
||||||
user.Fonction = req.Fonction;
|
user.Fonction = req.Fonction;
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetUserDto responseDto = new()
|
await usersRepository.UpdateAsync(user, ct);
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
Name = user.Name,
|
|
||||||
Password = user.Password,
|
|
||||||
Salt = user.Salt,
|
|
||||||
Email = user.Email,
|
|
||||||
Fonction = user.Fonction
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
|
||||||
|
|
||||||
public class GetTotalQuantityRequest
|
|
||||||
{
|
|
||||||
public int ProductId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/wareHouseProduct/{@ProductId}", x => new { x.ProductId });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var exists = await database.WarehouseProducts
|
|
||||||
.AnyAsync(wp => wp.ProductId == req.ProductId, ct);
|
|
||||||
|
|
||||||
if (!exists)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var totalQuantity = await database.WarehouseProducts
|
|
||||||
.Where(wp => wp.ProductId == req.ProductId)
|
|
||||||
.SumAsync(wp => wp.Quantity, ct);
|
|
||||||
|
|
||||||
GetTotalQuantityDto responseDto = new()
|
|
||||||
{
|
|
||||||
ProductId = req.ProductId,
|
|
||||||
TotalQuantity = totalQuantity
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.WarehouseProducts;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||||
|
|
||||||
|
public class GetTotalQuantityRequest
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetTotalQuantityEndpoint(
|
||||||
|
WarehouseProductsRepository warehouseProductsRepository) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/wareHouseProducts/{@ProductId}", x => new { x.ProductId });
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct);
|
||||||
|
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int? totalQuantityNullable = await warehouseProductsRepository.
|
||||||
|
SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
|
||||||
|
|
||||||
|
int totalQuantity = totalQuantityNullable ?? 0;
|
||||||
|
|
||||||
|
GetTotalQuantityDto responseDto = new()
|
||||||
|
{
|
||||||
|
ProductId = req.ProductId,
|
||||||
|
TotalQuantity = totalQuantity
|
||||||
|
};
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +1,32 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.QuotationProduct.Request;
|
|
||||||
using PyroFetes.DTO.QuotationProduct.Response;
|
|
||||||
using PyroFetes.DTO.WareHouseProduct.Request;
|
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||||
|
|
||||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
|
||||||
|
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Patch("/api/wareHouseProduct/{@ProductId}/{@WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId });
|
Patch("/wareHouseProducts/{@ProductId}/{@WareHouseId}/quantity", x => new { x.ProductId, x.WareHouseId });
|
||||||
AllowAnonymous();
|
AllowAnonymous();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
|
WarehouseProduct? wareHouseProduct =
|
||||||
|
await database.WarehouseProducts.SingleOrDefaultAsync(
|
||||||
|
wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
|
||||||
|
|
||||||
if (wareHouseProduct == null)
|
if (wareHouseProduct == null)
|
||||||
{
|
{
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wareHouseProduct.Quantity = req.Quantity;
|
wareHouseProduct.Quantity = req.Quantity;
|
||||||
await database.SaveChangesAsync(ct);
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using PyroFetes.DTO.Deliverer.Request;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.DTO.Price.Request;
|
||||||
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.DTO.ProductDelivery.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||||
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Request;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.User.Request;
|
||||||
|
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.MappingProfiles;
|
||||||
|
|
||||||
|
public class DtoToEntityMappings : Profile
|
||||||
|
{
|
||||||
|
public DtoToEntityMappings()
|
||||||
|
{
|
||||||
|
CreateMap<CreateDelivererDto, Deliverer>();
|
||||||
|
CreateMap<UpdateDelivererDto, Deliverer>();
|
||||||
|
|
||||||
|
CreateMap<CreateDeliveryNoteDto, DeliveryNote>();
|
||||||
|
CreateMap<UpdateDeliveryNoteDto, DeliveryNote>();
|
||||||
|
CreateMap<PatchDeliveryNoteRealDeliveryDateDto, DeliveryNote>();
|
||||||
|
|
||||||
|
CreateMap<CreatePriceDto, Price>();
|
||||||
|
CreateMap<UpdatePriceDto, Price>();
|
||||||
|
CreateMap<PatchPriceSellingPriceDto, Price>();
|
||||||
|
|
||||||
|
CreateMap<CreateProductDto, Product>();
|
||||||
|
CreateMap<UpdateProductDto, Product>();
|
||||||
|
CreateMap<PatchProductMinimalStockDto, Product>();
|
||||||
|
|
||||||
|
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
|
||||||
|
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
|
||||||
|
|
||||||
|
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>();
|
||||||
|
|
||||||
|
CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
|
||||||
|
CreateMap<UpdatePurchaseProductDto, PurchaseProduct>();
|
||||||
|
CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>();
|
||||||
|
|
||||||
|
CreateMap<PatchQuotationConditionsSaleDto, Quotation>();
|
||||||
|
CreateMap<PatchQuotationMessageDto, Quotation>();
|
||||||
|
|
||||||
|
CreateMap<CreateQuotationProductDto, QuotationProduct>();
|
||||||
|
CreateMap<UpdateQuotationProductDto, QuotationProduct>();
|
||||||
|
CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>();
|
||||||
|
|
||||||
|
CreateMap<CreateSettingDto, Setting>();
|
||||||
|
CreateMap<PatchSettingElectronicSignatureDto, Setting>();
|
||||||
|
CreateMap<PatchSettingLogoDto, Setting>();
|
||||||
|
|
||||||
|
CreateMap<CreateSupplierDto, Supplier>();
|
||||||
|
CreateMap<UpdateSupplierDto, Supplier>();
|
||||||
|
CreateMap<PatchSupplierDeliveryDelayDto, Supplier>();
|
||||||
|
|
||||||
|
CreateMap<CreateUserDto, User>();
|
||||||
|
CreateMap<UpdateUserDto, User>();
|
||||||
|
CreateMap<PatchUserPasswordDto, User>();
|
||||||
|
|
||||||
|
CreateMap<PatchWareHouseProductQuantityDto, WarehouseProduct>();
|
||||||
|
}
|
||||||
|
}
|
||||||
49
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
49
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.DTO.Price.Response;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.DTO.ProductDelivery.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.MappingProfiles;
|
||||||
|
|
||||||
|
public class EntityToDtoMappings : Profile
|
||||||
|
{
|
||||||
|
public EntityToDtoMappings()
|
||||||
|
{
|
||||||
|
CreateMap<Deliverer, GetDelivererDto>();
|
||||||
|
|
||||||
|
CreateMap<Supplier, GetSupplierDto>();
|
||||||
|
|
||||||
|
CreateMap<DeliveryNote, GetDeliveryNoteDto>();
|
||||||
|
|
||||||
|
CreateMap<Price, GetPriceDto>();
|
||||||
|
|
||||||
|
CreateMap<Product, GetProductDto>();
|
||||||
|
|
||||||
|
CreateMap<ProductDelivery, GetProductDeliveryDto>();
|
||||||
|
|
||||||
|
CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
|
||||||
|
|
||||||
|
CreateMap<PurchaseProduct, GetPurchaseProductDto>();
|
||||||
|
|
||||||
|
CreateMap<Quotation, GetQuotationDto>();
|
||||||
|
|
||||||
|
CreateMap<QuotationProduct, GetQuotationProductDto>();
|
||||||
|
|
||||||
|
CreateMap<Setting, GetSettingDto>();
|
||||||
|
|
||||||
|
CreateMap<User, GetUserDto>();
|
||||||
|
|
||||||
|
CreateMap<WarehouseProduct, GetWareHouseProductDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
1963
PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs
generated
Normal file
1963
PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
PyroFetes/Migrations/20251113162655_FixedNullableValue.cs
Normal file
37
PyroFetes/Migrations/20251113162655_FixedNullableValue.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PyroFetes.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class FixedNullableValue : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<DateOnly>(
|
||||||
|
name: "RealDeliveryDate",
|
||||||
|
table: "DeliveryNotes",
|
||||||
|
type: "date",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(DateOnly),
|
||||||
|
oldType: "date");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<DateOnly>(
|
||||||
|
name: "RealDeliveryDate",
|
||||||
|
table: "DeliveryNotes",
|
||||||
|
type: "date",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateOnly(1, 1, 1),
|
||||||
|
oldClrType: typeof(DateOnly),
|
||||||
|
oldType: "date",
|
||||||
|
oldNullable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user