Compare commits

...

15 Commits

Author SHA1 Message Date
Cristiano
7f3ffde3ff Merge branch 'develop' 2025-11-27 14:56:14 +01:00
Cristiano
50a5f371dd Fixed Database 2025-11-27 14:35:35 +01:00
86c5d6ae7b new migration 2025-11-27 13:41:55 +01:00
1c0432a2c4 updated length of password in User.cs 2025-11-27 13:40:02 +01:00
6be43958fa updated length of password to 60 for bcrypt length 2025-11-27 13:28:05 +01:00
3e8f36457e fixed errors in database 2025-11-26 20:37:49 +01:00
5d68ee6992 fix length on approval number 2025-11-26 19:43:54 +01:00
Cristiano
d26284d552 Merge branch 'feature/repositories-refactor' into develop 2025-11-20 16:45:55 +01:00
Cristiano
d537051bea Fix Type errors 2025-11-20 16:45:44 +01:00
Cristiano
3ad506f869 Retired /api in all the endpoints 2025-11-20 16:33:56 +01:00
Cristiano
9aac7c39f2 Merge branch 'feature/repositories-refactor' into develop
# Conflicts:
#	PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs
#	PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
#	PyroFetes/Endpoints/Product/GetProductEndpoint.cs
#	PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs
#	PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs
#	PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs
#	PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs
#	PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs
#	PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs
#	PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs
#	PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs
#	PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs
#	PyroFetes/Endpoints/User/GetUserEndpoint.cs
2025-11-20 16:16:15 +01:00
Cristiano
b76b668097 Addapted to use cors and optimized connection with the frontend 2025-11-20 16:12:16 +01:00
Cristiano
669938d677 Refactored WarehouseProduct 2025-11-20 16:09:04 +01:00
Cristiano
165c9b9322 Refactored User 2025-11-20 15:38:53 +01:00
27e8fea7f3 added AllowAnonymous(); 2025-11-17 21:20:04 +01:00
75 changed files with 8286 additions and 164 deletions

View File

@@ -17,8 +17,8 @@ public class CreatePriceDto
public string? ProductReferences { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; }
public int ProductCaliber { get; set; }
public string? ProductApprovalNumber { get; set; }
public decimal ProductWeight { get; set; }
public decimal ProductNec { get; set; }
public string? ProductImage { get; set; }

View File

@@ -5,8 +5,8 @@ public class CreateProductDto
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public int Caliber { get; set; }
public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }

View File

@@ -6,8 +6,8 @@ public class UpdateProductDto
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public int Caliber { get; set; }
public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }

View File

@@ -6,8 +6,8 @@ public class GetProductDto
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public int Caliber { get; set; }
public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }

View File

