132 lines
6.1 KiB
C#
132 lines
6.1 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using PlotLine.Models;
|
|
|
|
namespace PlotLine.Data;
|
|
|
|
public interface IStoryIntelligenceReviewCandidateRepository
|
|
{
|
|
Task<StoryIntelligenceReviewCandidateGeneration> BeginGenerationAsync(int projectId, int bookId, string module, string source);
|
|
Task<StoryIntelligenceReviewCandidateGeneration?> GetCurrentGenerationAsync(int bookId, string module);
|
|
Task<StoryIntelligenceReviewCandidateRow> SaveCandidateAsync(StoryIntelligenceReviewCandidateSaveRequest request);
|
|
Task SaveEvidenceAsync(int reviewCandidateId, int? sceneId, string evidenceText, decimal? confidence, int sortOrder);
|
|
Task<StoryIntelligenceReviewCandidateGeneration?> CompleteGenerationAsync(int generationId);
|
|
Task FailGenerationAsync(int generationId, string errorMessage);
|
|
Task<IReadOnlyList<StoryIntelligenceReviewCandidateRow>> ListPageAsync(int bookId, string module, int pageNumber, int pageSize);
|
|
Task<StoryIntelligenceReviewCandidateGeneration?> MarkReviewedAsync(StoryIntelligenceReviewCandidateDecisionRequest request);
|
|
Task ResetBookAsync(int bookId);
|
|
}
|
|
|
|
public sealed class StoryIntelligenceReviewCandidateRepository(ISqlConnectionFactory connectionFactory) : IStoryIntelligenceReviewCandidateRepository
|
|
{
|
|
public async Task<StoryIntelligenceReviewCandidateGeneration> BeginGenerationAsync(int projectId, int bookId, string module, string source)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleAsync<StoryIntelligenceReviewCandidateGeneration>(
|
|
"dbo.StoryIntelligenceReviewCandidateGeneration_Begin",
|
|
new { ProjectID = projectId, BookID = bookId, Module = module, Source = source },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<StoryIntelligenceReviewCandidateGeneration?> GetCurrentGenerationAsync(int bookId, string module)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<StoryIntelligenceReviewCandidateGeneration>(
|
|
"dbo.StoryIntelligenceReviewCandidateGeneration_GetCurrent",
|
|
new { BookID = bookId, Module = module },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<StoryIntelligenceReviewCandidateRow> SaveCandidateAsync(StoryIntelligenceReviewCandidateSaveRequest request)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleAsync<StoryIntelligenceReviewCandidateRow>(
|
|
"dbo.StoryIntelligenceReviewCandidate_Save",
|
|
new
|
|
{
|
|
request.ReviewCandidateGenerationID,
|
|
request.ProjectID,
|
|
request.BookID,
|
|
request.Module,
|
|
request.StableKey,
|
|
request.CandidateType,
|
|
request.DisplayName,
|
|
request.SortOrder,
|
|
request.Confidence,
|
|
request.ExistingCanonicalID,
|
|
request.CandidatePayloadJson
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task SaveEvidenceAsync(int reviewCandidateId, int? sceneId, string evidenceText, decimal? confidence, int sortOrder)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
await connection.ExecuteAsync(
|
|
"dbo.StoryIntelligenceReviewCandidateEvidence_Save",
|
|
new
|
|
{
|
|
ReviewCandidateID = reviewCandidateId,
|
|
SceneID = sceneId,
|
|
EvidenceText = evidenceText,
|
|
Confidence = confidence,
|
|
SortOrder = sortOrder
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<StoryIntelligenceReviewCandidateGeneration?> CompleteGenerationAsync(int generationId)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<StoryIntelligenceReviewCandidateGeneration>(
|
|
"dbo.StoryIntelligenceReviewCandidateGeneration_Complete",
|
|
new { ReviewCandidateGenerationID = generationId },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task FailGenerationAsync(int generationId, string errorMessage)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
await connection.ExecuteAsync(
|
|
"dbo.StoryIntelligenceReviewCandidateGeneration_Fail",
|
|
new { ReviewCandidateGenerationID = generationId, ErrorMessage = errorMessage },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<IReadOnlyList<StoryIntelligenceReviewCandidateRow>> ListPageAsync(int bookId, string module, int pageNumber, int pageSize)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
var rows = await connection.QueryAsync<StoryIntelligenceReviewCandidateRow>(
|
|
"dbo.StoryIntelligenceReviewCandidate_ListPage",
|
|
new { BookID = bookId, Module = module, PageNumber = pageNumber, PageSize = pageSize },
|
|
commandType: CommandType.StoredProcedure);
|
|
return rows.ToList();
|
|
}
|
|
|
|
public async Task<StoryIntelligenceReviewCandidateGeneration?> MarkReviewedAsync(StoryIntelligenceReviewCandidateDecisionRequest request)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<StoryIntelligenceReviewCandidateGeneration>(
|
|
"dbo.StoryIntelligenceReviewCandidate_MarkReviewed",
|
|
new
|
|
{
|
|
request.BookID,
|
|
request.Module,
|
|
request.StableKey,
|
|
request.DecisionAction,
|
|
request.DecisionTargetKey,
|
|
request.DecisionCanonicalID
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task ResetBookAsync(int bookId)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
await connection.ExecuteAsync(
|
|
"dbo.StoryIntelligenceReviewCandidate_ResetBook",
|
|
new { BookID = bookId },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
}
|