Three things the outline could not express before:
Main vs supporting. A new CharacterImportance sits alongside CharacterRole
rather than inside it — role is the part a character plays (protagonist,
mentor, foil), importance is how much of the book they carry, and a mentor can
be either. Characters start Supporting and get promoted. Listings put main
characters first.
Character arcs. A main character's arc is a flat ordered list of stages, the
same shape as a chapter's beats and for the same reason: an arc is a sequence
of changes, not a tree. A stage can be pinned to the chapter where it lands.
Nothing refuses an arc on a supporting character — demoting someone should not
delete their work.
Open questions. What the writer has not decided yet, hanging off a chapter
outline, a character, both, or neither. They can be resolved, reopened or
deleted, and resolving can append the decision to the notes of whatever the
question was attached to, so it lands where the writer will re-read it.
Resolved questions drop off the list unless asked for.
Also adds GET /api/characters/{id}/beats — every beat a character appears in,
in manuscript order, carrying each beat's chapter so the character page can
link straight into that chapter's outline.
Deletes are deliberately asymmetric: deleting a chapter unpins arc stages and
detaches questions rather than taking them, because a plan outlives a decision
about where the chapter break falls. Deleting a character or project does take
their arcs and questions.
All three capabilities are surfaced in the REST API, the agent toolset and the
MCP server, per the one-source-of-truth rule.
Two things worth flagging in the migration: EF's generated default for the new
Importance column was an empty string, which does not parse back to a
CharacterImportance and would have faulted every read of an existing dossier —
it now defaults to Supporting, verified by migrating a database seeded on the
old schema and reading the row back through the API. And the earlier migrations
were renamed to the namespace EF derives from the output folder, so future
`migrations add` runs stop drifting.
72 tests pass (28 new). The endpoints were also exercised over curl end to end:
arc stages resolving their chapter, a character's beats across chapters, and a
question attached to both a chapter and a character resolving into both sets of
notes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S56bfZMGe1hnhpWP4CjjNw
91 lines
4.3 KiB
C#
91 lines
4.3 KiB
C#
namespace Novelly.Api.Characters;
|
|
|
|
public static class CharacterEndpoints
|
|
{
|
|
public static IEndpointRouteBuilder MapCharacterEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var projectScoped = app.MapGroup("/api/projects/{projectId:guid}/characters").WithTags("Characters");
|
|
|
|
projectScoped.MapGet("/", async (Guid projectId, CharacterService service, CancellationToken ct) =>
|
|
Results.Ok(await service.ListAsync(projectId, ct)))
|
|
.WithSummary("List a project's character dossiers.");
|
|
|
|
projectScoped.MapPost("/", async (
|
|
Guid projectId, CreateCharacterRequest request, CharacterService service, CancellationToken ct) =>
|
|
{
|
|
var created = await service.CreateAsync(projectId, request, ct);
|
|
return Results.Created($"/api/characters/{created.Id}", created);
|
|
})
|
|
.WithSummary("Add a character dossier.");
|
|
|
|
var characters = app.MapGroup("/api/characters").WithTags("Characters");
|
|
|
|
characters.MapGet("/{id:guid}", async (Guid id, CharacterService service, CancellationToken ct) =>
|
|
Results.Ok(await service.GetAsync(id, ct)))
|
|
.WithSummary("Read a character dossier.");
|
|
|
|
characters.MapPatch("/{id:guid}", async (
|
|
Guid id, UpdateCharacterRequest request, CharacterService service, CancellationToken ct) =>
|
|
Results.Ok(await service.UpdateAsync(id, request, ct)))
|
|
.WithSummary("Update a character dossier.");
|
|
|
|
characters.MapDelete("/{id:guid}", async (Guid id, CharacterService service, CancellationToken ct) =>
|
|
{
|
|
await service.DeleteAsync(id, ct);
|
|
return Results.NoContent();
|
|
})
|
|
.WithSummary("Delete a character.");
|
|
|
|
characters.MapPost("/{id:guid}/relationships", async (
|
|
Guid id, CreateRelationshipRequest request, CharacterService service, CancellationToken ct) =>
|
|
Results.Ok(await service.AddRelationshipAsync(id, request, ct)))
|
|
.WithSummary("Relate this character to another in the same project.");
|
|
|
|
characters.MapDelete("/relationships/{relationshipId:guid}", async (
|
|
Guid relationshipId, CharacterService service, CancellationToken ct) =>
|
|
{
|
|
await service.RemoveRelationshipAsync(relationshipId, ct);
|
|
return Results.NoContent();
|
|
})
|
|
.WithSummary("Remove a relationship.");
|
|
|
|
characters.MapGet("/{id:guid}/arc", async (
|
|
Guid id, CharacterArcService service, CancellationToken ct) =>
|
|
Results.Ok(await service.ListAsync(id, ct)))
|
|
.WithSummary("Read a character's arc: its stages, in order.");
|
|
|
|
characters.MapPost("/{id:guid}/arc", async (
|
|
Guid id, CreateArcStageRequest request, CharacterArcService service, CancellationToken ct) =>
|
|
{
|
|
var created = await service.CreateAsync(id, request, ct);
|
|
return Results.Created($"/api/arc-stages/{created.Id}", created);
|
|
})
|
|
.WithSummary("Add a stage to a character's arc.");
|
|
|
|
characters.MapPost("/{id:guid}/arc/reorder", async (
|
|
Guid id, ReorderArcStagesRequest request, CharacterArcService service, CancellationToken ct) =>
|
|
Results.Ok(await service.ReorderAsync(id, request, ct)))
|
|
.WithSummary("Renumber a character's arc to match the order given.");
|
|
|
|
var arcStages = app.MapGroup("/api/arc-stages").WithTags("Characters");
|
|
|
|
arcStages.MapGet("/{id:guid}", async (Guid id, CharacterArcService service, CancellationToken ct) =>
|
|
Results.Ok(await service.GetAsync(id, ct)))
|
|
.WithSummary("Read one arc stage.");
|
|
|
|
arcStages.MapPatch("/{id:guid}", async (
|
|
Guid id, UpdateArcStageRequest request, CharacterArcService service, CancellationToken ct) =>
|
|
Results.Ok(await service.UpdateAsync(id, request, ct)))
|
|
.WithSummary("Update an arc stage.");
|
|
|
|
arcStages.MapDelete("/{id:guid}", async (Guid id, CharacterArcService service, CancellationToken ct) =>
|
|
{
|
|
await service.DeleteAsync(id, ct);
|
|
return Results.NoContent();
|
|
})
|
|
.WithSummary("Delete an arc stage.");
|
|
|
|
return app;
|
|
}
|
|
}
|