39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.SoundTimecode.Request;
|
|
using PyroFetes.DTO.SoundTimecode.Response;
|
|
|
|
namespace PyroFetes.Endpoints.SoundTimecode;
|
|
|
|
public class CreateSoundTimecodeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateSoundTimecodeDto, ReadSoundTimecodeDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/soundtimecodes");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(CreateSoundTimecodeDto req, CancellationToken ct)
|
|
{
|
|
var soundTimecode = new PyroFetes.Models.SoundTimecode
|
|
{
|
|
ShowId = req.ShowId,
|
|
SoundId = req.SoundId,
|
|
Start = req.Start,
|
|
End = req.End
|
|
};
|
|
|
|
pyroFetesDbContext.SoundTimecodes.Add(soundTimecode);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
var result = new ReadSoundTimecodeDto
|
|
{
|
|
ShowId = soundTimecode.ShowId,
|
|
SoundId = soundTimecode.SoundId,
|
|
Start = (int)soundTimecode.Start,
|
|
End = (int)soundTimecode.End
|
|
};
|
|
|
|
await Send.OkAsync(result, ct);
|
|
}
|
|
}
|