25 lines
2.0 KiB
C#
25 lines
2.0 KiB
C#
using System.Data;
|
|
using System.Text.Json;
|
|
using Dapper;
|
|
using PlotLine.Services.NativeCompanion;
|
|
namespace PlotLine.Data;
|
|
public sealed class NativeImportedChapter {public Guid? DocumentGuid{get;set;}public int? ChapterStart{get;set;}public int? ChapterEnd{get;set;}public string ChapterKey{get;set;}="";public string ContentHash{get;set;}="";public int ReviewVersion{get;set;}}
|
|
public interface INativeImportRepository
|
|
{
|
|
Task<IReadOnlyList<NativeImportedChapter>> List(int user,int book);
|
|
Task<NativeImportResult?> Result(int user,Guid operation);
|
|
Task<NativeImportResult> Commit(int user,Guid operation,NativeImportPlan plan);
|
|
}
|
|
public sealed class NativeImportRepository(ISqlConnectionFactory factory):INativeImportRepository
|
|
{
|
|
public async Task<IReadOnlyList<NativeImportedChapter>> List(int user,int book){using var db=factory.CreateConnection();return (await db.QueryAsync<NativeImportedChapter>("dbo.NativeImportedCatalog",new{UserID=user,BookID=book},commandType:CommandType.StoredProcedure)).ToArray();}
|
|
public async Task<NativeImportResult?> Result(int user,Guid operation){using var db=factory.CreateConnection();return await db.QuerySingleOrDefaultAsync<NativeImportResult>("dbo.NativeReviewImport",new{Action="Result",UserID=user,OperationID=operation},commandType:CommandType.StoredProcedure);}
|
|
public async Task<NativeImportResult> Commit(int user,Guid operation,NativeImportPlan plan)
|
|
{
|
|
using var db=factory.CreateConnection();using var sets=await db.QueryMultipleAsync("dbo.NativeReviewImport",new{Action="Commit",UserID=user,OperationID=operation,BookID=plan.BookID,DocumentGuid=plan.ManuscriptID,ItemsJson=JsonSerializer.Serialize(plan.Items)},commandType:CommandType.StoredProcedure,commandTimeout:120);
|
|
// The canonical build emits its four established sets. Consume through the final
|
|
// post-commit result so a later source-save failure cannot masquerade as success.
|
|
await sets.ReadAsync();await sets.ReadAsync();await sets.ReadAsync();await sets.ReadAsync();return await sets.ReadSingleAsync<NativeImportResult>();
|
|
}
|
|
}
|