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