Modifs de noms et providers

This commit is contained in:
2026-06-07 19:06:45 +02:00
parent 7da7c26a2e
commit af21591669
15 changed files with 60 additions and 16 deletions
@@ -3,4 +3,5 @@ namespace PyroFetes.DTO.Provider.Request;
public class CreateProviderDto public class CreateProviderDto
{ {
public decimal Price { get; set; } public decimal Price { get; set; }
public int ProviderTypeId { get; set; }
} }
@@ -4,4 +4,6 @@ public class GetProviderDto
{ {
public int Id { get; set; } public int Id { get; set; }
public decimal Price { get; set; } public decimal Price { get; set; }
public int ProviderTypeId { get; set; }
} }
@@ -2,6 +2,10 @@ namespace PyroFetes.DTO.Staff.Request;
public class CreateStaffDto public class CreateStaffDto
{ {
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? Profession { get; set; }
public string? Email { get; set; }
public string? F4T2NumberApproval { get; set; } public string? F4T2NumberApproval { get; set; }
public DateOnly F4T2ExpirationDate { get; set; } public DateOnly F4T2ExpirationDate { get; set; }
} }
@@ -3,6 +3,10 @@ namespace PyroFetes.DTO.Staff.Response;
public class GetStaffDto public class GetStaffDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? Profession { get; set; }
public string? Email { get; set; }
public string? F4T2NumberApproval { get; set; } public string? F4T2NumberApproval { get; set; }
public DateOnly F4T2ExpirationDate { get; set; } public DateOnly F4T2ExpirationDate { get; set; }
} }
@@ -1,4 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Provider.Request; using PyroFetes.DTO.Provider.Request;
using PyroFetes.DTO.Provider.Response; using PyroFetes.DTO.Provider.Response;
@@ -8,16 +9,26 @@ public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{ {
public override void Configure() public override void Configure()
{ {
Post("/providers"); Post("/serviceproviders");
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(CreateProviderDto req, CancellationToken ct) public override async Task HandleAsync(CreateProviderDto req, CancellationToken ct)
{ {
var provider = new Models.ServiceProvider() Models.ProviderType? databaseProviderType = await pyroFetesDbContext.ProviderTypes.SingleOrDefaultAsync(x => x.Id == req.ProviderTypeId, cancellationToken: ct);
if (databaseProviderType == null)
{ {
Price = req.Price await Send.NotFoundAsync(ct);
Console.WriteLine("Customer Type not found");
return;
}
Models.ServiceProvider provider = new()
{
Price = req.Price,
ProviderTypeId = req.ProviderTypeId
}; };
pyroFetesDbContext.Add(provider); pyroFetesDbContext.Add(provider);
await pyroFetesDbContext.SaveChangesAsync(ct); await pyroFetesDbContext.SaveChangesAsync(ct);
@@ -25,7 +36,8 @@ public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
GetProviderDto response = new GetProviderDto() GetProviderDto response = new GetProviderDto()
{ {
Id = provider.Id, Id = provider.Id,
Price = provider.Price Price = provider.Price,
ProviderTypeId = provider.ProviderTypeId
}; };
await Send.OkAsync(response, ct); await Send.OkAsync(response, ct);
@@ -9,20 +9,20 @@ public class DeleteProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{ {
public override void Configure() public override void Configure()
{ {
Delete ("/providers/{@Id}", x => new { x.Id }); Delete ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct) public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct)
{ {
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.ServiceProviders.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseProvider == null) if (databaseProvider == null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
pyroFetesDbContext.Providers.Remove(databaseProvider); pyroFetesDbContext.ServiceProviders.Remove(databaseProvider);
await pyroFetesDbContext.SaveChangesAsync(ct); await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
@@ -8,18 +8,19 @@ public class GetAllProvidersEndpoint(PyroFetesDbContext pyroFetesDbContext) : En
{ {
public override void Configure() public override void Configure()
{ {
Get ("/providers"); Get ("/serviceproviders");
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
List<GetProviderDto> customer= await pyroFetesDbContext.Providers.Select(x => new GetProviderDto() List<GetProviderDto> provider= await pyroFetesDbContext.ServiceProviders.Select(x => new GetProviderDto()
{ {
Id = x.Id, Id = x.Id,
Price = x.Price, Price = x.Price,
ProviderTypeId = x.ProviderTypeId,
}).ToListAsync(ct); }).ToListAsync(ct);
await Send.OkAsync(customer, ct); await Send.OkAsync(provider, ct);
} }
} }
@@ -9,13 +9,13 @@ public class GetProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
{ {
public override void Configure() public override void Configure()
{ {
Get ("/providers/{@Id}", x => new { x.Id }); Get ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct) public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct)
{ {
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.ServiceProviders.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseProvider == null) if (databaseProvider == null)
{ {
@@ -9,13 +9,13 @@ public class UpdateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{ {
public override void Configure() public override void Configure()
{ {
Put ("/providers/{@Id}", x => new { x.Id }); Put ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateProviderDto req, CancellationToken ct) public override async Task HandleAsync(UpdateProviderDto req, CancellationToken ct)
{ {
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.ServiceProviders.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseProvider == null) if (databaseProvider == null)
{ {
@@ -8,7 +8,7 @@ public class GetAllProviderTypesEndpoint(PyroFetesDbContext pyroFetesDbContext)
{ {
public override void Configure() public override void Configure()
{ {
Get ("/providertype"); Get ("/providertypes");
AllowAnonymous(); AllowAnonymous();
} }
@@ -17,6 +17,10 @@ public class CreateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
{ {
Models.Staff staff = new() Models.Staff staff = new()
{ {
FirstName = req.FirstName,
LastName = req.LastName,
Profession = req.Profession,
Email = req.Email,
F4T2NumberApproval = req.F4T2NumberApproval, F4T2NumberApproval = req.F4T2NumberApproval,
F4T2ExpirationDate = req.F4T2ExpirationDate, F4T2ExpirationDate = req.F4T2ExpirationDate,
}; };
@@ -25,6 +29,10 @@ public class CreateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
GetStaffDto response = new() GetStaffDto response = new()
{ {
FirstName = staff.FirstName,
LastName = staff.LastName,
Profession = staff.Profession,
Email = staff.Email,
F4T2NumberApproval = staff.F4T2NumberApproval, F4T2NumberApproval = staff.F4T2NumberApproval,
F4T2ExpirationDate = staff.F4T2ExpirationDate, F4T2ExpirationDate = staff.F4T2ExpirationDate,
}; };
@@ -17,6 +17,10 @@ public class GetAllStaffsEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpo
List<GetStaffDto> staff = await pyroFetesDbContext.Staffs.Select(x => new GetStaffDto() List<GetStaffDto> staff = await pyroFetesDbContext.Staffs.Select(x => new GetStaffDto()
{ {
Id = x.Id, Id = x.Id,
FirstName = x.FirstName,
LastName = x.LastName,
Profession = x.Profession,
Email = x.Email,
F4T2NumberApproval = x.F4T2NumberApproval, F4T2NumberApproval = x.F4T2NumberApproval,
F4T2ExpirationDate = x.F4T2ExpirationDate, F4T2ExpirationDate = x.F4T2ExpirationDate,
@@ -26,6 +26,10 @@ public class GetStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint
GetStaffDto dto = new() GetStaffDto dto = new()
{ {
Id = databaseStaff.Id, Id = databaseStaff.Id,
FirstName = databaseStaff.FirstName,
LastName = databaseStaff.LastName,
Profession = databaseStaff.Profession,
Email = databaseStaff.Email,
F4T2NumberApproval = databaseStaff.F4T2NumberApproval, F4T2NumberApproval = databaseStaff.F4T2NumberApproval,
F4T2ExpirationDate = databaseStaff.F4T2ExpirationDate, F4T2ExpirationDate = databaseStaff.F4T2ExpirationDate,
}; };
@@ -32,6 +32,10 @@ public class UpdateStaffRequest(PyroFetesDbContext pyroFetesDbContext) : Endpoin
GetStaffDto dto = new() GetStaffDto dto = new()
{ {
Id = databaseStaff.Id, Id = databaseStaff.Id,
FirstName = databaseStaff.FirstName,
LastName = databaseStaff.LastName,
Profession = databaseStaff.Profession,
Email = databaseStaff.Email,
F4T2NumberApproval = req.F4T2NumberApproval, F4T2NumberApproval = req.F4T2NumberApproval,
F4T2ExpirationDate = req.F4T2ExpirationDate, F4T2ExpirationDate = req.F4T2ExpirationDate,
}; };
+1 -1
View File
@@ -28,7 +28,7 @@ public class PyroFetesDbContext : DbContext
public DbSet<ProductColor> ProductColors { get; set; } public DbSet<ProductColor> ProductColors { get; set; }
public DbSet<ProductDelivery> ProductDeliveries { get; set; } public DbSet<ProductDelivery> ProductDeliveries { get; set; }
public DbSet<ProductEffect> ProductEffects { get; set; } public DbSet<ProductEffect> ProductEffects { get; set; }
public DbSet<ServiceProvider> Providers { get; set; } public DbSet<ServiceProvider> ServiceProviders { get; set; }
public DbSet<ProviderContact> ProviderContacts { get; set; } public DbSet<ProviderContact> ProviderContacts { get; set; }
public DbSet<ProviderType> ProviderTypes { get; set; } public DbSet<ProviderType> ProviderTypes { get; set; }
public DbSet<PurchaseOrder> PurchaseOrders { get; set; } public DbSet<PurchaseOrder> PurchaseOrders { get; set; }