4 Commits

Author SHA1 Message Date
06c64a9f3f add token 2025-10-17 16:53:00 +01:00
aa1c98d649 fix error in api's route 2025-10-17 16:47:34 +01:00
fa72c6d777 creating endpoint WareHouseProduct 2025-10-17 16:23:39 +01:00
59628717d4 rename directory 2025-10-17 15:51:03 +01:00
20 changed files with 135 additions and 101 deletions

View File

@@ -0,0 +1,7 @@
namespace PyroFetes.DTO.User.Request;
public class ConnectUserDto
{
public string? Username { get; set; }
public string? Password { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.User.Response;
public class GetTokenDto
{
public string? Token { get; set; }
}

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

@@ -12,7 +12,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint
{
public override void Configure()
{
Delete("/api/purchaseOrders/{Id}", x => new {x.Id});
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext dat
{
public override void Configure()
{
Patch("/api/purchaseOrders/{Id}/PurchaseConditions", x => new { x.Id });
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint
{
public override void Configure()
{
Delete("/api/purchaseProducts/{ProductId}/{PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) :
{
public override void Configure()
{
Patch("/api/purchaseProducts/{ProductId}/{PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
AllowAnonymous();
}

View File

@@ -12,7 +12,7 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<Del
{
public override void Configure()
{
Delete("/api/quotations/{Id}", x => new {x.Id});
Delete("/api/quotations/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) :
{
public override void Configure()
{
Patch("/api/quotations/{Id}/ConditionsSale", x => new { x.Id });
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id });
AllowAnonymous();
}

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
{
@@ -13,7 +13,7 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
{
public override void Configure()
{
Delete("/api/quotationProduct/{ProductId}/{QuotationId}", x => new {x.ProductId, x.QuotationId});
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
AllowAnonymous();
}

View File

@@ -3,13 +3,13 @@ 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>
{
public override void Configure()
{
Patch("/api/quotationProduct/{ProductId}/{QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous();
}

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)
{
var 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);
}
}

View File

@@ -1,18 +1,26 @@
var builder = WebApplication.CreateBuilder(args);
using PyroFetes;
using FastEndpoints;
using FastEndpoints.Swagger;
using FastEndpoints.Security;
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
builder.Services
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
.AddAuthorization()
.AddFastEndpoints()
.SwaggerDocument();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
// On ajoute ici la configuration de la base de données
builder.Services.AddDbContext<PyroFetesDbContext>();
// On construit l'application en lui donnant vie
WebApplication app = builder.Build();
app.UseAuthentication()
.UseAuthorization()
.UseFastEndpoints()
.UseSwaggerGen();
app.UseHttpsRedirection();

View File

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