Files
PF3-fork/PyroFetes/Endpoints/Sound/GetAllSoundsEndpoint.cs
2025-11-13 15:11:34 +01:00

35 lines
1015 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Sound.Response;
namespace PyroFetes.Endpoints.Sound;
public class GetAllSoundsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<ReadSoundDto>>
{
public override void Configure()
{
Get("/api/sounds");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
var sounds = await pyroFetesDbContext.Sounds
.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()
})
.ToListAsync(ct);
await Send.OkAsync(sounds, ct);
}
}