Added new endpoint to manage warehouse
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.WareHouse.Response;
|
||||||
|
|
||||||
|
public class GetWareHouseDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.WareHouse.Response;
|
||||||
|
using PyroFetes.Repositories;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints;
|
||||||
|
|
||||||
|
public class GetAllWarehouseEndpoint(WareHouseRepository wareHouseRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<List<GetWareHouseDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/wareHouses/");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
await Send.OkAsync(await wareHouseRepository.ProjectToListAsync<GetWareHouseDto>(ct), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,12 @@ using PyroFetes.DTO.WareHouseProduct.Request;
|
|||||||
using PyroFetes.DTO.WareHouseProduct.Response;
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
using PyroFetes.Models;
|
using PyroFetes.Models;
|
||||||
using PyroFetes.Repositories;
|
using PyroFetes.Repositories;
|
||||||
|
using PyroFetes.Specifications.WareHouse;
|
||||||
using PyroFetes.Specifications.WarehouseProducts;
|
using PyroFetes.Specifications.WarehouseProducts;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.WareHouseProducts;
|
namespace PyroFetes.Endpoints.WareHouseProducts;
|
||||||
|
|
||||||
public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository, WareHouseRepository wareHouseRepository , AutoMapper.IMapper mapper) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -18,16 +19,21 @@ public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository w
|
|||||||
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
WarehouseProduct? wareHouseProduct = await warehouseProductsRepository.FirstOrDefaultAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, req.WareHouseId), ct);
|
WarehouseProduct? wareHouseProduct = await warehouseProductsRepository.FirstOrDefaultAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, req.WareHouseId), ct);
|
||||||
|
Warehouse? warehouse = await wareHouseRepository.SingleOrDefaultAsync(new GetWareHouseByIdSpec(req.WareHouseId), ct);
|
||||||
|
|
||||||
if (wareHouseProduct is null)
|
if (warehouse is null)
|
||||||
{
|
{
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wareHouseProduct.Quantity = req.Quantity;
|
if (wareHouseProduct is null) await warehouseProductsRepository.AddAsync(mapper.Map<WarehouseProduct>(req), ct);
|
||||||
await warehouseProductsRepository.SaveChangesAsync(ct);
|
else
|
||||||
|
{
|
||||||
|
wareHouseProduct.Quantity = req.Quantity;
|
||||||
|
await warehouseProductsRepository.SaveChangesAsync(ct);
|
||||||
|
}
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +49,7 @@ builder.Services.AddScoped<SuppliersRepository>();
|
|||||||
builder.Services.AddScoped<SettingsRepository>();
|
builder.Services.AddScoped<SettingsRepository>();
|
||||||
builder.Services.AddScoped<UsersRepository>();
|
builder.Services.AddScoped<UsersRepository>();
|
||||||
builder.Services.AddScoped<WarehouseProductsRepository>();
|
builder.Services.AddScoped<WarehouseProductsRepository>();
|
||||||
|
builder.Services.AddScoped<WareHouseRepository>();
|
||||||
|
|
||||||
// Ajout des services
|
// Ajout des services
|
||||||
builder.Services.AddScoped<IDeliveryNotePdfService, DeliveryNotePdfService>();
|
builder.Services.AddScoped<IDeliveryNotePdfService, DeliveryNotePdfService>();
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.Repositories;
|
||||||
|
|
||||||
|
public class WareHouseRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<Warehouse>(pyrofetesContext, mapper);
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using Ardalis.Specification;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.Specifications.WareHouse;
|
||||||
|
|
||||||
|
public class GetWareHouseByIdSpec : SingleResultSpecification<Warehouse>
|
||||||
|
{
|
||||||
|
public GetWareHouseByIdSpec(int id)
|
||||||
|
{
|
||||||
|
Query
|
||||||
|
.Where(x => x.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user