using System.Data; using Dapper; using PlotLine.Models; namespace PlotLine.Data; public interface IProjectRestorePointRepository { Task> ListAsync(int projectId); Task GetAsync(int projectRestorePointId, int projectId); Task CreateAsync(int projectId, string restorePointName, string restorePointType, string jsonData, string? notes); } public sealed class ProjectRestorePointRepository(ISqlConnectionFactory connectionFactory) : IProjectRestorePointRepository { public async Task> ListAsync(int projectId) { using var connection = connectionFactory.CreateConnection(); var rows = await connection.QueryAsync( "dbo.ProjectRestorePoint_List", new { ProjectID = projectId }, commandType: CommandType.StoredProcedure); return rows.ToList(); } public async Task GetAsync(int projectRestorePointId, int projectId) { using var connection = connectionFactory.CreateConnection(); return await connection.QuerySingleOrDefaultAsync( "dbo.ProjectRestorePoint_Get", new { ProjectRestorePointID = projectRestorePointId, ProjectID = projectId }, commandType: CommandType.StoredProcedure); } public async Task CreateAsync(int projectId, string restorePointName, string restorePointType, string jsonData, string? notes) { using var connection = connectionFactory.CreateConnection(); return await connection.QuerySingleAsync( "dbo.ProjectRestorePoint_Create", new { ProjectID = projectId, RestorePointName = restorePointName, RestorePointType = restorePointType, JsonData = jsonData, Notes = notes }, commandType: CommandType.StoredProcedure); } }