Finalisation endpoints
This commit is contained in:
48
PyroFetes/Endpoints/Sound/GetSoundEndpoint.cs
Normal file
48
PyroFetes/Endpoints/Sound/GetSoundEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Sound.Request;
|
||||
using PyroFetes.DTO.Sound.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Sound;
|
||||
|
||||
public class GetSoundEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<IdSoundto, ReadSoundDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/sounds/{Id}");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(IdSoundto req, CancellationToken ct)
|
||||
{
|
||||
if (!req.Id.HasValue)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
var sound = await pyroFetesDbContext.Sounds
|
||||
.Where(s => s.Id == req.Id.Value)
|
||||
.Select(s => new ReadSoundDto
|
||||
{
|
||||
Id = s.Id,
|
||||
Name = s.Name,
|
||||
Type = s.Type,
|
||||
Artist = s.Artist,
|
||||
Duration = s.Duration != null ? s.Duration.Value.ToString() : null,
|
||||
Kind = s.Kind,
|
||||
Format = s.Format,
|
||||
CreationDate = s.CreationDate,
|
||||
SoundCategoryId = s.SoundCategoryId.ToString()
|
||||
})
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (sound is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(sound, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user