Compare commits
22 Commits
0511bb5075
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3ffde3ff | ||
|
|
50a5f371dd | ||
| 86c5d6ae7b | |||
| 1c0432a2c4 | |||
| 6be43958fa | |||
| 3e8f36457e | |||
| 5d68ee6992 | |||
|
|
d26284d552 | ||
|
|
d537051bea | ||
|
|
3ad506f869 | ||
|
|
9aac7c39f2 | ||
|
|
b76b668097 | ||
|
|
669938d677 | ||
|
|
165c9b9322 | ||
|
|
0b72549143 | ||
|
|
d64890dec9 | ||
|
|
8325aa0768 | ||
|
|
ee9b4675dd | ||
|
|
f6383265ba | ||
|
|
7bf0b5bfd1 | ||
|
|
bd653c149c | ||
| 27e8fea7f3 |
@@ -17,8 +17,8 @@ public class CreatePriceDto
|
||||
public string? ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public int ProductCaliber { get; set; }
|
||||
public string? ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
|
||||
@@ -5,8 +5,8 @@ public class CreateProductDto
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
public int ApprovalNumber { get; set; }
|
||||
public int Caliber { get; set; }
|
||||
public string? ApprovalNumber { get; set; }
|
||||
public decimal Weight { get; set; }
|
||||
public decimal Nec { get; set; }
|
||||
public string? Image { get; set; }
|
||||
|
||||
@@ -6,8 +6,8 @@ public class UpdateProductDto
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
public int ApprovalNumber { get; set; }
|
||||
public int Caliber { get; set; }
|
||||
public string? ApprovalNumber { get; set; }
|
||||
public decimal Weight { get; set; }
|
||||
public decimal Nec { get; set; }
|
||||
public string? Image { get; set; }
|
||||
|
||||
@@ -6,8 +6,8 @@ public class GetProductDto
|
||||
public string? References { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public decimal Duration {get; set;}
|
||||
public decimal Caliber { get; set; }
|
||||
public int ApprovalNumber { get; set; }
|
||||
public int Caliber { get; set; }
|
||||
public string? ApprovalNumber { get; set; }
|
||||
public decimal Weight { get; set; }
|
||||
public decimal Nec { get; set; }
|
||||
public string? Image { get; set; }
|
||||
|
||||
@@ -12,7 +12,7 @@ public class CreateDelivererEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("api/deliverers");
|
||||
Post("/deliverers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository)
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("api/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
Delete("/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/deliverers");
|
||||
Get("/deliverers");
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class GetDelivererEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
Get("/deliverers/{@id}", x=>new {x.DelivererId});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class UpdateDelivererEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("api/deliverers/{@id}", x=>new {x.Id});
|
||||
Put("/deliverers/{@id}", x=>new {x.Id});
|
||||
AllowAnonymous();
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CreateDeliveryNoteEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/DeliveryNote");
|
||||
Post("/deliveryNotes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRep
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("api/deliveryNotes");
|
||||
Get("/deliveryNotes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class GetDeliveryNoteEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId});
|
||||
Get("/deliveryNotes/{@id}", x=> new {x.DeliveryNoteId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class PatchRealDeliveryDateEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/deliveryNote/{@id}", x=> new {x.Id});
|
||||
Patch("/deliveryNotes/{@id}", x=> new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CreatePriceEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/prices");
|
||||
Post("/prices");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
|
||||
namespace PyroFetes.Endpoints.Prices;
|
||||
|
||||
@@ -10,18 +12,17 @@ public class DeletePriceRequest
|
||||
public int SupplierId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint<DeletePriceRequest>
|
||||
public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
|
||||
Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
|
||||
{
|
||||
Price? price = await database.Prices
|
||||
.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct);
|
||||
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId,req.SupplierId), ct);
|
||||
|
||||
if (price == null)
|
||||
{
|
||||
@@ -29,8 +30,7 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint<DeleteP
|
||||
return;
|
||||
}
|
||||
|
||||
database.Prices.Remove(price);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await pricesRepository.DeleteAsync(price, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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(PyroFetesDbContext database) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto>
|
||||
public class PatchPriceEndpoint(
|
||||
PricesRepository pricesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
|
||||
Patch("/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct)
|
||||
{
|
||||
Price? price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct);
|
||||
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct);
|
||||
|
||||
if (price == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -24,14 +28,9 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint<PatchPri
|
||||
}
|
||||
|
||||
price.SellingPrice = req.SellingPrice;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetPriceDto responseDto = new()
|
||||
{
|
||||
ProductId = price.ProductId,
|
||||
SupplierId = price.SupplierId,
|
||||
SellingPrice = price.SellingPrice
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
|
||||
await pricesRepository.UpdateAsync(price, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPriceDto>(price), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Products;
|
||||
|
||||
public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetProductDto>>
|
||||
public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/products");
|
||||
Get("/products");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetProductDto> product = await database.Products
|
||||
.Select(product => new GetProductDto()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(product, ct);
|
||||
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Products;
|
||||
|
||||
namespace PyroFetes.Endpoints.Products;
|
||||
|
||||
@@ -10,18 +12,19 @@ public class GetProductRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint<GetProductRequest, GetProductDto>
|
||||
public class GetProductEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetProductRequest, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/products/{@Id}", x => new {x.Id});
|
||||
Get("/products/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await database.Products
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
@@ -29,21 +32,6 @@ public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint<GetProdu
|
||||
return;
|
||||
}
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,25 @@ 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(PyroFetesDbContext database)
|
||||
: Endpoint<PatchProductMinimalStockDto, GetProductDto>
|
||||
public class PatchProductMinimalStockEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id });
|
||||
Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -25,22 +29,8 @@ public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database)
|
||||
}
|
||||
|
||||
product.MinimalQuantity = req.MinimalQuantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await productsRepository.UpdateAsync(product, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,24 @@ 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(PyroFetesDbContext database) : Endpoint<UpdateProductDto, GetProductDto>
|
||||
public class UpdateProductEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto, GetProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/products/{@Id}", x => new {x.Id});
|
||||
Put("/products/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await database.Products.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
@@ -34,23 +38,9 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint<Updat
|
||||
product.Image = req.Image;
|
||||
product.Link = req.Link;
|
||||
product.MinimalQuantity = req.MinimalQuantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetProductDto responseDto = new()
|
||||
{
|
||||
Id = product.Id,
|
||||
References = product.Reference,
|
||||
Name = product.Name,
|
||||
Duration = product.Duration,
|
||||
Caliber = product.Caliber,
|
||||
ApprovalNumber = product.ApprovalNumber,
|
||||
Weight = product.Weight,
|
||||
Nec = product.Nec,
|
||||
Image = product.Image,
|
||||
Link = product.Link,
|
||||
MinimalQuantity = product.MinimalQuantity,
|
||||
};
|
||||
await productsRepository.UpdateAsync(product, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||
|
||||
@@ -9,19 +11,19 @@ public class DeletePurchaseOrderRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
|
||||
public class DeletePurchaseOrderEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseOrderRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
Delete("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await database.PurchaseOrders
|
||||
.Include(po => po.PurchaseProducts)
|
||||
.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
@@ -31,11 +33,10 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint
|
||||
|
||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||
{
|
||||
database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts);
|
||||
await purchaseProductsRepository.DeleteRangeAsync(purchaseOrder.PurchaseProducts, ct);
|
||||
}
|
||||
|
||||
database.PurchaseOrders.Remove(purchaseOrder);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -2,45 +2,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||
|
||||
public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
||||
public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders");
|
||||
Get("/purchaseOrders");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetPurchaseOrderDto> 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);
|
||||
await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync<GetPurchaseOrderDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ 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;
|
||||
|
||||
@@ -11,18 +13,19 @@ public class GetPurchaseOrderRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
public class GetPurchaseOrderEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
Get("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await database.PurchaseOrders
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
@@ -30,29 +33,6 @@ public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<Ge
|
||||
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);
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,24 @@ 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(PyroFetesDbContext database) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
||||
Patch("/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -25,30 +29,8 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext dat
|
||||
}
|
||||
|
||||
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
||||
await database.SaveChangesAsync(ct);
|
||||
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, 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);
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,66 +3,54 @@ 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(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
public class CreatePurchaseProductEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
PurchaseProductsRepository purchaseProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/purchaseProducts");
|
||||
Post("/purchaseProducts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
PurchaseOrder? purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct);
|
||||
|
||||
|
||||
PurchaseOrder? purchaseOrder =
|
||||
await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
purchaseOrder = new PurchaseOrder()
|
||||
{
|
||||
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
|
||||
};
|
||||
database.PurchaseOrders.Add(purchaseOrder);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
|
||||
}
|
||||
|
||||
|
||||
PurchaseProduct purchaseProduct = new PurchaseProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
PurchaseOrderId = purchaseOrder.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
database.PurchaseProducts.Add(purchaseProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetPurchaseProductDto 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 purchaseProductsRepository.AddAsync(purchaseProduct, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||
|
||||
@@ -10,18 +12,18 @@ public class DeletePurchaseProductRequest
|
||||
public int PurchaseOrderId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseProductRequest>
|
||||
public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||
Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
||||
{
|
||||
PurchaseProduct? purchaseProduct = await database.PurchaseProducts
|
||||
.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
||||
PurchaseProduct? purchaseProduct = await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
@@ -29,8 +31,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint
|
||||
return;
|
||||
}
|
||||
|
||||
database.PurchaseProducts.Remove(purchaseProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -3,20 +3,27 @@ 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(PyroFetesDbContext database) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
||||
public class PatchPurchaseProductQuantityEndpoint(
|
||||
PurchaseProductsRepository purchaseProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
Patch("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
PurchaseProduct? purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct);
|
||||
PurchaseProduct? purchaseProduct =
|
||||
await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -24,14 +31,8 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) :
|
||||
}
|
||||
|
||||
purchaseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
await purchaseProductsRepository.UpdateAsync(purchaseProduct, ct);
|
||||
|
||||
GetPurchaseProductDto responseDto = new()
|
||||
{
|
||||
ProductId = purchaseProduct.ProductId,
|
||||
PurchaseOrderId = purchaseProduct.PurchaseOrderId,
|
||||
Quantity = purchaseProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,35 @@ 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(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||
public class CreateQuotationProductEndpoint(
|
||||
QuotationProductsRepository quotationProductsRepository,
|
||||
ProductsRepository productsRepository,
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/quotationProduct");
|
||||
Post("/quotationProducts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
Quotation? quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
@@ -32,8 +40,8 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
|
||||
Message = req.QuotationMessage ?? "",
|
||||
ConditionsSale = req.QuotationConditionsSale,
|
||||
};
|
||||
database.Quotations.Add(quotation);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
await quotationsRepository.AddAsync(quotation, ct);
|
||||
}
|
||||
|
||||
QuotationProduct quotationProduct = new QuotationProduct()
|
||||
@@ -42,28 +50,9 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
|
||||
QuotationId = quotation.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
database.QuotationProducts.Add(quotationProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetQuotationProductDto 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 quotationProductsRepository.AddAsync(quotationProduct, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.QuotationProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||
|
||||
@@ -10,18 +12,19 @@ public class DeleteQuotationProductRequest
|
||||
public int QuotationId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
|
||||
public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
||||
Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
|
||||
{
|
||||
QuotationProduct? quotationProduct = await database.QuotationProducts
|
||||
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
||||
QuotationProduct? quotationProduct =
|
||||
await quotationProductsRepository.FirstOrDefaultAsync(
|
||||
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
|
||||
if (quotationProduct == null)
|
||||
{
|
||||
@@ -29,8 +32,7 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
|
||||
return;
|
||||
}
|
||||
|
||||
database.QuotationProducts.Remove(quotationProduct);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -3,20 +3,26 @@ 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(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||
public class PatchQuotationProductQuantityEndpoint(
|
||||
QuotationProductsRepository quotationProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||
Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
QuotationProduct? quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
|
||||
QuotationProduct? quotationProduct =
|
||||
await quotationProductsRepository.FirstOrDefaultAsync(
|
||||
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
if (quotationProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -24,14 +30,8 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database)
|
||||
}
|
||||
|
||||
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);
|
||||
await quotationProductsRepository.UpdateAsync(quotationProduct, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
@@ -9,19 +11,19 @@ public class DeleteQuotationRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationRequest>
|
||||
public class DeleteQuotationEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/quotations/{@Id}", x => new {x.Id});
|
||||
Delete("/quotations/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await database.Quotations
|
||||
.Include(q => q.QuotationProducts)
|
||||
.SingleOrDefaultAsync(q => q.Id == req.Id, ct);
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
@@ -31,11 +33,10 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<Del
|
||||
|
||||
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
|
||||
{
|
||||
database.QuotationProducts.RemoveRange(quotation.QuotationProducts);
|
||||
await quotationProductsRepository.DeleteRangeAsync(quotation.QuotationProducts, ct);
|
||||
}
|
||||
|
||||
database.Quotations.Remove(quotation);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await quotationsRepository.DeleteAsync(quotation, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -3,48 +3,20 @@ 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(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetQuotationDto>>
|
||||
public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository) : EndpointWithoutRequest<List<GetQuotationDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/quotations");
|
||||
Get("/quotations");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetQuotationDto> 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);
|
||||
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ 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;
|
||||
|
||||
@@ -11,18 +13,19 @@ public class GetQuotationRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
||||
public class GetQuotationEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/quotations/{@Id}", x => new {x.Id});
|
||||
Get("/quotations/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await database.Quotations
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
@@ -30,32 +33,6 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuo
|
||||
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);
|
||||
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,25 @@ using PyroFetes.DTO.Quotation.Request;
|
||||
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 PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
||||
public class PatchQuotationConditionsSaleEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id });
|
||||
Patch("/quotations/{@Id}/saleConditions", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -25,32 +30,9 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) :
|
||||
}
|
||||
|
||||
quotation.ConditionsSale = req.ConditionsSale;
|
||||
await database.SaveChangesAsync(ct);
|
||||
await quotationsRepository.UpdateAsync(quotation, 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);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,17 @@
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||
public class CreateSettingEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/setting");
|
||||
Post("/settings");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
@@ -21,15 +24,8 @@ public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<Creat
|
||||
Logo = req.Logo
|
||||
};
|
||||
|
||||
database.Settings.Add(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await settingsRepository.AddAsync(setting, ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
@@ -9,17 +11,17 @@ public class DeleteSettingRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
|
||||
public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint<DeleteSettingRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/setting/{@Id}", x => new {x.Id});
|
||||
Delete("/settings/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
@@ -27,8 +29,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<Delet
|
||||
return;
|
||||
}
|
||||
|
||||
database.Settings.Remove(setting);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await settingsRepository.DeleteAsync(setting, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
@@ -10,18 +12,19 @@ public class GetSettingRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||
public class GetSettingEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/setting/{@Id}", x => new {x.Id});
|
||||
Get("/settings/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await database.Settings
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
@@ -29,12 +32,6 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSetti
|
||||
return;
|
||||
}
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,25 @@ 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(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||
public class PatchSettingElectronicSignatureEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||
Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -25,15 +29,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database
|
||||
}
|
||||
|
||||
setting.ElectronicSignature = req.ElectronicSignature;
|
||||
await database.SaveChangesAsync(ct);
|
||||
await settingsRepository.UpdateAsync(setting, ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,24 @@ 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(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||
public class PatchSettingLogoEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/setting/{@Id}/Logo", x => new {x.Id});
|
||||
Patch("/settings/{@Id}/logo", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
@@ -25,15 +29,8 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<Pa
|
||||
}
|
||||
|
||||
setting.Logo = req.Logo;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSettingDto responseDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = setting.ElectronicSignature,
|
||||
Logo = setting.Logo
|
||||
};
|
||||
await settingsRepository.UpdateAsync(setting, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,17 @@
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||
public class CreateSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/suppliers");
|
||||
Post("/suppliers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
@@ -26,20 +29,8 @@ public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Crea
|
||||
DeliveryDelay = req.DeliveryDelay
|
||||
};
|
||||
|
||||
database.Suppliers.Add(supplier);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await suppliersRepository.AddAsync(supplier, ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
@@ -9,17 +11,17 @@ public class DeleteSupplierRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSupplierRequest>
|
||||
public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : Endpoint<DeleteSupplierRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
Delete("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
@@ -27,8 +29,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Dele
|
||||
return;
|
||||
}
|
||||
|
||||
database.Suppliers.Remove(supplier);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await suppliersRepository.DeleteAsync(supplier, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,20 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetSupplierDto>>
|
||||
public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) : EndpointWithoutRequest<List<GetSupplierDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/suppliers");
|
||||
Get("/suppliers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetSupplierDto> supplier = await database.Suppliers
|
||||
.Select(supplier => new GetSupplierDto()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(supplier, ct);
|
||||
await Send.OkAsync(await suppliersRepository.ProjectToListAsync<GetSupplierDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
@@ -10,18 +12,19 @@ public class GetSupplierRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
public class GetSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
Get("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await database.Suppliers
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
@@ -29,17 +32,6 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupp
|
||||
return;
|
||||
}
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,24 @@ 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 PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
|
||||
public class PatchSupplierDeliveryDelayEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id});
|
||||
Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
@@ -25,14 +29,8 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E
|
||||
}
|
||||
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
DeliveryDelay = supplier.DeliveryDelay,
|
||||
};
|
||||
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,24 @@ 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(PyroFetesDbContext database) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
||||
public class UpdateSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/suppliers/{@Id}", x => new {x.Id});
|
||||
Put("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
{
|
||||
@@ -31,20 +35,9 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Upda
|
||||
supplier.City = req.City;
|
||||
supplier.ZipCode = req.ZipCode;
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetSupplierDto responseDto = new()
|
||||
{
|
||||
Id = supplier.Id,
|
||||
Name = supplier.Name,
|
||||
Email = supplier.Email,
|
||||
Phone = supplier.Phone,
|
||||
Address = supplier.Address,
|
||||
City = supplier.City,
|
||||
ZipCode = supplier.ZipCode,
|
||||
DeliveryDelay = supplier.DeliveryDelay
|
||||
};
|
||||
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,22 @@ 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 ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint<ConnectUserDto, GetTokenDto>
|
||||
public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<ConnectUserDto, GetTokenDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/users/connect");
|
||||
Post("/users/connection");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
|
||||
{
|
||||
User? user = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,17 @@ using PasswordGenerator;
|
||||
using PyroFetes.DTO.User.Request;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUserDto, GetUserDto>
|
||||
public class CreateUserEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateUserDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/users");
|
||||
Post("/users");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
@@ -27,20 +30,8 @@ public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUs
|
||||
Fonction = req.Fonction
|
||||
};
|
||||
|
||||
database.Users.Add(user);
|
||||
await usersRepository.AddAsync(user, ct);
|
||||
|
||||
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);
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Users;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
@@ -9,17 +11,17 @@ public class DeleteUserRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUserRequest>
|
||||
public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint<DeleteUserRequest>
|
||||
{
|
||||
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)
|
||||
{
|
||||
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -27,8 +29,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUs
|
||||
return;
|
||||
}
|
||||
|
||||
database.Users.Remove(user);
|
||||
await database.SaveChangesAsync(ct);
|
||||
await usersRepository.DeleteAsync(user, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetUserDto>>
|
||||
public class GetAllUsersEndpoint(UsersRepository usersRepository) : EndpointWithoutRequest<List<GetUserDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/users");
|
||||
Get("/users");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetUserDto> 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);
|
||||
await Send.OkAsync(await usersRepository.ProjectToListAsync<GetUserDto>(ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.User.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Users;
|
||||
|
||||
namespace PyroFetes.Endpoints.Users;
|
||||
|
||||
@@ -10,18 +12,19 @@ public class GetUserRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequest, GetUserDto>
|
||||
public class GetUserEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/users/{@Id}", x => new {x.Id});
|
||||
Get("/users/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
|
||||
{
|
||||
User? user = await database.Users
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -29,16 +32,6 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequ
|
||||
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);
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
}
|
||||
}
|
||||
@@ -3,20 +3,25 @@ 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(PyroFetesDbContext database) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||
public class PatchUserPasswordEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/users/{@Id}/Password", x => new { x.Id });
|
||||
Patch("/users/{@Id}/password", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
|
||||
{
|
||||
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
@@ -24,17 +29,8 @@ public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint<P
|
||||
}
|
||||
|
||||
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);
|
||||
await usersRepository.UpdateAsync(user, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,25 @@ 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 UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUserDto, GetUserDto>
|
||||
public class UpdateUserEndpoint(
|
||||
UsersRepository usersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateUserDto, GetUserDto>
|
||||
{
|
||||
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)
|
||||
{
|
||||
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
User? ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
|
||||
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@@ -39,18 +43,9 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUs
|
||||
user.Salt = salt;
|
||||
user.Email = req.Email;
|
||||
user.Fonction = req.Fonction;
|
||||
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 usersRepository.UpdateAsync(user, ct);
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||
|
||||
@@ -10,18 +12,18 @@ public class GetTotalQuantityRequest
|
||||
public int ProductId { get; set; }
|
||||
}
|
||||
|
||||
public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
||||
public class GetTotalQuantityEndpoint(
|
||||
WarehouseProductsRepository warehouseProductsRepository) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/wareHouseProduct/{@ProductId}", x => new { x.ProductId });
|
||||
Get("/wareHouseProducts/{@ProductId}", x => new { x.ProductId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
||||
{
|
||||
bool exists = await database.WarehouseProducts
|
||||
.AnyAsync(wp => wp.ProductId == req.ProductId, ct);
|
||||
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct);
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
@@ -29,9 +31,9 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<Ge
|
||||
return;
|
||||
}
|
||||
|
||||
int totalQuantity = await database.WarehouseProducts
|
||||
.Where(wp => wp.ProductId == req.ProductId)
|
||||
.SumAsync(wp => wp.Quantity, ct);
|
||||
int totalQuantity =
|
||||
await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId),
|
||||
wp => wp.Quantity, ct);
|
||||
|
||||
GetTotalQuantityDto responseDto = new()
|
||||
{
|
||||
|
||||
@@ -6,23 +6,27 @@ using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||
|
||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
|
||||
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
WarehouseProduct? 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)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
|
||||
1966
PyroFetes/Migrations/20251120154429_FixTypeErrors.Designer.cs
generated
Normal file
1966
PyroFetes/Migrations/20251120154429_FixTypeErrors.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
68
PyroFetes/Migrations/20251120154429_FixTypeErrors.cs
Normal file
68
PyroFetes/Migrations/20251120154429_FixTypeErrors.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PyroFetes.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixTypeErrors : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ZipCode",
|
||||
table: "Suppliers",
|
||||
type: "nvarchar(5)",
|
||||
maxLength: 5,
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "Caliber",
|
||||
table: "Products",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
oldClrType: typeof(decimal),
|
||||
oldType: "decimal(18,2)");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ApprovalNumber",
|
||||
table: "Products",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ZipCode",
|
||||
table: "Suppliers",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(5)",
|
||||
oldMaxLength: 5);
|
||||
|
||||
migrationBuilder.AlterColumn<decimal>(
|
||||
name: "Caliber",
|
||||
table: "Products",
|
||||
type: "decimal(18,2)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ApprovalNumber",
|
||||
table: "Products",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
}
|
||||
}
|
||||
}
|
||||
1967
PyroFetes/Migrations/20251126193437_UpdatedDatabaseProductType.Designer.cs
generated
Normal file
1967
PyroFetes/Migrations/20251126193437_UpdatedDatabaseProductType.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PyroFetes.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UpdatedDatabaseProductType : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ApprovalNumber",
|
||||
table: "Products",
|
||||
type: "nvarchar(100)",
|
||||
maxLength: 100,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ApprovalNumber",
|
||||
table: "Products",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(100)",
|
||||
oldMaxLength: 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
1967
PyroFetes/Migrations/20251127124107_UpdatedLengthOfPassword.Designer.cs
generated
Normal file
1967
PyroFetes/Migrations/20251127124107_UpdatedLengthOfPassword.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PyroFetes.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class UpdatedLengthOfPassword : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Password",
|
||||
table: "Users",
|
||||
type: "nvarchar(60)",
|
||||
maxLength: 60,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(50)",
|
||||
oldMaxLength: 50);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "Password",
|
||||
table: "Users",
|
||||
type: "nvarchar(50)",
|
||||
maxLength: 50,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(60)",
|
||||
oldMaxLength: 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
1967
PyroFetes/Migrations/20251127133430_FixZipCode.Designer.cs
generated
Normal file
1967
PyroFetes/Migrations/20251127133430_FixZipCode.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
52
PyroFetes/Migrations/20251127133430_FixZipCode.cs
Normal file
52
PyroFetes/Migrations/20251127133430_FixZipCode.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PyroFetes.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FixZipCode : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ZipCode",
|
||||
table: "Warehouses",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(int),
|
||||
oldType: "int");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ZipCode",
|
||||
table: "Suppliers",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(5)",
|
||||
oldMaxLength: 5);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<int>(
|
||||
name: "ZipCode",
|
||||
table: "Warehouses",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "ZipCode",
|
||||
table: "Suppliers",
|
||||
type: "nvarchar(5)",
|
||||
maxLength: 5,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "nvarchar(max)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -503,11 +503,13 @@ namespace PyroFetes.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ApprovalNumber")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("ApprovalNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<decimal>("Caliber")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
b.Property<int>("Caliber")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ClassificationId")
|
||||
.HasColumnType("int");
|
||||
@@ -1113,8 +1115,9 @@ namespace PyroFetes.Migrations
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("nvarchar(30)");
|
||||
|
||||
b.Property<int>("ZipCode")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("ZipCode")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@@ -1178,8 +1181,8 @@ namespace PyroFetes.Migrations
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("nvarchar(50)");
|
||||
.HasMaxLength(60)
|
||||
.HasColumnType("nvarchar(60)");
|
||||
|
||||
b.Property<string>("Salt")
|
||||
.IsRequired()
|
||||
@@ -1223,8 +1226,9 @@ namespace PyroFetes.Migrations
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("nvarchar(100)");
|
||||
|
||||
b.Property<int>("ZipCode")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("ZipCode")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace PyroFetes.Models
|
||||
[Required, MaxLength(20)] public string? Reference { get; set; }
|
||||
[Required, MaxLength(100)] public string? Name { get; set; }
|
||||
[Required] public decimal Duration {get; set;}
|
||||
[Required] public decimal Caliber { get; set; }
|
||||
[Required] public int ApprovalNumber { get; set; }
|
||||
[Required] public int Caliber { get; set; }
|
||||
[Required, MaxLength(100)] public string? ApprovalNumber { get; set; }
|
||||
[Required] public decimal Weight { get; set; }
|
||||
[Required] public decimal Nec { get; set; }
|
||||
[Required] public string? Image { get; set; }
|
||||
|
||||
@@ -9,7 +9,7 @@ public class Supplier
|
||||
[Required, MaxLength(100)] public string? Email { get; set; }
|
||||
[Required, MaxLength(30)] public string? Phone { get; set; }
|
||||
[Required, MaxLength(100)] public string? Address { get; set; }
|
||||
[Required,MaxLength(5),MinLength(5)] public string? ZipCode { get; set; }
|
||||
[Required,Length(5,5)] public string? ZipCode { get; set; }
|
||||
[Required, MaxLength(100)] public string? City { get; set; }
|
||||
[Required] public int DeliveryDelay { get; set; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ public class User
|
||||
{
|
||||
[Key] public int Id { get; set; }
|
||||
[Required, MaxLength(100)] public string? Name { get; set; }
|
||||
[Required, MinLength(12), MaxLength(50)] public string? Password { get; set; }
|
||||
[Required, MaxLength(60)] public string? Password { get; set; }
|
||||
[Required, MaxLength(100)] public string? Salt { get; set; }
|
||||
[Required, MaxLength(100)] public string? Email { get; set; }
|
||||
[Required, MaxLength(100)] public string? Fonction { get; set; }
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Warehouse
|
||||
[Required] public int Current {get; set;}
|
||||
[Required] public int MinWeight {get; set;}
|
||||
[Required, MaxLength(100)] public string? Address { get; set; }
|
||||
[Required] public int ZipCode { get; set; }
|
||||
[Required, Length(5,5)] public string? ZipCode { get; set; }
|
||||
[Required, MaxLength(100)] public string? City { get; set; }
|
||||
|
||||
public List<WarehouseProduct>? WarehouseProducts { get; set; }
|
||||
|
||||
@@ -5,7 +5,7 @@ using FastEndpoints;
|
||||
using FastEndpoints.Swagger;
|
||||
using FastEndpoints.Security;
|
||||
using PyroFetes.MappingProfiles;
|
||||
using IMapper = FastEndpoints.IMapper;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -14,11 +14,37 @@ builder.Services
|
||||
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
||||
.AddAuthorization()
|
||||
.AddFastEndpoints()
|
||||
.SwaggerDocument();
|
||||
.SwaggerDocument(options =>
|
||||
{
|
||||
options.ShortSchemaNames = true;
|
||||
})
|
||||
.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(policyBuilder =>
|
||||
{
|
||||
policyBuilder
|
||||
.WithOrigins("http://localhost:4200")
|
||||
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
|
||||
// On ajoute ici la configuration de la base de données
|
||||
builder.Services.AddDbContext<PyroFetesDbContext>();
|
||||
|
||||
builder.Services.AddScoped<DeliverersRepository>();
|
||||
builder.Services.AddScoped<DeliveryNotesRepository>();
|
||||
builder.Services.AddScoped<PricesRepository>();
|
||||
builder.Services.AddScoped<ProductDeliveriesRepository>();
|
||||
builder.Services.AddScoped<ProductsRepository>();
|
||||
builder.Services.AddScoped<PurchaseOrdersRepository>();
|
||||
builder.Services.AddScoped<PurchaseProductsRepository>();
|
||||
builder.Services.AddScoped<QuotationProductsRepository>();
|
||||
builder.Services.AddScoped<QuotationsRepository>();
|
||||
builder.Services.AddScoped<SuppliersRepository>();
|
||||
builder.Services.AddScoped<SettingsRepository>();
|
||||
builder.Services.AddScoped<UsersRepository>();
|
||||
builder.Services.AddScoped<WarehouseProductsRepository>();
|
||||
|
||||
MapperConfiguration mappingConfig = new(mc =>
|
||||
{
|
||||
@@ -35,9 +61,15 @@ builder.Services.AddSingleton(mapper);
|
||||
WebApplication app = builder.Build();
|
||||
app.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseFastEndpoints()
|
||||
.UseFastEndpoints(options =>
|
||||
{
|
||||
options.Endpoints.ShortNames = true;
|
||||
options.Endpoints.RoutePrefix = "API";
|
||||
})
|
||||
.UseSwaggerGen();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseCors();
|
||||
|
||||
app.Run();
|
||||
5
PyroFetes/Repositories/PurchaseOrdersRepository.cs
Normal file
5
PyroFetes/Repositories/PurchaseOrdersRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class PurchaseOrdersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<PurchaseOrder>(pyrofetesContext, mapper);
|
||||
5
PyroFetes/Repositories/PurchaseProductsRepository.cs
Normal file
5
PyroFetes/Repositories/PurchaseProductsRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class PurchaseProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<PurchaseProduct>(pyrofetesContext, mapper);
|
||||
@@ -59,9 +59,9 @@ public class PyrofetesRepository<T>(DbContext databaseContext, AutoMapper.IMappe
|
||||
/// <param name="selector"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<decimal> SumAsync(
|
||||
public async Task<int> SumAsync(
|
||||
ISpecification<T> specification,
|
||||
Expression<Func<T, decimal>> selector,
|
||||
Expression<Func<T, int>> selector,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await ApplySpecification(specification).SumAsync(selector, cancellationToken);
|
||||
|
||||
5
PyroFetes/Repositories/QuotationProductsRepository.cs
Normal file
5
PyroFetes/Repositories/QuotationProductsRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class QuotationProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<QuotationProduct>(pyrofetesContext, mapper);
|
||||
5
PyroFetes/Repositories/QuotationsRepository.cs
Normal file
5
PyroFetes/Repositories/QuotationsRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class QuotationsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<Quotation>(pyrofetesContext, mapper);
|
||||
5
PyroFetes/Repositories/SettingsRepository.cs
Normal file
5
PyroFetes/Repositories/SettingsRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class SettingsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<Setting>(pyrofetesContext, mapper);
|
||||
5
PyroFetes/Repositories/UsersRepository.cs
Normal file
5
PyroFetes/Repositories/UsersRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class UsersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<User>(pyrofetesContext, mapper);
|
||||
5
PyroFetes/Repositories/WarehouseProductsRepository.cs
Normal file
5
PyroFetes/Repositories/WarehouseProductsRepository.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Repositories;
|
||||
|
||||
public class WarehouseProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<WarehouseProduct>(pyrofetesContext, mapper);
|
||||
@@ -0,0 +1,14 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
public sealed class GetPurchaseOrderByIdSpec : Specification<PurchaseOrder>
|
||||
{
|
||||
public GetPurchaseOrderByIdSpec(int purchaseOrderId)
|
||||
{
|
||||
Query
|
||||
.Include(po => po.PurchaseProducts)
|
||||
.Where(po => po.Id == purchaseOrderId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.PurchaseProducts;
|
||||
|
||||
public sealed class GetPurchaseProductByProductIdAndPurchaseOrderIdSpec : Specification<PurchaseProduct>
|
||||
{
|
||||
public GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(int productId, int purchaseOrderId)
|
||||
{
|
||||
Query
|
||||
.Where(p => p.ProductId == productId && p.PurchaseOrderId == purchaseOrderId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.QuotationProducts;
|
||||
|
||||
public sealed class GetQuotationProductByProductIdAndQuotationIdSpec : Specification<QuotationProduct>
|
||||
{
|
||||
public GetQuotationProductByProductIdAndQuotationIdSpec(int productId, int quotationId)
|
||||
{
|
||||
Query
|
||||
.Where(x => x.ProductId == productId && x.QuotationId == quotationId);
|
||||
}
|
||||
}
|
||||
14
PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs
Normal file
14
PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.Quotations;
|
||||
|
||||
public sealed class GetQuotationByIdSpec : Specification<Quotation>
|
||||
{
|
||||
public GetQuotationByIdSpec(int quotationId)
|
||||
{
|
||||
Query
|
||||
.Include(q => q.QuotationProducts)
|
||||
.Where(x => x.Id == quotationId);
|
||||
}
|
||||
}
|
||||
13
PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs
Normal file
13
PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.Settings;
|
||||
|
||||
public sealed class GetSettingByIdSpec : Specification<Setting>
|
||||
{
|
||||
public GetSettingByIdSpec(int settingId)
|
||||
{
|
||||
Query
|
||||
.Where(setting => setting.Id == settingId);
|
||||
}
|
||||
}
|
||||
13
PyroFetes/Specifications/Users/GetUserByIdSpec.cs
Normal file
13
PyroFetes/Specifications/Users/GetUserByIdSpec.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.Users;
|
||||
|
||||
public sealed class GetUserByIdSpec : Specification<User>
|
||||
{
|
||||
public GetUserByIdSpec(int userId)
|
||||
{
|
||||
Query
|
||||
.Where(x => x.Id == userId);
|
||||
}
|
||||
}
|
||||
13
PyroFetes/Specifications/Users/GetUserByNameSpec.cs
Normal file
13
PyroFetes/Specifications/Users/GetUserByNameSpec.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.Users;
|
||||
|
||||
public sealed class GetUserByNameSpec : Specification<User>
|
||||
{
|
||||
public GetUserByNameSpec(string userName)
|
||||
{
|
||||
Query
|
||||
.Where(x=> x.Name == userName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
public sealed class GetProductTotalQuantitySpec : Specification<WarehouseProduct>
|
||||
{
|
||||
public GetProductTotalQuantitySpec(int productId)
|
||||
{
|
||||
Query
|
||||
.Where(wp => wp.ProductId == productId);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Ardalis.Specification;
|
||||
using PyroFetes.Models;
|
||||
|
||||
namespace PyroFetes.Specifications.WarehouseProducts;
|
||||
|
||||
public sealed class GetWarehouseProductByProductIdSpec : Specification<WarehouseProduct>
|
||||
{
|
||||
public GetWarehouseProductByProductIdSpec(int productId)
|
||||
{
|
||||
Query
|
||||
.Where(x => x.ProductId == productId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user