rename directory

This commit is contained in:
2025-10-17 15:51:03 +01:00
parent ff590302e2
commit 59628717d4
3 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
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;
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
{
public override void Configure()
{
Post("/api/quotationProduct");
AllowAnonymous();
}
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
{
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
if (product == null)
{
await Send.NotFoundAsync(ct);
return;
}
var quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
if (quotation == null)
{
quotation = new Models.Quotation()
{
Message = req.QuotationMessage ?? "",
ConditionsSale = req.QuotationConditionsSale,
};
database.Quotations.Add(quotation);
await database.SaveChangesAsync(ct);
}
var quotationProduct = new Models.QuotationProduct()
{
ProductId = product.Id,
QuotationId = quotation.Id,
Quantity = req.Quantity
};
database.QuotationProducts.Add(quotationProduct);
await database.SaveChangesAsync(ct);
var responseDto = new GetQuotationProductDto()
{
ProductId = product.Id,
ProductReferences = product.Reference,
ProductName = product.Name,
ProductDuration = product.Duration,
ProductCaliber = product.Caliber,
ProductApprovalNumber = product.ApprovalNumber,
ProductWeight = product.Weight,
ProductNec = product.Nec,
ProductImage = product.Image,
ProductLink = product.Link,
ProductMinimalQuantity = product.MinimalQuantity,
Quantity = quotationProduct.Quantity,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
QuotationId = quotation.Id,
};
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,36 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.QuoationProduct;
public class DeleteQuotationProductRequest
{
public int ProductId { get; set; }
public int QuotationId { get; set; }
}
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
{
public override void Configure()
{
Delete("/api/quotationProduct/{ProductId}/{QuotationId}", x => new {x.ProductId, x.QuotationId});
AllowAnonymous();
}
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
{
var quotationProduct = await database.QuotationProducts
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
if (quotationProduct == null)
{
await Send.NotFoundAsync(ct);
return;
}
database.QuotationProducts.Remove(quotationProduct);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,36 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.QuoationProduct;
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
{
public override void Configure()
{
Patch("/api/quotationProduct/{ProductId}/{QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous();
}
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
{
var quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
if (quotationProduct == null)
{
await Send.NotFoundAsync(ct);
return;
}
quotationProduct.Quantity = req.Quantity;
await database.SaveChangesAsync(ct);
GetQuotationProductDto responseDto = new()
{
ProductId = quotationProduct.ProductId,
QuotationId = quotationProduct.QuotationId,
Quantity = quotationProduct.Quantity
};
await Send.OkAsync(responseDto, ct);
}
}