Compare commits

...

5 Commits

Author SHA1 Message Date
Cristiano
0b72549143 Refactored Program.cs 2025-11-20 15:20:13 +01:00
Cristiano
d64890dec9 Refactored Supplier 2025-11-20 15:11:14 +01:00
Cristiano
8325aa0768 Refactored Setting 2025-11-20 15:05:44 +01:00
Cristiano
ee9b4675dd Refactored Quotation 2025-11-20 14:34:09 +01:00
Cristiano
f6383265ba Refactored QuotationProduct 2025-11-20 14:20:25 +01:00
26 changed files with 208 additions and 267 deletions

View File

@@ -29,9 +29,10 @@ public class CreatePurchaseProductEndpoint(
await Send.NotFoundAsync(ct);
return;
}
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
PurchaseOrder? purchaseOrder =
await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
if (purchaseOrder == null)
{
purchaseOrder = new PurchaseOrder()
@@ -40,16 +41,16 @@ public class CreatePurchaseProductEndpoint(
};
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
}
PurchaseProduct purchaseProduct = new PurchaseProduct()
{
ProductId = product.Id,
PurchaseOrderId = purchaseOrder.Id,
Quantity = req.Quantity
};
await purchaseProductsRepository.AddAsync(purchaseProduct, ct);
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
}
}
}

View File

@@ -3,10 +3,17 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.QuotationProducts;
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
public class CreateQuotationProductEndpoint(
QuotationProductsRepository quotationProductsRepository,
ProductsRepository productsRepository,
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
{
public override void Configure()
{
@@ -16,14 +23,15 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
{
Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
if (product == null)
{
await Send.NotFoundAsync(ct);
return;
}
Quotation? quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct);
if (quotation == null)
{
@@ -32,8 +40,8 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
Message = req.QuotationMessage ?? "",
ConditionsSale = req.QuotationConditionsSale,
};
database.Quotations.Add(quotation);
await database.SaveChangesAsync(ct);
await quotationsRepository.AddAsync(quotation, ct);
}
QuotationProduct quotationProduct = new QuotationProduct()
@@ -42,28 +50,9 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
QuotationId = quotation.Id,
Quantity = req.Quantity
};
database.QuotationProducts.Add(quotationProduct);
await database.SaveChangesAsync(ct);
GetQuotationProductDto 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 quotationProductsRepository.AddAsync(quotationProduct, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
}
}

View File

