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
@@ -1,4 +1,5 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Provider.Request;
using PyroFetes.DTO.Provider.Response;
@@ -8,16 +9,26 @@ public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{
public override void Configure()
{
Post("/providers");
Post("/serviceproviders");
AllowAnonymous();
}
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);
await pyroFetesDbContext.SaveChangesAsync(ct);
@@ -25,7 +36,8 @@ public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
GetProviderDto response = new GetProviderDto()
{
Id = provider.Id,
Price = provider.Price
Price = provider.Price,
ProviderTypeId = provider.ProviderTypeId
};
await Send.OkAsync(response, ct);
@@ -9,20 +9,20 @@ public class DeleteProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{
public override void Configure()
{
Delete ("/providers/{@Id}", x => new { x.Id });
Delete ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous();
}
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)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.Providers.Remove(databaseProvider);
pyroFetesDbContext.ServiceProviders.Remove(databaseProvider);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
@@ -8,18 +8,19 @@ public class GetAllProvidersEndpoint(PyroFetesDbContext pyroFetesDbContext) : En
{
public override void Configure()
{
Get ("/providers");
Get ("/serviceproviders");
AllowAnonymous();
}
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,
Price = x.Price,
ProviderTypeId = x.ProviderTypeId,
}).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()
{
Get ("/providers/{@Id}", x => new { x.Id });
Get ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous();
}
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)
{
@@ -9,13 +9,13 @@ public class UpdateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : End
{
public override void Configure()
{
Put ("/providers/{@Id}", x => new { x.Id });
Put ("/serviceproviders/{@Id}", x => new { x.Id });
AllowAnonymous();
}
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)
{