forked from sanchezvem/PyroFetes
commentaire endpoint
This commit is contained in:
@@ -4,32 +4,32 @@ using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Classification;
|
||||
|
||||
public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateClassificationDto, GetClassificationDto>
|
||||
public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateClassificationDto, GetClassificationDto> //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateClassificationDto et l'élement de réponse GetClassificationDto
|
||||
{
|
||||
public override void Configure()
|
||||
public override void Configure() //Configuration de l'endpoint
|
||||
{
|
||||
Post("/api/classifications");
|
||||
AllowAnonymous();
|
||||
Post("/api/classifications"); //Créer une classification
|
||||
AllowAnonymous(); //Autorise l'accès sans authentification
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct)
|
||||
{
|
||||
|
||||
Models.Classification classification = new ()
|
||||
Models.Classification classification = new () //Création d'un label rentré par l'utilisateur
|
||||
{
|
||||
Label = req.Label
|
||||
};
|
||||
|
||||
pyrofetesdbcontext.Classifications.Add(classification);
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||
pyrofetesdbcontext.Classifications.Add(classification); //Ajout de la classification à la bdd
|
||||
await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde de la classification dans la bdd
|
||||
|
||||
Console.WriteLine("Classification créée avec succès !");
|
||||
|
||||
GetClassificationDto responseDto = new ()
|
||||
GetClassificationDto responseDto = new () //Renvoie le label de la classification
|
||||
{
|
||||
Label = req.Label
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
await Send.OkAsync(responseDto, ct); //Réponse au client
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user