1 Commits

Author SHA1 Message Date
2f3b6ef1ee Téléverser les fichiers vers "/" 2025-10-08 15:00:22 +02:00
10 changed files with 162 additions and 162 deletions

35
CreateColorEndpoint.cs Normal file
View File

@@ -0,0 +1,35 @@
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);
}
}

View File

@@ -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);
}
}

37
DeleteColorEndpoint.cs Normal file
View File

@@ -0,0 +1,37 @@
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);
}
}

View File

@@ -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);
}
}

View File

@@ -1,27 +1,26 @@
using API.DTO.Effect.Response;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace API.Endpoints.Effect;
namespace API.Endpoints.Color;
public class GetAllEffectsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetEffectDto>>
public class GetAllColorsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
{
public override void Configure()
{
Get("/effects");
Get("/colors");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetEffectDto> responseDto = await appDbContext.Effects
.Select(a => new GetEffectDto
List<GetColorDto> responseDto = await appDbContext.Colors
.Select(a => new GetColorDto
{
Id = a.Id,
Label = a.Label,
}
).ToListAsync(ct);
await Send.OkAsync(responseDto, ct);
}
}

42
GetColorEndpoint.cs Normal file
View File

@@ -0,0 +1,42 @@
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);
}
}

View File

@@ -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);
}
}

42
UpdateColorEndpoint.cs Normal file
View File

@@ -0,0 +1,42 @@
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);
}
}

View File

@@ -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);
}
}

View File

@@ -1 +0,0 @@
dzqzq