using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Sound.Response; namespace PyroFetes.Endpoints.Sound; public class GetAllSoundsEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest> { 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); } }