PlotDirector/PlotLine/Data/IntentAssessmentRepository.cs

17 lines
1.3 KiB
C#

using System.Data;
using Dapper;
using PlotLine.Services;
namespace PlotLine.Data;
public interface IIntentAssessmentRepository
{
Task<IntentAssessment?> Read(int user,int scene,string? hash=null);
Task Save(int user,int scene,string hash,string json,string model);
Task Decide(int user,int scene,string hash,string key,string decision);
}
public sealed class IntentAssessmentRepository(ISqlConnectionFactory factory):IIntentAssessmentRepository
{
public async Task<IntentAssessment?> Read(int user,int scene,string? hash=null){using var db=factory.CreateConnection();return await db.QuerySingleOrDefaultAsync<IntentAssessment>("dbo.WritingIntentAssessment",new{Action="Read",UserID=user,SceneID=scene,InputHash=hash},commandType:CommandType.StoredProcedure);}
public async Task Save(int user,int scene,string hash,string json,string model){using var db=factory.CreateConnection();await db.ExecuteAsync("dbo.WritingIntentAssessment",new{Action="Save",UserID=user,SceneID=scene,InputHash=hash,ResultsJson=json,Model=model},commandType:CommandType.StoredProcedure);}
public async Task Decide(int user,int scene,string hash,string key,string decision){using var db=factory.CreateConnection();await db.ExecuteAsync("dbo.WritingIntentAssessment",new{Action="Decide",UserID=user,SceneID=scene,InputHash=hash,Key=key,Decision=decision},commandType:CommandType.StoredProcedure);}
}