17:17 09/10

This commit is contained in:
2025-10-09 17:17:42 +02:00
parent 1734ec0219
commit 91b4aca2fa
76 changed files with 815 additions and 388 deletions

View File

@@ -1,14 +1,14 @@
using PyroFetes.DTO.Color.Request;
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Request;
using API.DTO.Color.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Color;
public class CreateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
public class CreateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateColorDto, GetColorDto>
{
public override void Configure()
{
Post("/api/color/create");
Post("/color/create");
AllowAnonymous();
}
@@ -19,8 +19,8 @@ public class CreateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Cre
Label = req.Label,
};
appDbContext.Colors.Add(color);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Colors.Add(color);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Added Color");
GetColorDto responseDto = new()

View File

@@ -8,17 +8,17 @@ public class DeleteColorRequest
public int Id { get; set; }
}
public class DeleteColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteColorRequest>
public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteColorRequest>
{
public override void Configure()
{
Delete("/api/colors/{@id}", x => new { x.Id });
Delete("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
{
Models.Color? colorToDelete = await appDbContext
Models.Color? colorToDelete = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -29,8 +29,8 @@ public class DeleteColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Del
return;
}
appDbContext.Colors.Remove(colorToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Colors.Remove(colorToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,20 +1,20 @@
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
public class GetAllColorsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetColorDto>>
{
public override void Configure()
{
Get("/api/colors");
Get("/colors");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetColorDto> responseDto = await appDbContext.Colors
List<GetColorDto> responseDto = await pyrofetesdbcontext.Colors
.Select(a => new GetColorDto
{
Id = a.Id,

View File

@@ -1,6 +1,5 @@
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
@@ -10,23 +9,23 @@ public class GetColorRequest
public int Id { get; set; }
}
public class GetColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<GetColorRequest, GetColorDto>
public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetColorRequest, GetColorDto>
{
public override void Configure()
{
Get("/api/colors/{@id}", x => new { x.Id});
Get("/colors/{@id}", x => new { x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
{
Models.Color? color = await appDbContext
Models.Color? color = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (color == null)
{
Console.WriteLine($"Aucune couleur avec l'ID {req.Id} trouvé.");
Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}

View File

@@ -1,34 +1,33 @@
using PyroFetes.DTO.Color.Request;
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Request;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
public class UpdateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateColorDto, GetColorDto>
public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateColorDto, GetColorDto>
{
public override void Configure()
{
Put("/api/colors/{@id}", x => new { x.Id });
Put("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
{
Models.Color? colorToEdit = await appDbContext
Models.Color? colorToEdit = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (colorToEdit == null)
{
Console.WriteLine($"Aucune couleur avec l'id {req.Id} trouvé.");
Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
colorToEdit.Label = req.Label;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetColorDto responseDto = new()
{