Endopoint presque fini
This commit is contained in:
34
PF3/Endpoints/SoundCategory/CreateSoundCategoryEndpoint.cs
Normal file
34
PF3/Endpoints/SoundCategory/CreateSoundCategoryEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FastEndpoints;
|
||||
using PF3.DTO.SoundCategory.Request;
|
||||
using PF3.DTO.SoundCategory.Response;
|
||||
using PF3.Models;
|
||||
|
||||
namespace PF3.Endpoints.SoundCategory;
|
||||
|
||||
public class CreateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<CreateSoundCategoryDto, ReadSoundCategoryDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/soundcategorys");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSoundCategoryDto req, CancellationToken ct)
|
||||
{
|
||||
var soundCategory = new Models.SoundCategory
|
||||
{
|
||||
Name = req.Name,
|
||||
};
|
||||
|
||||
pf3DbContext.SoundsCategorys.Add(soundCategory);
|
||||
await pf3DbContext.SaveChangesAsync(ct);
|
||||
|
||||
var result = new ReadSoundCategoryDto
|
||||
{
|
||||
Id = soundCategory.Id,
|
||||
Name = soundCategory.Name
|
||||
};
|
||||
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user