Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c6809b12af | |||
30b2164aa3 |
@@ -1,34 +0,0 @@
|
|||||||
using API.DTO.Effect.Request;
|
|
||||||
using API.DTO.Effect.Response;
|
|
||||||
|
|
||||||
using FastEndpoints;
|
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class CreateEffectEndpoint(AppDbContext appDbContext) : Endpoint<CreateEffectDto, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/effect/create");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect effect = new()
|
|
||||||
{
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
appDbContext.Effects.Add(effect);
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine("Effect added");
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = effect.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class DeleteEffectRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
public class DeleteEffectEndpoint(AppDbContext appDbContext) : Endpoint<DeleteEffectRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/effects/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effectToDelete = await appDbContext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effectToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun effet avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
appDbContext.Effects.Remove(effectToDelete);
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class GetAllEffectsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetEffectDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/effects");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetEffectDto> responseDto = await appDbContext.Effects
|
|
||||||
.Select(a => new GetEffectDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Label,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class GetEffectRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetEffectEndpoint(AppDbContext appDbContext) : Endpoint<GetEffectRequest, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/effect/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effect = await appDbContext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effect == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = effect.Id,
|
|
||||||
Label = effect.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Effect.Request;
|
|
||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class UpdateEffectEndpoint(AppDbContext appDbContext) : Endpoint<UpdateEffectDto, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/effect/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effectToEdit = await appDbContext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effectToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
effectToEdit.Label = req.Label;
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1 +0,0 @@
|
|||||||
dzqzq
|
|
@@ -10,9 +10,10 @@
|
|||||||
</html>
|
</html>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h2>Entreprise - Service & Solution</h2>
|
<h2>Entreprise - Services & Solutions</h2>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>© 2024-Entreprise</p>
|
<p>© 2024 - Entreprise</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
scherry-pick
|
||||||
|
Reference in New Issue
Block a user