Add genre feature; extract ConfirmModal for reusable confirm dialogs

Genres seed on boot, are editable per project, and gate agent config
errors more gracefully. ConfirmModal replaces ad-hoc confirm prompts
across chapters, tags, and characters pages.
This commit is contained in:
James Wampler
2026-08-15 11:25:13 -07:00
parent ffb476a81a
commit 27c287b9c8
27 changed files with 1428 additions and 80 deletions
@@ -1,8 +1,3 @@
namespace Novelly.Api.Common;
/// <summary>
/// Thrown when the agent is asked to run but has no model credentials. This is a
/// deployment problem rather than a bad request, so the API reports it as 503 — the rest
/// of the app works fine without a key.
/// </summary>
public class AgentNotConfiguredException(string message) : Exception(message);
@@ -6,6 +6,7 @@ using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Common.Validation;
using Novelly.Api.Data;
using Novelly.Api.Genres;
using Novelly.Api.Imports;
using Novelly.Api.Projects;
using Novelly.Api.Questions;
@@ -28,6 +29,7 @@ public static class NovellyServiceRegistration
services.AddScoped<CharacterArcService>();
services.AddScoped<BeatService>();
services.AddScoped<TagService>();
services.AddScoped<GenreService>();
services.AddScoped<ChapterService>();
services.AddScoped<OpenQuestionService>();
services.AddScoped<NovelAgentToolset>();
+2
View File
@@ -3,6 +3,7 @@ using Novelly.Api.Agent;
using Novelly.Api.Beats;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Genres;
using Novelly.Api.Imports;
using Novelly.Api.Projects;
using Novelly.Api.Questions;
@@ -23,6 +24,7 @@ public interface INovelDbContext
DbSet<AgentConversation> Conversations { get; }
DbSet<AgentMessage> AgentMessages { get; }
DbSet<ImportJob> ImportJobs { get; }
DbSet<Genre> Genres { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
@@ -0,0 +1,879 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Novelly.Api.Data;
#nullable disable
namespace Novelly.Api.Data.Migrations
{
[DbContext(typeof(NovelDbContext))]
[Migration("20260813035743_AddGenres")]
partial class AddGenres
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.10");
modelBuilder.Entity("BeatCharacter", b =>
{
b.Property<Guid>("BeatsId")
.HasColumnType("TEXT");
b.Property<Guid>("CharactersId")
.HasColumnType("TEXT");
b.HasKey("BeatsId", "CharactersId");
b.HasIndex("CharactersId");
b.ToTable("BeatCharacters", (string)null);
});
modelBuilder.Entity("BeatTag", b =>
{
b.Property<Guid>("BeatsId")
.HasColumnType("TEXT");
b.Property<Guid>("TagsId")
.HasColumnType("TEXT");
b.HasKey("BeatsId", "TagsId");
b.HasIndex("TagsId");
b.ToTable("BeatTags", (string)null);
});
modelBuilder.Entity("ChapterTag", b =>
{
b.Property<Guid>("ChaptersId")
.HasColumnType("TEXT");
b.Property<Guid>("TagsId")
.HasColumnType("TEXT");
b.HasKey("ChaptersId", "TagsId");
b.HasIndex("TagsId");
b.ToTable("ChapterTags", (string)null);
});
modelBuilder.Entity("CharacterTag", b =>
{
b.Property<Guid>("CharactersId")
.HasColumnType("TEXT");
b.Property<Guid>("TagsId")
.HasColumnType("TEXT");
b.HasKey("CharactersId", "TagsId");
b.HasIndex("TagsId");
b.ToTable("CharacterTags", (string)null);
});
modelBuilder.Entity("Novelly.Api.Agent.AgentConversation", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("Conversations");
});
modelBuilder.Entity("Novelly.Api.Agent.AgentMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("ConversationId")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Role")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("TEXT");
b.Property<int>("Sequence")
.HasColumnType("INTEGER");
b.Property<string>("ToolCallsJson")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ConversationId", "Sequence")
.IsUnique();
b.ToTable("AgentMessages");
});
modelBuilder.Entity("Novelly.Api.Beats.Beat", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ChapterId")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<int>("SortOrder")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.Property<string>("WhatHappened")
.HasColumnType("TEXT");
b.Property<string>("WhatsNext")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ChapterId", "SortOrder");
b.ToTable("Beats");
});
modelBuilder.Entity("Novelly.Api.Chapters.Chapter", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Notes")
.HasColumnType("TEXT");
b.Property<int>("Number")
.HasColumnType("INTEGER");
b.Property<Guid?>("PovCharacterId")
.HasColumnType("TEXT");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<string>("Prose")
.HasColumnType("TEXT");
b.Property<string>("Setting")
.HasColumnType("TEXT");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<string>("Summary")
.HasColumnType("TEXT");
b.Property<int?>("TargetWordCount")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.Property<int>("WordCount")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("PovCharacterId");
b.HasIndex("ProjectId", "Number");
b.ToTable("Chapters");
});
modelBuilder.Entity("Novelly.Api.Characters.Character", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Age")
.HasColumnType("TEXT");
b.Property<string>("Appearance")
.HasColumnType("TEXT");
b.Property<string>("ArcSummary")
.HasColumnType("TEXT");
b.Property<string>("Backstory")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("ExternalConflict")
.HasColumnType("TEXT");
b.Property<string>("Importance")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<string>("InternalConflict")
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<string>("Need")
.HasColumnType("TEXT");
b.Property<string>("Notes")
.HasColumnType("TEXT");
b.Property<string>("Occupation")
.HasColumnType("TEXT");
b.Property<string>("Personality")
.HasColumnType("TEXT");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<string>("Pronouns")
.HasColumnType("TEXT");
b.Property<string>("Role")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Voice")
.HasColumnType("TEXT");
b.Property<string>("Want")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProjectId");
b.ToTable("Characters");
});
modelBuilder.Entity("Novelly.Api.Characters.CharacterArcStage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid?>("ChapterId")
.HasColumnType("TEXT");
b.Property<Guid>("CharacterId")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<int>("SortOrder")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ChapterId");
b.HasIndex("CharacterId", "SortOrder");
b.ToTable("CharacterArcStages");
});
modelBuilder.Entity("Novelly.Api.Characters.CharacterRelationship", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("CharacterId")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnType("TEXT");
b.Property<Guid>("RelatedCharacterId")
.HasColumnType("TEXT");
b.Property<string>("RelationshipType")
.IsRequired()
.HasMaxLength(120)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CharacterId");
b.HasIndex("RelatedCharacterId");
b.ToTable("CharacterRelationships");
});
modelBuilder.Entity("Novelly.Api.Genres.Genre", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Genres");
b.HasData(
new
{
Id = new Guid("b89aadb3-ee96-5a33-897d-94946b037f96"),
Name = "Adventure"
},
new
{
Id = new Guid("1295b746-5de1-5724-aab8-186d4220c84f"),
Name = "Contemporary Fiction"
},
new
{
Id = new Guid("786d6d01-be6c-5dff-ab53-17081d2979ed"),
Name = "Crime"
},
new
{
Id = new Guid("800eea0a-52cb-5e03-8b6f-5e1ceaec8554"),
Name = "Dystopian"
},
new
{
Id = new Guid("8dbe0291-1ab6-5045-b327-00f2025a7b0a"),
Name = "Fantasy"
},
new
{
Id = new Guid("93face5a-9a61-5d63-9a8d-7fd5d49eab7d"),
Name = "Historical Fiction"
},
new
{
Id = new Guid("4eba456f-b706-5f1f-bfc9-5d32cab0da62"),
Name = "Horror"
},
new
{
Id = new Guid("d49c5adf-3ed9-5bc9-8652-1f7a9a098ecb"),
Name = "Literary Fiction"
},
new
{
Id = new Guid("f72c6437-c8e7-519f-8d35-5aefeebbff9e"),
Name = "Magical Realism"
},
new
{
Id = new Guid("1b670010-b4cc-5b22-a879-d36eb1bf3429"),
Name = "Memoir"
},
new
{
Id = new Guid("03063bbf-de5d-5dd0-af06-0ee939de58bc"),
Name = "Middle Grade"
},
new
{
Id = new Guid("c22ed045-52e5-54b0-8cdd-cd1d6a699c19"),
Name = "Mystery"
},
new
{
Id = new Guid("abe2e8bc-a35e-5a30-a07f-7ae30a00d838"),
Name = "Non-Fiction"
},
new
{
Id = new Guid("f8543db0-c519-56a0-996a-c6028176e57e"),
Name = "Poetry"
},
new
{
Id = new Guid("b6251b9e-63a1-563f-94c0-834162fb580b"),
Name = "Romance"
},
new
{
Id = new Guid("4f188842-488e-567a-b31d-831e0c551fa5"),
Name = "Science Fiction"
},
new
{
Id = new Guid("ae67fc84-1ed9-55ae-8c9f-8a37adb52b57"),
Name = "Thriller"
},
new
{
Id = new Guid("37956a94-e9c4-5d29-abbc-f121d687f997"),
Name = "Young Adult"
});
});
modelBuilder.Entity("Novelly.Api.Imports.ImportJob", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("ChaptersCompleted")
.HasColumnType("INTEGER");
b.Property<int>("ChaptersTotal")
.HasColumnType("INTEGER");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<Guid?>("ProjectId")
.HasColumnType("TEXT");
b.Property<string>("SourceRoot")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("TEXT");
b.Property<string>("Status")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("TEXT");
b.Property<string>("StatusMessage")
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("SourceRoot");
b.ToTable("ImportJobs");
});
modelBuilder.Entity("Novelly.Api.Projects.Project", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Author")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Genre")
.HasColumnType("TEXT");
b.Property<string>("Logline")
.HasColumnType("TEXT");
b.Property<string>("Notes")
.HasColumnType("TEXT");
b.Property<string>("Phase")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("TEXT");
b.Property<string>("Synopsis")
.HasColumnType("TEXT");
b.Property<int?>("TargetWordCount")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(300)
.HasColumnType("TEXT");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Projects");
});
modelBuilder.Entity("Novelly.Api.Questions.OpenQuestion", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid?>("ChapterId")
.HasColumnType("TEXT");
b.Property<Guid?>("CharacterId")
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Detail")
.HasColumnType("TEXT");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<string>("Question")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("Resolution")
.HasColumnType("TEXT");
b.Property<long?>("ResolvedAt")
.HasColumnType("INTEGER");
b.Property<long>("UpdatedAt")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("ChapterId");
b.HasIndex("CharacterId");
b.HasIndex("ProjectId");
b.ToTable("OpenQuestions");
});
modelBuilder.Entity("Novelly.Api.Tags.Tag", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Color")
.HasMaxLength(16)
.HasColumnType("TEXT");
b.Property<long>("CreatedAt")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("TEXT");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProjectId", "Name")
.IsUnique();
b.ToTable("Tags");
});
modelBuilder.Entity("BeatCharacter", b =>
{
b.HasOne("Novelly.Api.Beats.Beat", null)
.WithMany()
.HasForeignKey("BeatsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Novelly.Api.Characters.Character", null)
.WithMany()
.HasForeignKey("CharactersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BeatTag", b =>
{
b.HasOne("Novelly.Api.Beats.Beat", null)
.WithMany()
.HasForeignKey("BeatsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Novelly.Api.Tags.Tag", null)
.WithMany()
.HasForeignKey("TagsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("ChapterTag", b =>
{
b.HasOne("Novelly.Api.Chapters.Chapter", null)
.WithMany()
.HasForeignKey("ChaptersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Novelly.Api.Tags.Tag", null)
.WithMany()
.HasForeignKey("TagsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CharacterTag", b =>
{
b.HasOne("Novelly.Api.Characters.Character", null)
.WithMany()
.HasForeignKey("CharactersId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Novelly.Api.Tags.Tag", null)
.WithMany()
.HasForeignKey("TagsId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Novelly.Api.Agent.AgentConversation", b =>
{
b.HasOne("Novelly.Api.Projects.Project", "Project")
.WithMany("Conversations")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Novelly.Api.Agent.AgentMessage", b =>
{
b.HasOne("Novelly.Api.Agent.AgentConversation", "Conversation")
.WithMany("Messages")
.HasForeignKey("ConversationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Conversation");
});
modelBuilder.Entity("Novelly.Api.Beats.Beat", b =>
{
b.HasOne("Novelly.Api.Chapters.Chapter", "Chapter")
.WithMany("Beats")
.HasForeignKey("ChapterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Chapter");
});
modelBuilder.Entity("Novelly.Api.Chapters.Chapter", b =>
{
b.HasOne("Novelly.Api.Characters.Character", "PovCharacter")
.WithMany()
.HasForeignKey("PovCharacterId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Novelly.Api.Projects.Project", "Project")
.WithMany("Chapters")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("PovCharacter");
b.Navigation("Project");
});
modelBuilder.Entity("Novelly.Api.Characters.Character", b =>
{
b.HasOne("Novelly.Api.Projects.Project", "Project")
.WithMany("Characters")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Novelly.Api.Characters.CharacterArcStage", b =>
{
b.HasOne("Novelly.Api.Chapters.Chapter", "Chapter")
.WithMany()
.HasForeignKey("ChapterId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Novelly.Api.Characters.Character", "Character")
.WithMany("ArcStages")
.HasForeignKey("CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Chapter");
b.Navigation("Character");
});
modelBuilder.Entity("Novelly.Api.Characters.CharacterRelationship", b =>
{
b.HasOne("Novelly.Api.Characters.Character", "Character")
.WithMany("Relationships")
.HasForeignKey("CharacterId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Novelly.Api.Characters.Character", "RelatedCharacter")
.WithMany()
.HasForeignKey("RelatedCharacterId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Character");
b.Navigation("RelatedCharacter");
});
modelBuilder.Entity("Novelly.Api.Questions.OpenQuestion", b =>
{
b.HasOne("Novelly.Api.Chapters.Chapter", "Chapter")
.WithMany()
.HasForeignKey("ChapterId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Novelly.Api.Characters.Character", "Character")
.WithMany()
.HasForeignKey("CharacterId")
.OnDelete(DeleteBehavior.SetNull);
b.HasOne("Novelly.Api.Projects.Project", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Chapter");
b.Navigation("Character");
b.Navigation("Project");
});
modelBuilder.Entity("Novelly.Api.Tags.Tag", b =>
{
b.HasOne("Novelly.Api.Projects.Project", "Project")
.WithMany("Tags")
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Novelly.Api.Agent.AgentConversation", b =>
{
b.Navigation("Messages");
});
modelBuilder.Entity("Novelly.Api.Chapters.Chapter", b =>
{
b.Navigation("Beats");
});
modelBuilder.Entity("Novelly.Api.Characters.Character", b =>
{
b.Navigation("ArcStages");
b.Navigation("Relationships");
});
modelBuilder.Entity("Novelly.Api.Projects.Project", b =>
{
b.Navigation("Chapters");
b.Navigation("Characters");
b.Navigation("Conversations");
b.Navigation("Tags");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,67 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Novelly.Api.Data.Migrations
{
/// <inheritdoc />
public partial class AddGenres : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Genres",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.Id);
});
migrationBuilder.InsertData(
table: "Genres",
columns: new[] { "Id", "Name" },
values: new object[,]
{
{ new Guid("03063bbf-de5d-5dd0-af06-0ee939de58bc"), "Middle Grade" },
{ new Guid("1295b746-5de1-5724-aab8-186d4220c84f"), "Contemporary Fiction" },
{ new Guid("1b670010-b4cc-5b22-a879-d36eb1bf3429"), "Memoir" },
{ new Guid("37956a94-e9c4-5d29-abbc-f121d687f997"), "Young Adult" },
{ new Guid("4eba456f-b706-5f1f-bfc9-5d32cab0da62"), "Horror" },
{ new Guid("4f188842-488e-567a-b31d-831e0c551fa5"), "Science Fiction" },
{ new Guid("786d6d01-be6c-5dff-ab53-17081d2979ed"), "Crime" },
{ new Guid("800eea0a-52cb-5e03-8b6f-5e1ceaec8554"), "Dystopian" },
{ new Guid("8dbe0291-1ab6-5045-b327-00f2025a7b0a"), "Fantasy" },
{ new Guid("93face5a-9a61-5d63-9a8d-7fd5d49eab7d"), "Historical Fiction" },
{ new Guid("abe2e8bc-a35e-5a30-a07f-7ae30a00d838"), "Non-Fiction" },
{ new Guid("ae67fc84-1ed9-55ae-8c9f-8a37adb52b57"), "Thriller" },
{ new Guid("b6251b9e-63a1-563f-94c0-834162fb580b"), "Romance" },
{ new Guid("b89aadb3-ee96-5a33-897d-94946b037f96"), "Adventure" },
{ new Guid("c22ed045-52e5-54b0-8cdd-cd1d6a699c19"), "Mystery" },
{ new Guid("d49c5adf-3ed9-5bc9-8652-1f7a9a098ecb"), "Literary Fiction" },
{ new Guid("f72c6437-c8e7-519f-8d35-5aefeebbff9e"), "Magical Realism" },
{ new Guid("f8543db0-c519-56a0-996a-c6028176e57e"), "Poetry" }
});
migrationBuilder.CreateIndex(
name: "IX_Genres_Name",
table: "Genres",
column: "Name",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Genres");
}
}
}
@@ -376,6 +376,117 @@ namespace Novelly.Api.Data.Migrations
b.ToTable("CharacterRelationships");
});
modelBuilder.Entity("Novelly.Api.Genres.Genre", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Genres");
b.HasData(
new
{
Id = new Guid("b89aadb3-ee96-5a33-897d-94946b037f96"),
Name = "Adventure"
},
new
{
Id = new Guid("1295b746-5de1-5724-aab8-186d4220c84f"),
Name = "Contemporary Fiction"
},
new
{
Id = new Guid("786d6d01-be6c-5dff-ab53-17081d2979ed"),
Name = "Crime"
},
new
{
Id = new Guid("800eea0a-52cb-5e03-8b6f-5e1ceaec8554"),
Name = "Dystopian"
},
new
{
Id = new Guid("8dbe0291-1ab6-5045-b327-00f2025a7b0a"),
Name = "Fantasy"
},
new
{
Id = new Guid("93face5a-9a61-5d63-9a8d-7fd5d49eab7d"),
Name = "Historical Fiction"
},
new
{
Id = new Guid("4eba456f-b706-5f1f-bfc9-5d32cab0da62"),
Name = "Horror"
},
new
{
Id = new Guid("d49c5adf-3ed9-5bc9-8652-1f7a9a098ecb"),
Name = "Literary Fiction"
},
new
{
Id = new Guid("f72c6437-c8e7-519f-8d35-5aefeebbff9e"),
Name = "Magical Realism"
},
new
{
Id = new Guid("1b670010-b4cc-5b22-a879-d36eb1bf3429"),
Name = "Memoir"
},
new
{
Id = new Guid("03063bbf-de5d-5dd0-af06-0ee939de58bc"),
Name = "Middle Grade"
},
new
{
Id = new Guid("c22ed045-52e5-54b0-8cdd-cd1d6a699c19"),
Name = "Mystery"
},
new
{
Id = new Guid("abe2e8bc-a35e-5a30-a07f-7ae30a00d838"),
Name = "Non-Fiction"
},
new
{
Id = new Guid("f8543db0-c519-56a0-996a-c6028176e57e"),
Name = "Poetry"
},
new
{
Id = new Guid("b6251b9e-63a1-563f-94c0-834162fb580b"),
Name = "Romance"
},
new
{
Id = new Guid("4f188842-488e-567a-b31d-831e0c551fa5"),
Name = "Science Fiction"
},
new
{
Id = new Guid("ae67fc84-1ed9-55ae-8c9f-8a37adb52b57"),
Name = "Thriller"
},
new
{
Id = new Guid("37956a94-e9c4-5d29-abbc-f121d687f997"),
Name = "Young Adult"
});
});
modelBuilder.Entity("Novelly.Api.Imports.ImportJob", b =>
{
b.Property<Guid>("Id")
+9
View File
@@ -4,6 +4,7 @@ using Novelly.Api.Agent;
using Novelly.Api.Beats;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Genres;
using Novelly.Api.Imports;
using Novelly.Api.Projects;
using Novelly.Api.Questions;
@@ -30,6 +31,7 @@ public class NovelDbContext(DbContextOptions<NovelDbContext> options)
public DbSet<AgentConversation> Conversations => Set<AgentConversation>();
public DbSet<AgentMessage> AgentMessages => Set<AgentMessage>();
public DbSet<ImportJob> ImportJobs => Set<ImportJob>();
public DbSet<Genre> Genres => Set<Genre>();
Task<int> INovelDbContext.SaveChangesAsync(CancellationToken cancellationToken) =>
base.SaveChangesAsync(cancellationToken);
@@ -150,6 +152,13 @@ public class NovelDbContext(DbContextOptions<NovelDbContext> options)
entity.HasIndex(m => new { m.ConversationId, m.Sequence }).IsUnique();
});
builder.Entity<Genre>(entity =>
{
entity.Property(g => g.Name).IsRequired().HasMaxLength(100);
entity.HasIndex(g => g.Name).IsUnique();
entity.HasData(SeededGenres.All);
});
builder.Entity<ImportJob>(entity =>
{
entity.Property(j => j.SourceRoot).IsRequired().HasMaxLength(1000);
+8
View File
@@ -0,0 +1,8 @@
namespace Novelly.Api.Genres;
public class Genre
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; } = string.Empty;
}
+8
View File
@@ -0,0 +1,8 @@
namespace Novelly.Api.Genres;
public record GenreResponse(Guid Id, string Name);
public static class GenreMapping
{
public static GenreResponse ToResponse(this Genre g) => new(g.Id, g.Name);
}
+18
View File
@@ -0,0 +1,18 @@
using Novelly.Api.Common;
namespace Novelly.Api.Genres;
public static class GenreEndpoints
{
public static IEndpointRouteBuilder MapGenreEndpoints(this IEndpointRouteBuilder app)
{
var genres = app.MapGroup("/api/genres").WithTags("Genres")
.AddEndpointFilter<RequestLoggingEndpointFilter>();
genres.MapGet("/", async (GenreService service, CancellationToken ct) =>
Results.Ok(await service.ListAsync(ct)))
.WithSummary("List the suggested genres a novel can be filed under.");
return app;
}
}
+17
View File
@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using Novelly.Api.Data;
namespace Novelly.Api.Genres;
public class GenreService(INovelDbContext db, ILogger<GenreService> logger)
{
public async Task<IReadOnlyList<GenreResponse>> ListAsync(CancellationToken ct = default)
{
logger.LogInformation("Listing genres");
return await db.Genres
.OrderBy(g => g.Name)
.Select(g => new GenreResponse(g.Id, g.Name))
.ToListAsync(ct);
}
}
+26
View File
@@ -0,0 +1,26 @@
namespace Novelly.Api.Genres;
public static class SeededGenres
{
public static IReadOnlyList<Genre> All { get; } =
[
new Genre { Id = new Guid("b89aadb3-ee96-5a33-897d-94946b037f96"), Name = "Adventure" },
new Genre { Id = new Guid("1295b746-5de1-5724-aab8-186d4220c84f"), Name = "Contemporary Fiction" },
new Genre { Id = new Guid("786d6d01-be6c-5dff-ab53-17081d2979ed"), Name = "Crime" },
new Genre { Id = new Guid("800eea0a-52cb-5e03-8b6f-5e1ceaec8554"), Name = "Dystopian" },
new Genre { Id = new Guid("8dbe0291-1ab6-5045-b327-00f2025a7b0a"), Name = "Fantasy" },
new Genre { Id = new Guid("93face5a-9a61-5d63-9a8d-7fd5d49eab7d"), Name = "Historical Fiction" },
new Genre { Id = new Guid("4eba456f-b706-5f1f-bfc9-5d32cab0da62"), Name = "Horror" },
new Genre { Id = new Guid("d49c5adf-3ed9-5bc9-8652-1f7a9a098ecb"), Name = "Literary Fiction" },
new Genre { Id = new Guid("f72c6437-c8e7-519f-8d35-5aefeebbff9e"), Name = "Magical Realism" },
new Genre { Id = new Guid("1b670010-b4cc-5b22-a879-d36eb1bf3429"), Name = "Memoir" },
new Genre { Id = new Guid("03063bbf-de5d-5dd0-af06-0ee939de58bc"), Name = "Middle Grade" },
new Genre { Id = new Guid("c22ed045-52e5-54b0-8cdd-cd1d6a699c19"), Name = "Mystery" },
new Genre { Id = new Guid("abe2e8bc-a35e-5a30-a07f-7ae30a00d838"), Name = "Non-Fiction" },
new Genre { Id = new Guid("f8543db0-c519-56a0-996a-c6028176e57e"), Name = "Poetry" },
new Genre { Id = new Guid("b6251b9e-63a1-563f-94c0-834162fb580b"), Name = "Romance" },
new Genre { Id = new Guid("4f188842-488e-567a-b31d-831e0c551fa5"), Name = "Science Fiction" },
new Genre { Id = new Guid("ae67fc84-1ed9-55ae-8c9f-8a37adb52b57"), Name = "Thriller" },
new Genre { Id = new Guid("37956a94-e9c4-5d29-abbc-f121d687f997"), Name = "Young Adult" }
];
}
+2
View File
@@ -7,6 +7,7 @@ using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Common;
using Novelly.Api.Data;
using Novelly.Api.Genres;
using Novelly.Api.Imports;
using Novelly.Api.Projects;
using Novelly.Api.Questions;
@@ -86,6 +87,7 @@ app.MapProjectEndpoints()
.MapChapterEndpoints()
.MapBeatEndpoints()
.MapTagEndpoints()
.MapGenreEndpoints()
.MapOpenQuestionEndpoints()
.MapAgentEndpoints()
.MapImportEndpoints();