@@ -12,7 +12,7 @@ public class CreateDelivererEndpoint(
{
public override void Configure()
{
Post("api/deliverers");
Post("/deliverers");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository)
{
public override void Configure()
{
Delete("api/deliverers/{@id}", x=>new {x.DelivererId});
Delete("/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous();
}

View File

@@ -10,7 +10,7 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
{
public override void Configure()
{
Get("api/deliverers");
Get("/deliverers");
AllowAnonymous();
}

View File

@@ -18,7 +18,7 @@ public class GetDelivererEndpoint(
{
public override void Configure()
{
Get("api/deliverers/{@id}", x=>new {x.DelivererId});
Get("/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class UpdateDelivererEndpoint(
{
public override void Configure()
{
Put("api/deliverers/{@id}", x=>new {x.Id});
Put("/deliverers/{@id}", x=>new {x.Id});
AllowAnonymous();
}

View File

@@ -17,7 +17,7 @@ public class CreateDeliveryNoteEndpoint(
{
public override void Configure()
{
Post("/api/DeliveryNote");
Post("/deliveryNotes");
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRep
{
public override void Configure()
{
Get("api/deliveryNotes");
Get("/deliveryNotes");
AllowAnonymous();
}

View File

@@ -16,7 +16,7 @@ public class GetDeliveryNoteEndpoint(
{
public override void Configure()
{
Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId});
Get("/deliveryNotes/{@id}", x=> new {x.DeliveryNoteId});
AllowAnonymous();
}

View File

@@ -15,7 +15,7 @@ public class PatchRealDeliveryDateEndpoint(
{
public override void Configure()
{
Patch("/api/deliveryNote/{@id}", x=> new {x.Id});
Patch("/deliveryNotes/{@id}", x=> new {x.Id});
AllowAnonymous();
}

View File

@@ -17,7 +17,7 @@ public class CreatePriceEndpoint(
{
public override void Configure()
{
Post("/api/prices");
Post("/prices");
AllowAnonymous();
}

View File

@@ -16,7 +16,7 @@ public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<D
{
public override void Configure()
{
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class PatchPriceEndpoint(
{
public override void Configure()
{
Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
Patch("/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
AllowAnonymous();
}

View File

@@ -10,7 +10,7 @@ public class GetAllProductsEndpoint(ProductsRepository productsRepository) : End
{
public override void Configure()
{
Get("/api/products");
Get("/products");
AllowAnonymous();
}

View File

@@ -18,7 +18,7 @@ public class GetProductEndpoint(
{
public override void Configure()
{
Get("/api/products/{@Id}", x => new {x.Id});
Get("/products/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class PatchProductMinimalStockEndpoint(
{
public override void Configure()
{
Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id });
Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class UpdateProductEndpoint(
{
public override void Configure()
{
Put("/api/products/{@Id}", x => new {x.Id});
Put("/products/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

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

View File

@@ -10,7 +10,7 @@ public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrders
{
public override void Configure()
{
Get("/api/purchaseOrders");
Get("/purchaseOrders");
AllowAnonymous();
}

View File

@@ -19,7 +19,7 @@ public class GetPurchaseOrderEndpoint(
{
public override void Configure()
{
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
Get("/purchaseOrders/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

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

View File

@@ -17,7 +17,7 @@ public class CreatePurchaseProductEndpoint(
{
public override void Configure()
{
Post("/api/purchaseProducts");
Post("/purchaseProducts");
AllowAnonymous();
}

View File

@@ -16,7 +16,7 @@ public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchasePr
{
public override void Configure()
{
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
AllowAnonymous();
}

View File

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

View File

@@ -17,7 +17,7 @@ public class CreateQuotationProductEndpoint(
{
public override void Configure()
{
Post("/api/quotationProduct");
Post("/quotationProducts");
AllowAnonymous();
}

View File

@@ -16,7 +16,7 @@ public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotatio
{
public override void Configure()
{
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class PatchQuotationProductQuantityEndpoint(
{
public override void Configure()
{
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous();
}

View File

@@ -17,7 +17,7 @@ public class DeleteQuotationEndpoint(
{
public override void Configure()
{
Delete("/api/quotations/{@Id}", x => new {x.Id});
Delete("/quotations/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository)
{
public override void Configure()
{
Get("/api/quotations");
Get("/quotations");
AllowAnonymous();
}

View File

@@ -19,7 +19,7 @@ public class GetQuotationEndpoint(
{
public override void Configure()
{
Get("/api/quotations/{@Id}", x => new {x.Id});
Get("/quotations/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

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

View File

@@ -12,7 +12,7 @@ public class CreateSettingEndpoint(
{
public override void Configure()
{
Post("/api/setting");
Post("/settings");
AllowAnonymous();
}

View File

@@ -15,7 +15,7 @@ public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endp
{
public override void Configure()
{
Delete("/api/setting/{@Id}", x => new {x.Id});
Delete("/settings/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -18,7 +18,7 @@ public class GetSettingEndpoint(
{
public override void Configure()
{
Get("/api/setting/{@Id}", x => new {x.Id});
Get("/settings/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class PatchSettingElectronicSignatureEndpoint(
{
public override void Configure()
{
Patch("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id});
Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class PatchSettingLogoEndpoint(
{
public override void Configure()
{
Patch("/api/setting/{@Id}/Logo", x => new {x.Id});
Patch("/settings/{@Id}/logo", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -12,7 +12,7 @@ public class CreateSupplierEndpoint(
{
public override void Configure()
{
Post("/api/suppliers");
Post("/suppliers");
AllowAnonymous();
}

View File

@@ -15,7 +15,7 @@ public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : E
{
public override void Configure()
{
Delete("/api/suppliers/{@Id}", x => new {x.Id});
Delete("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) :
{
public override void Configure()
{
Get("/api/suppliers");
Get("/suppliers");
AllowAnonymous();
}

View File

@@ -18,7 +18,7 @@ public class GetSupplierEndpoint(
{
public override void Configure()
{
Get("/api/suppliers/{@Id}", x => new {x.Id});
Get("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -8,13 +8,13 @@ using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers;
public class PatchSupplierDeleveryDelayEndpoint(
public class PatchSupplierDeliveryDelayEndpoint(
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
{
public override void Configure()
{
Patch("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id});
Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class UpdateSupplierEndpoint(
{
public override void Configure()
{
Put("/api/suppliers/{@Id}", x => new {x.Id});
Put("/suppliers/{@Id}", x => new {x.Id});
AllowAnonymous();
}

View File

@@ -4,20 +4,22 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint<ConnectUserDto, GetTokenDto>
public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<ConnectUserDto, GetTokenDto>
{
public override void Configure()
{
Post("/api/users/connect");
Post("/users/connection");
AllowAnonymous();
}
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
{
User? user = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
if (user == null)
{

View File

@@ -3,14 +3,17 @@ using PasswordGenerator;
using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Users;
public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUserDto, GetUserDto>
public class CreateUserEndpoint(
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateUserDto, GetUserDto>
{
public override void Configure()
{
Post("/api/users");
Post("/users");
AllowAnonymous();
}
@@ -27,20 +30,8 @@ public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint<CreateUs
Fonction = req.Fonction
};
database.Users.Add(user);
await usersRepository.AddAsync(user, ct);
await database.SaveChangesAsync(ct);
GetUserDto responseDto = new()
{
Id = user.Id,
Name = user.Name,
Password = user.Password,
Salt = user.Salt,
Email = user.Email,
Fonction = user.Fonction
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
}
}

View File

@@ -1,6 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
@@ -9,17 +11,17 @@ public class DeleteUserRequest
public int Id { get; set; }
}
public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUserRequest>
public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint<DeleteUserRequest>
{
public override void Configure()
{
Delete("/api/users/{@Id}", x => new {x.Id});
Delete("/users/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
{
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null)
{
@@ -27,8 +29,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint<DeleteUs
return;
}
database.Users.Remove(user);
await database.SaveChangesAsync(ct);
await usersRepository.DeleteAsync(user, ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,31 +1,20 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Users;
public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetUserDto>>
public class GetAllUsersEndpoint(UsersRepository usersRepository) : EndpointWithoutRequest<List<GetUserDto>>
{
public override void Configure()
{
Get("/api/users");
Get("/users");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetUserDto> users = await database.Users
.Select(users => new GetUserDto()
{
Id = users.Id,
Name = users.Name,
Password = users.Password,
Salt = users.Salt,
Email = users.Email,
Fonction = users.Fonction
})
.ToListAsync(ct);
await Send.OkAsync(users, ct);
await Send.OkAsync(await usersRepository.ProjectToListAsync<GetUserDto>(ct), ct);
}
}

View File

@@ -2,6 +2,8 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
@@ -10,18 +12,19 @@ public class GetUserRequest
public int Id { get; set; }
}
public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequest, GetUserDto>
public class GetUserEndpoint(
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
{
public override void Configure()
{
Get("/api/users/{@Id}", x => new {x.Id});
Get("/users/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
{
User? user = await database.Users
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null)
{
@@ -29,16 +32,6 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint<GetUserRequ
return;
}
GetUserDto responseDto = new()
{
Id = user.Id,
Name = user.Name,
Password = user.Password,
Salt = user.Salt,
Email = user.Email,
Fonction = user.Fonction
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
}
}

View File

@@ -3,20 +3,25 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint<PatchUserPasswordDto, GetUserDto>
public class PatchUserPasswordEndpoint(
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
{
public override void Configure()
{
Patch("/api/users/{@Id}/Password", x => new { x.Id });
Patch("/users/{@Id}/password", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
{
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null)
{
await Send.NotFoundAsync(ct);
@@ -24,17 +29,8 @@ public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint<P
}
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
await database.SaveChangesAsync(ct);
GetUserDto responseDto = new()
{
Id = user.Id,
Name = user.Name,
Password = user.Password,
Salt = user.Salt,
Email = user.Email,
Fonction = user.Fonction
};
await Send.OkAsync(responseDto, ct);
await usersRepository.UpdateAsync(user, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
}
}

View File

@@ -4,21 +4,25 @@ using PasswordGenerator;
using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users;
public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUserDto, GetUserDto>
public class UpdateUserEndpoint(
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateUserDto, GetUserDto>
{
public override void Configure()
{
Put("/api/users/{@Id}", x => new {x.Id});
Put("/users/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
{
User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
User? ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
if (user == null)
{
@@ -39,18 +43,9 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint<UpdateUs
user.Salt = salt;
user.Email = req.Email;
user.Fonction = req.Fonction;
await database.SaveChangesAsync(ct);
GetUserDto responseDto = new()
{
Id = user.Id,
Name = user.Name,
Password = user.Password,
Salt = user.Salt,
Email = user.Email,
Fonction = user.Fonction
};
await usersRepository.UpdateAsync(user, ct);
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
}
}

View File

@@ -2,6 +2,8 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.WareHouseProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.WarehouseProducts;
namespace PyroFetes.Endpoints.WareHouseProducts;
@@ -10,18 +12,18 @@ public class GetTotalQuantityRequest
public int ProductId { get; set; }
}
public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
public class GetTotalQuantityEndpoint(
WarehouseProductsRepository warehouseProductsRepository) : Endpoint<GetTotalQuantityRequest, GetTotalQuantityDto>
{
public override void Configure()
{
Get("/api/wareHouseProduct/{@ProductId}", x => new { x.ProductId });
Get("/wareHouseProducts/{@ProductId}", x => new { x.ProductId });
AllowAnonymous();
}
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
{
bool exists = await database.WarehouseProducts
.AnyAsync(wp => wp.ProductId == req.ProductId, ct);
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct);
if (!exists)
{
@@ -29,9 +31,9 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint<Ge
return;
}
int totalQuantity = await database.WarehouseProducts
.Where(wp => wp.ProductId == req.ProductId)
.SumAsync(wp => wp.Quantity, ct);
int totalQuantity =
await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId),
wp => wp.Quantity, ct);
GetTotalQuantityDto responseDto = new()
{

View File

@@ -6,23 +6,27 @@ using PyroFetes.Models;
namespace PyroFetes.Endpoints.WareHouseProducts;
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
{
public override void Configure()
{
Patch("/api/wareHouseProduct/{@ProductId}/{@WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId });
Patch("/wareHouseProducts/{@ProductId}/{@WareHouseId}/quantity", x => new { x.ProductId, x.WareHouseId });
AllowAnonymous();
}
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
{
WarehouseProduct? wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
WarehouseProduct? 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);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class FixTypeErrors : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(5)",
maxLength: 5,
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "Caliber",
table: "Products",
type: "int",
nullable: false,
oldClrType: typeof(decimal),
oldType: "decimal(18,2)");
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ZipCode",
table: "Suppliers",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(5)",
oldMaxLength: 5);
migrationBuilder.AlterColumn<decimal>(
name: "Caliber",
table: "Products",
type: "decimal(18,2)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<int>(
name: "ApprovalNumber",
table: "Products",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class UpdatedDatabaseProductType : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(100)",
maxLength: 100,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ApprovalNumber",
table: "Products",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(100)",
oldMaxLength: 100);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class UpdatedLengthOfPassword : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Password",
table: "Users",
type: "nvarchar(60)",
maxLength: 60,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(50)",
oldMaxLength: 50);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Password",
table: "Users",
type: "nvarchar(50)",
maxLength: 50,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(60)",
oldMaxLength: 60);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class FixZipCode : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Warehouses",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(5)",
oldMaxLength: 5);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "ZipCode",
table: "Warehouses",
type: "int",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.AlterColumn<string>(
name: "ZipCode",
table: "Suppliers",
type: "nvarchar(5)",
maxLength: 5,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
}
}

View File

@@ -503,11 +503,13 @@ namespace PyroFetes.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApprovalNumber")
.HasColumnType("int");
b.Property<string>("ApprovalNumber")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<decimal>("Caliber")
.HasColumnType("decimal(18,2)");
b.Property<int>("Caliber")
.HasColumnType("int");
b.Property<int>("ClassificationId")
.HasColumnType("int");
@@ -1113,8 +1115,9 @@ namespace PyroFetes.Migrations
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.Property<string>("ZipCode")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
@@ -1178,8 +1181,8 @@ namespace PyroFetes.Migrations
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.Property<string>("Salt")
.IsRequired()
@@ -1223,8 +1226,9 @@ namespace PyroFetes.Migrations
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");
b.Property<int>("ZipCode")
.HasColumnType("int");
b.Property<string>("ZipCode")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");

View File

@@ -8,8 +8,8 @@ namespace PyroFetes.Models
[Required, MaxLength(20)] public string? Reference { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public decimal Duration {get; set;}
[Required] public decimal Caliber { get; set; }
[Required] public int ApprovalNumber { get; set; }
[Required] public int Caliber { get; set; }
[Required, MaxLength(100)] public string? ApprovalNumber { get; set; }
[Required] public decimal Weight { get; set; }
[Required] public decimal Nec { get; set; }
[Required] public string? Image { get; set; }

View File

@@ -9,7 +9,7 @@ public class Supplier
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(30)] public string? Phone { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; }
[Required,MaxLength(5),MinLength(5)] public string? ZipCode { get; set; }
[Required,Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
[Required] public int DeliveryDelay { get; set; }

View File

@@ -6,7 +6,7 @@ public class User
{
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required, MinLength(12), MaxLength(50)] public string? Password { get; set; }
[Required, MaxLength(60)] public string? Password { get; set; }
[Required, MaxLength(100)] public string? Salt { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(100)] public string? Fonction { get; set; }

View File

@@ -10,7 +10,7 @@ public class Warehouse
[Required] public int Current {get; set;}
[Required] public int MinWeight {get; set;}
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required, Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
public List<WarehouseProduct>? WarehouseProducts { get; set; }

View File

@@ -14,7 +14,20 @@ builder.Services
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
.AddAuthorization()
.AddFastEndpoints()
.SwaggerDocument();
.SwaggerDocument(options =>
{
options.ShortSchemaNames = true;
})
.AddCors(options =>
{
options.AddDefaultPolicy(policyBuilder =>
{
policyBuilder
.WithOrigins("http://localhost:4200")
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
.AllowAnyHeader();
});
});
// On ajoute ici la configuration de la base de données
builder.Services.AddDbContext<PyroFetesDbContext>();
@@ -30,6 +43,8 @@ builder.Services.AddScoped<QuotationProductsRepository>();
builder.Services.AddScoped<QuotationsRepository>();
builder.Services.AddScoped<SuppliersRepository>();
builder.Services.AddScoped<SettingsRepository>();
builder.Services.AddScoped<UsersRepository>();
builder.Services.AddScoped<WarehouseProductsRepository>();
MapperConfiguration mappingConfig = new(mc =>
{
@@ -46,9 +61,15 @@ builder.Services.AddSingleton(mapper);
WebApplication app = builder.Build();
app.UseAuthentication()
.UseAuthorization()
.UseFastEndpoints()
.UseFastEndpoints(options =>
{
options.Endpoints.ShortNames = true;
options.Endpoints.RoutePrefix = "API";
})
.UseSwaggerGen();
app.UseHttpsRedirection();
app.UseCors();
app.Run();

View File

@@ -59,9 +59,9 @@ public class PyrofetesRepository<T>(DbContext databaseContext, AutoMapper.IMappe
/// <param name="selector"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<decimal> SumAsync(
public async Task<int> SumAsync(
ISpecification<T> specification,
Expression<Func<T, decimal>> selector,
Expression<Func<T, int>> selector,
CancellationToken cancellationToken = default)
{
return await ApplySpecification(specification).SumAsync(selector, cancellationToken);

View File

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

View File

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

View File

@@ -0,0 +1,13 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.Users;
public sealed class GetUserByIdSpec : Specification<User>
{
public GetUserByIdSpec(int userId)
{
Query
.Where(x => x.Id == userId);
}
}

View File

@@ -0,0 +1,13 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.Users;
public sealed class GetUserByNameSpec : Specification<User>
{
public GetUserByNameSpec(string userName)
{
Query
.Where(x=> x.Name == userName);
}
}

View File

@@ -0,0 +1,14 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.WarehouseProducts;
public sealed class GetProductTotalQuantitySpec : Specification<WarehouseProduct>
{
public GetProductTotalQuantitySpec(int productId)
{
Query
.Where(wp => wp.ProductId == productId);
}
}

View File

@@ -0,0 +1,13 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.WarehouseProducts;
public sealed class GetWarehouseProductByProductIdSpec : Specification<WarehouseProduct>
{
public GetWarehouseProductByProductIdSpec(int productId)
{
Query
.Where(x => x.ProductId == productId);
}
}