Compare commits
2 Commits
kieva-patc
...
develop
Author | SHA1 | Date | |
---|---|---|---|
c6809b12af | |||
30b2164aa3 |
@@ -1,35 +0,0 @@
|
|||||||
using API.DTO.Color.Request;
|
|
||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/color/create");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateColorDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color color = new()
|
|
||||||
{
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
appDbContext.Colors.Add(color);
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine("Added Color");
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = color.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class DeleteColorRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteColorEndpoint(AppDbContext appDbContext) : Endpoint<DeleteColorRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/colors/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? colorToDelete = await appDbContext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (colorToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune couleur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
appDbContext.Colors.Remove(colorToDelete);
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class GetAllColorsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/colors");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetColorDto> responseDto = await appDbContext.Colors
|
|
||||||
.Select(a => new GetColorDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Label,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class GetColorRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetColorEndpoint(AppDbContext appDbContext) : Endpoint<GetColorRequest, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/colors/{@id}", x => new { x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? color = await appDbContext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (color == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = color.Id,
|
|
||||||
Label = color.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Color.Request;
|
|
||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class UpdateColorEndpoint(AppDbContext appDbContext) : Endpoint<UpdateColorDto, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/colors/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? colorToEdit = await appDbContext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (colorToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
colorToEdit.Label = req.Label;
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -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