editing dto from PurchaseProduct

This commit is contained in:
2025-10-16 17:24:36 +02:00
parent b79e07dd8b
commit 74b5fa6666
9 changed files with 86 additions and 17 deletions

View File

@@ -3,20 +3,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request;
public class CreatePurchaseProductDto public class CreatePurchaseProductDto
{ {
public int Quantity { get; set; } public int Quantity { get; set; }
public int ProductId { 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; }
public int PurchaseOrderId { get; set; } public int PurchaseOrderId { get; set; }
public string? PurchaseOrderPurchaseConditions { get; set; } public string? PurchaseOrderPurchaseConditions { get; set; }
} }

View File

@@ -2,9 +2,6 @@ namespace PyroFetes.DTO.PurchaseProduct.Response;
public class GetPurchaseProductDto public class GetPurchaseProductDto
{ {
public int Id { get; set; }
public int Quantity { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public int ProductReferences { get; set; } public int ProductReferences { get; set; }
public string? ProductName { get; set; } public string? ProductName { get; set; }
@@ -18,7 +15,8 @@ public class GetPurchaseProductDto
public string? ProductLink { get; set; } public string? ProductLink { get; set; }
public int ProductMinimalQuantity { get; set; } public int ProductMinimalQuantity { get; set; }
public int PurchaseOrderId { get; set; } public int PurchaseOrderId { get; set; }
public string? PurchaseOrderPurchaseConditions { get; set; } public string? PurchaseOrderPurchaseConditions { get; set; }
public int Quantity { get; set; }
} }

View File

@@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore;
using FastEndpoints;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseProduct;
public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
{
public override void Configure()
{
Post("/api/purchaseProducts");
AllowAnonymous();
}
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
{
var purchaseOrderExists = await database.PurchaseOrders.FirstOrDefaultAsync(a => a.Id == req.PurchaseOrderId, ct);
if (purchaseOrderExists == null)
{
await Send.NoContentAsync(ct);
return;
}
var purchaseProduct = new Models.PurchaseProduct()
{
ProductId = req.ProductId,
PurchaseOrderId = req.PurchaseOrderId,
Quantity = req.Quantity
};
database.PurchaseProducts.Add(purchaseProduct);
var purchaseOrder = new Models.PurchaseOrder()
{
PurchaseConditions = req.PurchaseOrderPurchaseConditions,
};
database.PurchaseOrders.Add(purchaseOrder);
await database.SaveChangesAsync(ct);
GetPurchaseProductDto responseDto = new()
{
ProductId = purchaseProduct.ProductId,
PurchaseOrderId = purchaseProduct.PurchaseOrderId,
Quantity = purchaseProduct.Quantity,
PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions,
};
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class DeletePurchaseProductEndpoint
{
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class GetAllPurchasesProductsEndpoint
{
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class GetPurchaseProductEndpoint
{
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class PatchPurchaseProductQuantityEndpoint
{
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.Endpoints.PurchaseProduct;
public class UpdatePurchaseProductEndpoint
{
}

View File

@@ -7,6 +7,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="FastEndpoints" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">