creating endpoint WareHouseProduct

This commit is contained in:
2025-10-17 16:23:39 +01:00
parent 59628717d4
commit fa72c6d777
10 changed files with 92 additions and 81 deletions

View File

@@ -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; }
}

View File

@@ -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; }
}

View File

@@ -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; }
}

View File

@@ -0,0 +1,7 @@
namespace PyroFetes.DTO.WareHouseProduct.Response;
public class GetTotalQuantityDto
{
public int ProductId { get; set; }
public int TotalQuantity { get; set; }
}

View File

@@ -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; }
}

View File

@@ -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>
{

View File

@@ -1,7 +1,7 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.QuoationProduct;
namespace PyroFetes.Endpoints.QuotationProduct;
public class DeleteQuotationProductRequest
{

View File

@@ -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>
{

View File

@@ -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);
}
}

View File

@@ -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);
}
}