creating endpoint WareHouseProduct
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class CreateWareHouseProductDto
|
||||
{
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
@@ -2,6 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class PatchWareHouseProductQuantityDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int WareHouseId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Request;
|
||||
|
||||
public class UpdateWareHouseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
public class GetTotalQuantityDto
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int TotalQuantity { get; set; }
|
||||
}
|
@@ -2,27 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
public class GetWareHouseProductDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public int WareHouseId { get; set; }
|
||||
public string? WareHouseName {get; set;}
|
||||
public int WareHouseMaxWeight {get; set;}
|
||||
public int WareHouseCurrent {get; set;}
|
||||
public int WareHouseMinWeight {get; set;}
|
||||
public string? WareHouseAddress { get; set; }
|
||||
public int WareHouseZipCode { get; set; }
|
||||
public string? WareHouseCity { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
public int ProductReferences { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public decimal ProductDuration {get; set;}
|
||||
public decimal ProductCaliber { get; set; }
|
||||
public int ProductApprovalNumber { get; set; }
|
||||
public decimal ProductWeight { get; set; }
|
||||
public decimal ProductNec { get; set; }
|
||||
public string? ProductImage { get; set; }
|
||||
public string? ProductLink { get; set; }
|
||||
public int ProductMinimalQuantity { get; set; }
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuoationProduct;
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuoationProduct;
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class DeleteQuotationProductRequest
|
||||
{
|
||||
|
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuoationProduct;
|
||||
namespace PyroFetes.Endpoints.QuotationProduct;
|
||||
|
||||
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||
{
|
||||
|
@@ -0,0 +1,42 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
||||
|
||||
public class GetTotalQuantityRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
}
|
||||
|
||||
public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/wareHouseProduct/{ProductId}", x => new { x.ProductId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
|
||||
{
|
||||
bool exists = await database.WarehouseProducts
|
||||
.AnyAsync(wp => wp.ProductId == req.ProductId, ct);
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
var totalQuantity = await database.WarehouseProducts
|
||||
.Where(wp => wp.ProductId == req.ProductId)
|
||||
.SumAsync(wp => wp.Quantity, ct);
|
||||
|
||||
GetTotalQuantityDto responseDto = new()
|
||||
{
|
||||
ProductId = req.ProductId,
|
||||
TotalQuantity = totalQuantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.WareHouseProduct;
|
||||
|
||||
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/wareHouseProduct/{ProductId}/{WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
var wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
|
||||
if (wareHouseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
wareHouseProduct.Quantity = req.Quantity;
|
||||
await database.SaveChangesAsync(ct);
|
||||
|
||||
GetWareHouseProductDto responseDto = new()
|
||||
{
|
||||
ProductId = wareHouseProduct.ProductId,
|
||||
WareHouseId = wareHouseProduct.WarehouseId,
|
||||
Quantity = wareHouseProduct.Quantity
|
||||
};
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user