@@ -1,6 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.QuotationProducts;
@@ -10,7 +12,7 @@ public class DeleteQuotationProductRequest
public int QuotationId { get; set; }
}
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
{
public override void Configure()
{
@@ -20,8 +22,9 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
{
QuotationProduct? quotationProduct = await database.QuotationProducts
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
QuotationProduct? quotationProduct =
await quotationProductsRepository.FirstOrDefaultAsync(
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
if (quotationProduct == null)
{
@@ -29,8 +32,7 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo
return;
}
database.QuotationProducts.Remove(quotationProduct);
await database.SaveChangesAsync(ct);
await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
await Send.NoContentAsync(ct);
}

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.QuotationProducts;
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
public class PatchQuotationProductQuantityEndpoint(
QuotationProductsRepository quotationProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
{
public override void Configure()
{
@@ -16,7 +20,9 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database)
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
{
QuotationProduct? quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
QuotationProduct? quotationProduct =
await quotationProductsRepository.FirstOrDefaultAsync(
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
if (quotationProduct == null)
{
await Send.NotFoundAsync(ct);
@@ -24,14 +30,8 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database)
}
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);
await quotationProductsRepository.UpdateAsync(quotationProduct, ct);
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
}
}

View File

@@ -1,6 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
@@ -9,7 +11,9 @@ public class DeleteQuotationRequest
public int Id { get; set; }
}
public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationRequest>
public class DeleteQuotationEndpoint(
QuotationsRepository quotationsRepository,
QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationRequest>
{
public override void Configure()
{
@@ -19,9 +23,7 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<Del
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await database.Quotations
.Include(q => q.QuotationProducts)
.SingleOrDefaultAsync(q => q.Id == req.Id, ct);
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation == null)
{
@@ -31,11 +33,10 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<Del
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
{
database.QuotationProducts.RemoveRange(quotation.QuotationProducts);
await quotationProductsRepository.DeleteRangeAsync(quotation.QuotationProducts, ct);
}
database.Quotations.Remove(quotation);
await database.SaveChangesAsync(ct);
await quotationsRepository.DeleteAsync(quotation, ct);
await Send.NoContentAsync(ct);
}

View File

@@ -3,10 +3,11 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Quotations;
public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetQuotationDto>>
public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository) : EndpointWithoutRequest<List<GetQuotationDto>>
{
public override void Configure()
{
@@ -16,35 +17,6 @@ public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWith
public override async Task HandleAsync(CancellationToken ct)
{
List<GetQuotationDto> quotations = await database.Quotations
.Include(q => q.QuotationProducts!)
.ThenInclude(qp => qp.Product)
.Select(q => new GetQuotationDto
{
Id = q.Id,
Message = q.Message,
ConditionsSale = q.ConditionsSale,
GetQuotationProductDto = q.QuotationProducts.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = q.Id,
QuotationMessage = q.Message,
QuotationConditionsSale = q.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
})
.ToListAsync(ct);
await Send.OkAsync(quotations, ct);
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(ct), ct);
}
}

View File

@@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
@@ -11,7 +13,9 @@ public class GetQuotationRequest
public int Id { get; set; }
}
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
public class GetQuotationEndpoint(
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<GetQuotationRequest, GetQuotationDto>
{
public override void Configure()
{
@@ -21,8 +25,7 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuo
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await database.Quotations
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation == null)
{
@@ -30,32 +33,6 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuo
return;
}
GetQuotationDto responseDto = new()
{
Id = quotation.Id,
Message = quotation.Message,
ConditionsSale = quotation.ConditionsSale,
GetQuotationProductDto = quotation.QuotationProducts
.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = quotation.Id,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
}
}

View File

@@ -4,10 +4,14 @@ using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
public class PatchQuotationConditionsSaleEndpoint(
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
{
public override void Configure()
{
@@ -17,7 +21,8 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) :
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
{
Quotation? quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation == null)
{
await Send.NotFoundAsync(ct);
@@ -25,32 +30,9 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) :
}
quotation.ConditionsSale = req.ConditionsSale;
await database.SaveChangesAsync(ct);
await quotationsRepository.UpdateAsync(quotation, ct);
GetQuotationDto responseDto = new()
{
Id = quotation.Id,
Message = quotation.Message,
ConditionsSale = quotation.ConditionsSale,
GetQuotationProductDto = quotation.QuotationProducts.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = quotation.Id,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
}
}

View File

@@ -2,10 +2,13 @@
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Settings;
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
public class CreateSettingEndpoint(
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateSettingDto, GetSettingDto>
{
public override void Configure()
{
@@ -21,15 +24,8 @@ public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<Creat
Logo = req.Logo
};
database.Settings.Add(setting);
await database.SaveChangesAsync(ct);
await settingsRepository.AddAsync(setting, ct);
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
}
}

View File

@@ -1,6 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings;
@@ -9,7 +11,7 @@ public class DeleteSettingRequest
public int Id { get; set; }
}
public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSettingRequest>
public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint<DeleteSettingRequest>
{
public override void Configure()
{
@@ -19,7 +21,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<Delet
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
{
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null)
{
@@ -27,8 +29,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint<Delet
return;
}
database.Settings.Remove(setting);
await database.SaveChangesAsync(ct);
await settingsRepository.DeleteAsync(setting, ct);
await Send.NoContentAsync(ct);
}

View File

@@ -2,6 +2,8 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings;
@@ -10,7 +12,9 @@ public class GetSettingRequest
public int Id { get; set; }
}
public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSettingRequest, GetSettingDto>
public class GetSettingEndpoint(
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<GetSettingRequest, GetSettingDto>
{
public override void Configure()
{
@@ -20,8 +24,7 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSetti
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
{
Setting? setting = await database.Settings
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null)
{
@@ -29,12 +32,6 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint<GetSetti
return;
}
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
}
}

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings;
public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
public class PatchSettingElectronicSignatureEndpoint(
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
{
public override void Configure()
{
@@ -16,8 +20,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
{
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null)
{
await Send.NotFoundAsync(ct);
@@ -25,15 +29,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database
}
setting.ElectronicSignature = req.ElectronicSignature;
await database.SaveChangesAsync(ct);
await settingsRepository.UpdateAsync(setting, ct);
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
}
}

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings;
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
public class PatchSettingLogoEndpoint(
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
{
public override void Configure()
{
@@ -16,7 +20,7 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<Pa
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
{
Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null)
{
@@ -25,15 +29,8 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<Pa
}
setting.Logo = req.Logo;
await database.SaveChangesAsync(ct);
GetSettingDto responseDto = new()
{
Id = setting.Id,
ElectronicSignature = setting.ElectronicSignature,
Logo = setting.Logo
};
await settingsRepository.UpdateAsync(setting, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
}
}

View File

@@ -2,10 +2,13 @@
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Suppliers;
public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<CreateSupplierDto, GetSupplierDto>
public class CreateSupplierEndpoint(
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
@@ -26,20 +29,8 @@ public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Crea
DeliveryDelay = req.DeliveryDelay
};
database.Suppliers.Add(supplier);
await database.SaveChangesAsync(ct);
await suppliersRepository.AddAsync(supplier, ct);
GetSupplierDto responseDto = new()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
}
}

View File

@@ -1,6 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers;
@@ -9,7 +11,7 @@ public class DeleteSupplierRequest
public int Id { get; set; }
}
public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSupplierRequest>
public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : Endpoint<DeleteSupplierRequest>
{
public override void Configure()
{
@@ -19,7 +21,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Dele
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
{
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
if (supplier == null)
{
@@ -27,8 +29,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Dele
return;
}
database.Suppliers.Remove(supplier);
await database.SaveChangesAsync(ct);
await suppliersRepository.DeleteAsync(supplier, ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,10 +1,11 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Suppliers;
public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetSupplierDto>>
public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) : EndpointWithoutRequest<List<GetSupplierDto>>
{
public override void Configure()
{
@@ -14,19 +15,6 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWith
public override async Task HandleAsync(CancellationToken ct)
{
List<GetSupplierDto> supplier = await database.Suppliers
.Select(supplier => new GetSupplierDto()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
}).ToListAsync(ct);
await Send.OkAsync(supplier, ct);
await Send.OkAsync(await suppliersRepository.ProjectToListAsync<GetSupplierDto>(ct), ct);
}
}

View File

@@ -2,6 +2,8 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers;
@@ -10,7 +12,9 @@ public class GetSupplierRequest
public int Id { get; set; }
}
public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupplierRequest, GetSupplierDto>
public class GetSupplierEndpoint(
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
{
public override void Configure()
{
@@ -20,8 +24,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupp
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
{
Supplier? supplier = await database.Suppliers
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
if (supplier == null)
{
@@ -29,17 +32,6 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint<GetSupp
return;
}
GetSupplierDto responseDto = new()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
}
}

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers;
public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
public class PatchSupplierDeleveryDelayEndpoint(
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
{
public override void Configure()
{
@@ -16,7 +20,7 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct)
{
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
if (supplier == null)
{
@@ -25,14 +29,8 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E
}
supplier.DeliveryDelay = req.DeliveryDelay;
await database.SaveChangesAsync(ct);
GetSupplierDto responseDto = new()
{
Id = supplier.Id,
DeliveryDelay = supplier.DeliveryDelay,
};
await suppliersRepository.UpdateAsync(supplier, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
}
}

View File

@@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers;
public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<UpdateSupplierDto, GetSupplierDto>
public class UpdateSupplierEndpoint(
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
@@ -16,7 +20,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Upda
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
{
Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
if (supplier == null)
{
@@ -31,20 +35,9 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<Upda
supplier.City = req.City;
supplier.ZipCode = req.ZipCode;
supplier.DeliveryDelay = req.DeliveryDelay;
await database.SaveChangesAsync(ct);
GetSupplierDto responseDto = new()
{
Id = supplier.Id,
Name = supplier.Name,
Email = supplier.Email,
Phone = supplier.Phone,
Address = supplier.Address,
City = supplier.City,
ZipCode = supplier.ZipCode,
DeliveryDelay = supplier.DeliveryDelay
};
await suppliersRepository.UpdateAsync(supplier, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
}
}

View File

@@ -5,7 +5,7 @@ using FastEndpoints;
using FastEndpoints.Swagger;
using FastEndpoints.Security;
using PyroFetes.MappingProfiles;
using IMapper = FastEndpoints.IMapper;
using PyroFetes.Repositories;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
@@ -19,6 +19,17 @@ builder.Services
// On ajoute ici la configuration de la base de données
builder.Services.AddDbContext<PyroFetesDbContext>();
builder.Services.AddScoped<DeliverersRepository>();
builder.Services.AddScoped<DeliveryNotesRepository>();
builder.Services.AddScoped<PricesRepository>();
builder.Services.AddScoped<ProductDeliveriesRepository>();
builder.Services.AddScoped<ProductsRepository>();
builder.Services.AddScoped<PurchaseOrdersRepository>();
builder.Services.AddScoped<PurchaseProductsRepository>();
builder.Services.AddScoped<QuotationProductsRepository>();
builder.Services.AddScoped<QuotationsRepository>();
builder.Services.AddScoped<SuppliersRepository>();
builder.Services.AddScoped<SettingsRepository>();
MapperConfiguration mappingConfig = new(mc =>
{

View File

@@ -0,0 +1,5 @@
using PyroFetes.Models;
namespace PyroFetes.Repositories;
public class QuotationProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<QuotationProduct>(pyrofetesContext, mapper);

View File

@@ -0,0 +1,5 @@
using PyroFetes.Models;
namespace PyroFetes.Repositories;
public class QuotationsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<Quotation>(pyrofetesContext, mapper);

View File

@@ -0,0 +1,5 @@
using PyroFetes.Models;
namespace PyroFetes.Repositories;
public class SettingsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository<Setting>(pyrofetesContext, mapper);

View File

@@ -0,0 +1,13 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.QuotationProducts;
public sealed class GetQuotationProductByProductIdAndQuotationIdSpec : Specification<QuotationProduct>
{
public GetQuotationProductByProductIdAndQuotationIdSpec(int productId, int quotationId)
{
Query
.Where(x => x.ProductId == productId && x.QuotationId == quotationId);
}
}

View File

@@ -0,0 +1,14 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.Quotations;
public sealed class GetQuotationByIdSpec : Specification<Quotation>
{
public GetQuotationByIdSpec(int quotationId)
{
Query
.Include(q => q.QuotationProducts)
.Where(x => x.Id == quotationId);
}
}

View File

@@ -0,0 +1,13 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.Settings;
public sealed class GetSettingByIdSpec : Specification<Setting>
{
public GetSettingByIdSpec(int settingId)
{
Query
.Where(setting => setting.Id == settingId);
}
}