44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes.DTO.SoundTimecode.Response;
|
|
|
|
namespace PyroFetes.Endpoints.SoundTimecode;
|
|
|
|
// DTO pour la route avec clé composite
|
|
public class GetSoundTimecodeRequest
|
|
{
|
|
public int ShowId { get; set; }
|
|
public int SoundId { get; set; }
|
|
}
|
|
|
|
public class GetSoundTimecodeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<GetSoundTimecodeRequest, ReadSoundTimecodeDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get("/api/soundtimecodes/{ShowId}/{SoundId}");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(GetSoundTimecodeRequest req, CancellationToken ct)
|
|
{
|
|
var soundTimecode = await pyroFetesDbContext.SoundTimecodes
|
|
.Where(st => st.ShowId == req.ShowId && st.SoundId == req.SoundId)
|
|
.Select(st => new ReadSoundTimecodeDto
|
|
{
|
|
ShowId = st.ShowId,
|
|
SoundId = st.SoundId,
|
|
Start = (int)st.Start,
|
|
End = (int)st.End
|
|
})
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
if (soundTimecode is null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
await Send.OkAsync(soundTimecode, ct);
|
|
}
|
|
}
|