Finalisation endpoints
This commit is contained in:
34
PyroFetes/Endpoints/Sound/GetAllSoundsEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Sound/GetAllSoundsEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user