82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using PlotLine.Models;
|
|
|
|
namespace PlotLine.Data;
|
|
|
|
public interface IManuscriptTextStatisticsRepository
|
|
{
|
|
Task SaveAsync(int sceneId, ManuscriptTextStatistics statistics);
|
|
Task<ManuscriptTextStatistics?> GetBySceneAsync(int sceneId);
|
|
Task<IReadOnlyDictionary<int, ManuscriptTextStatistics>> ListByChapterAsync(int chapterId);
|
|
Task<SceneManuscriptSourceRecord?> GetSourceBySceneAsync(int sceneId);
|
|
}
|
|
|
|
public sealed class ManuscriptTextStatisticsRepository(ISqlConnectionFactory connectionFactory) : IManuscriptTextStatisticsRepository
|
|
{
|
|
public async Task SaveAsync(int sceneId, ManuscriptTextStatistics statistics)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
await connection.ExecuteAsync(
|
|
"dbo.SceneTextStatistics_Save",
|
|
new
|
|
{
|
|
SceneID = sceneId,
|
|
statistics.TotalWordCount,
|
|
statistics.DialogueWordCount,
|
|
statistics.ProseWordCount,
|
|
statistics.TotalParagraphCount,
|
|
statistics.DialogueParagraphCount,
|
|
statistics.ProseParagraphCount
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<ManuscriptTextStatistics?> GetBySceneAsync(int sceneId)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<ManuscriptTextStatistics>(
|
|
"dbo.SceneTextStatistics_GetByScene",
|
|
new { SceneID = sceneId },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
public async Task<IReadOnlyDictionary<int, ManuscriptTextStatistics>> ListByChapterAsync(int chapterId)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
var rows = await connection.QueryAsync<SceneTextStatisticsRow>(
|
|
"dbo.SceneTextStatistics_ListByChapter",
|
|
new { ChapterID = chapterId },
|
|
commandType: CommandType.StoredProcedure);
|
|
return rows.ToDictionary(row => row.SceneID, row => new ManuscriptTextStatistics
|
|
{
|
|
TotalWordCount = row.TotalWordCount,
|
|
DialogueWordCount = row.DialogueWordCount,
|
|
ProseWordCount = row.ProseWordCount,
|
|
TotalParagraphCount = row.TotalParagraphCount,
|
|
DialogueParagraphCount = row.DialogueParagraphCount,
|
|
ProseParagraphCount = row.ProseParagraphCount
|
|
});
|
|
}
|
|
|
|
public async Task<SceneManuscriptSourceRecord?> GetSourceBySceneAsync(int sceneId)
|
|
{
|
|
using var connection = connectionFactory.CreateConnection();
|
|
return await connection.QuerySingleOrDefaultAsync<SceneManuscriptSourceRecord>(
|
|
"dbo.SceneManuscriptSource_GetByScene",
|
|
new { SceneID = sceneId },
|
|
commandType: CommandType.StoredProcedure);
|
|
}
|
|
|
|
private sealed class SceneTextStatisticsRow
|
|
{
|
|
public int SceneID { get; init; }
|
|
public int TotalWordCount { get; init; }
|
|
public int DialogueWordCount { get; init; }
|
|
public int ProseWordCount { get; init; }
|
|
public int TotalParagraphCount { get; init; }
|
|
public int DialogueParagraphCount { get; init; }
|
|
public int ProseParagraphCount { get; init; }
|
|
}
|
|
}
|