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.Effect.Request;
using PyroFetes.DTO.Effect.Response;
using API.DTO.Effect.Request;
using API.DTO.Effect.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Effect;
public class CreateEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateEffectDto, GetEffectDto>
public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateEffectDto, GetEffectDto>
{
public override void Configure()
{
Post("/api/effect/create");
Post("/effect/create");
AllowAnonymous();
}
@@ -19,8 +19,8 @@ public class CreateEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Cr
Label = req.Label,
};
appDbContext.Effects.Add(effect);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Effects.Add(effect);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Effect added");
GetEffectDto responseDto = new()

View File

@@ -7,17 +7,17 @@ public class DeleteEffectRequest
{
public int Id { get; set; }
}
public class DeleteEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteEffectRequest>
public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteEffectRequest>
{
public override void Configure()
{
Delete("/api/effects/{@id}", x => new { x.Id });
Delete("/effects/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
{
Models.Effect? effectToDelete = await appDbContext
Models.Effect? effectToDelete = await pyrofetesdbcontext
.Effects
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -28,8 +28,8 @@ public class DeleteEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<De
return;
}
appDbContext.Effects.Remove(effectToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Effects.Remove(effectToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

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

View File

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

View File

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