Files
PF3-fork/PyroFetes/Endpoints/SoundCategory/CreateSoundCategoryEndpoint.cs
2025-11-13 15:11:12 +01:00

33 lines
930 B
C#

using FastEndpoints;
using PyroFetes.DTO.SoundCategory.Request;
using PyroFetes.DTO.SoundCategory.Response;
namespace PyroFetes.Endpoints.SoundCategory;
public class CreateSoundCategoryEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateSoundCategoryDto, ReadSoundCategoryDto>
{
public override void Configure()
{
Post("/api/soundcategorys");
AllowAnonymous();
}
public override async Task HandleAsync(CreateSoundCategoryDto req, CancellationToken ct)
{
var soundCategory = new PyroFetes.Models.SoundCategory
{
Name = req.Name,
};
pyroFetesDbContext.SoundCategories.Add(soundCategory);
await pyroFetesDbContext.SaveChangesAsync(ct);
var result = new ReadSoundCategoryDto
{
Id = soundCategory.Id,
Name = soundCategory.Name
};
await Send.OkAsync(result, ct);
}
}