Endopoint presque fini
This commit is contained in:
37
PF3/Endpoints/SoundCategory/UpdateSoundCategoryEndpoint.cs
Normal file
37
PF3/Endpoints/SoundCategory/UpdateSoundCategoryEndpoint.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PF3.DTO.SoundCategory.Request;
|
||||
using PF3.DTO.SoundCategory.Response;
|
||||
|
||||
namespace PF3.Endpoints.SoundCategory;
|
||||
|
||||
public class UpdateSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<UpdateSoundCategoryDto, ReadSoundCategoryDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/api/soundcategorys/{Id}/name");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateSoundCategoryDto req, CancellationToken ct)
|
||||
{
|
||||
var soundCategory = await pf3DbContext.SoundsCategorys.FirstOrDefaultAsync(st => st.Id == req.Id, ct);
|
||||
if (soundCategory is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
soundCategory.Name = req.Name;
|
||||
|
||||
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