namespace Novelly.Api.Chapters; public static class ChapterEndpoints { public static IEndpointRouteBuilder MapChapterEndpoints(this IEndpointRouteBuilder app) { var projectScoped = app.MapGroup("/api/projects/{projectId:guid}/chapters").WithTags("Chapters"); projectScoped.MapGet("/", async (Guid projectId, ChapterService service, CancellationToken ct) => Results.Ok(await service.ListAsync(projectId, ct))) .WithSummary("List a project's chapters in manuscript order."); projectScoped.MapPost("/", async ( Guid projectId, CreateChapterRequest request, ChapterService service, CancellationToken ct) => { var created = await service.CreateAsync(projectId, request, ct); return Results.Created($"/api/chapters/{created.Id}", created); }) .WithSummary("Add a chapter."); var chapters = app.MapGroup("/api/chapters").WithTags("Chapters"); chapters.MapGet("/{id:guid}", async (Guid id, ChapterService service, CancellationToken ct) => Results.Ok(await service.GetAsync(id, ct))) .WithSummary("Read a chapter with all of its scenes."); chapters.MapPatch("/{id:guid}", async ( Guid id, UpdateChapterRequest request, ChapterService service, CancellationToken ct) => Results.Ok(await service.UpdateAsync(id, request, ct))) .WithSummary("Update a chapter."); chapters.MapDelete("/{id:guid}", async (Guid id, ChapterService service, CancellationToken ct) => { await service.DeleteAsync(id, ct); return Results.NoContent(); }) .WithSummary("Delete a chapter and its scenes."); return app; } }