Endopoint presque fini
This commit is contained in:
35
PF3/Endpoints/SoundCategory/GetSoundCategoryEndpoint.cs
Normal file
35
PF3/Endpoints/SoundCategory/GetSoundCategoryEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PF3.DTO.SoundCategory.Request;
|
||||
using PF3.DTO.SoundCategory.Response;
|
||||
|
||||
namespace PF3.Endpoints.SoundCategory;
|
||||
|
||||
public class GetSoundCategoryEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdSoundCategoryDto, ReadSoundCategoryDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/soundcategorys/{Id}");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(IdSoundCategoryDto req, CancellationToken ct)
|
||||
{
|
||||
var soundCategory = await pf3DbContext.SoundsCategorys
|
||||
.Where(sc => sc.Id == req.Id)
|
||||
.Select(sc => new ReadSoundCategoryDto
|
||||
{
|
||||
Id = sc.Id,
|
||||
Name = sc.Name,
|
||||
})
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (soundCategory is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(soundCategory, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user