Finalisation endpoints
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace PyroFetes.Endpoints.SoundTimecode;
|
||||
|
||||
// DTO pour la route avec clé composite
|
||||
public class DeleteSoundTimecodeRequest
|
||||
{
|
||||
public int ShowId { get; set; }
|
||||
public int SoundId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSoundTimecodeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<DeleteSoundTimecodeRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/api/soundtimecodes/{ShowId}/{SoundId}");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSoundTimecodeRequest req, CancellationToken ct)
|
||||
{
|
||||
var soundTimecode = await pyroFetesDbContext.SoundTimecodes
|
||||
.FirstOrDefaultAsync(st => st.ShowId == req.ShowId && st.SoundId == req.SoundId, ct);
|
||||
|
||||
if (soundTimecode is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
pyroFetesDbContext.SoundTimecodes.Remove(soundTimecode);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SoundTimecode.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SoundTimecode;
|
||||
|
||||
public class GetAllSoundTimecodesEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<ReadSoundTimecodeDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/soundtimecodes");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var soundTimecodes = await pyroFetesDbContext.SoundTimecodes
|
||||
.Select(st => new ReadSoundTimecodeDto
|
||||
{
|
||||
ShowId = st.ShowId,
|
||||
SoundId = st.SoundId,
|
||||
Start = (int)st.Start,
|
||||
End = (int)st.End
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(soundTimecodes, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SoundTimecode.Request;
|
||||
using PyroFetes.DTO.SoundTimecode.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.SoundTimecode;
|
||||
|
||||
// DTO pour la route avec clé composite
|
||||
public class UpdateSoundTimecodeRequest
|
||||
{
|
||||
public int ShowId { get; set; }
|
||||
public int SoundId { get; set; }
|
||||
public int Start { get; set; }
|
||||
public int End { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateSoundTimecodeEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<UpdateSoundTimecodeRequest, ReadSoundTimecodeDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/api/soundtimecodes/{ShowId}/{SoundId}");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateSoundTimecodeRequest req, CancellationToken ct)
|
||||
{
|
||||
var soundTimecode = await pyroFetesDbContext.SoundTimecodes
|
||||
.FirstOrDefaultAsync(st => st.ShowId == req.ShowId && st.SoundId == req.SoundId, ct);
|
||||
|
||||
if (soundTimecode is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
soundTimecode.Start = req.Start;
|
||||
soundTimecode.End = req.End;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user