using System.Data; using Dapper; using PlotLine.Models; namespace PlotLine.Data; public interface IStoryIntelligenceSourceRepository { Task> ListProjectsAsync(); Task> ListBooksAsync(int projectId); Task> ListChaptersAsync(int bookId); Task GetChapterSourceAsync(int chapterId); } public sealed class StoryIntelligenceSourceRepository(ISqlConnectionFactory connectionFactory) : IStoryIntelligenceSourceRepository { public async Task> ListProjectsAsync() { using var connection = connectionFactory.CreateConnection(); var rows = await connection.QueryAsync( "dbo.StoryIntelligenceSource_ProjectListAdmin", commandType: CommandType.StoredProcedure); return rows.ToList(); } public async Task> ListBooksAsync(int projectId) { using var connection = connectionFactory.CreateConnection(); var rows = await connection.QueryAsync( "dbo.StoryIntelligenceSource_BookListAdmin", new { ProjectID = projectId }, commandType: CommandType.StoredProcedure); return rows.ToList(); } public async Task> ListChaptersAsync(int bookId) { using var connection = connectionFactory.CreateConnection(); var rows = await connection.QueryAsync( "dbo.StoryIntelligenceSource_ChapterListAdmin", new { BookID = bookId }, commandType: CommandType.StoredProcedure); return rows.ToList(); } public async Task GetChapterSourceAsync(int chapterId) { using var connection = connectionFactory.CreateConnection(); return await connection.QuerySingleOrDefaultAsync( "dbo.StoryIntelligenceSource_ChapterText_GetAdmin", new { ChapterID = chapterId }, commandType: CommandType.StoredProcedure); } }