Spaces:
Sleeping
Sleeping
File size: 1,669 Bytes
8fb6238 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | using ClipForge.Contracts.Requests;
using ClipForge.Contracts.Responses;
using ClipForge.Core.Interfaces;
using ClipForge.Core.Interfaces.Services;
namespace ClipForge.Api.Endpoints;
public static class ScriptEndpoints
{
public static void MapScriptEndpoints(this WebApplication app)
{
var group = app.MapGroup("/api/scripts").WithTags("Scripts");
group.MapPost("/generate", async (GenerateScriptRequest request, IScriptGenerationService service) =>
{
var script = await service.GenerateScriptAsync(request.IdeaId);
return Results.Ok(MapToResponse(script));
});
group.MapGet("/", async (IVideoScriptRepository repository) =>
{
var scripts = await repository.GetAllAsync();
return Results.Ok(scripts.Select(MapToResponse));
});
group.MapGet("/{id:guid}", async (Guid id, IVideoScriptRepository repository) =>
{
var script = await repository.GetByIdAsync(id);
return script is null ? Results.NotFound() : Results.Ok(MapToResponse(script));
});
group.MapGet("/idea/{ideaId:guid}", async (Guid ideaId, IVideoScriptRepository repository) =>
{
var script = await repository.GetByIdeaIdAsync(ideaId);
return script is null ? Results.NotFound() : Results.Ok(MapToResponse(script));
});
}
private static VideoScriptResponse MapToResponse(ClipForge.Core.Entities.VideoScript script) => new(
script.Id, script.VideoIdeaId, script.ScriptText, script.Scenes,
script.EstimatedDurationSeconds, script.Tone, script.Language, script.CreatedAt);
}
|