app / src /ClipForge.Api /Endpoints /ScriptEndpoints.cs
Vanderson da Silva Quintino
Initial deploy: ClipForge video generator
8fb6238
Raw History Blame Contribute Delete
1.67 kB
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);
}