diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs new file mode 100644 index 0000000..f2682db --- /dev/null +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -0,0 +1,68 @@ +using Microsoft.AspNetCore.Mvc; +using Persistence.Models; +using Persistence.Repositories; + +namespace Persistence.API.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class ChangeLogController : ControllerBase, IChangeLogApi + where TDto : class, IChangeLogAbstract, new() + where TChangeLogDto : ChangeLogDto + { + private IChangeLogRepository changeLogRepository; + + public ChangeLogController(IChangeLogRepository changeLogRepository) + { + this.changeLogRepository = changeLogRepository; + } + + [HttpGet] + public Task>> GetChangeLogCurrent(CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpGet("forDate")] + public Task>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost] + public Task> AddAsync(TDto dto, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost] + public Task> AddRangeAsync(IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost] + public Task> DeleteAsync(int id, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost] + public Task> DeleteRangeAsync(IEnumerable ids, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost("update")] + public Task> UpdateAsync(TDto dto, CancellationToken token) + { + throw new NotImplementedException(); + } + + [HttpPost("update")] + public Task> UpdateRangeAsync(IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + } +} diff --git a/Persistence.Database/Model/ChangeLog.cs b/Persistence.Database/Model/ChangeLog.cs new file mode 100644 index 0000000..1def17f --- /dev/null +++ b/Persistence.Database/Model/ChangeLog.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations.Schema; + +namespace Persistence.Database.Model +{ + public class ChangeLog : IChangeLogData + { + [Column("id")] + public int Id { get; set; } + + [Column("idnext")] + public int? IdNext { get; set; } + + [Column("idprevious")] + public int? IdPrevious { get; set; } + + [Column("creation")] + public DateTimeOffset Creation { get; set; } + + [Column("obsolete")] + public DateTimeOffset? Obsolete { get; set; } + } +} diff --git a/Persistence.Database/Model/IChangeLogData.cs b/Persistence.Database/Model/IChangeLogData.cs new file mode 100644 index 0000000..1938b8f --- /dev/null +++ b/Persistence.Database/Model/IChangeLogData.cs @@ -0,0 +1,11 @@ +namespace Persistence.Database.Model +{ + internal interface IChangeLogData + { + public int Id { get; set; } + public int? IdNext { get; set; } + public int? IdPrevious { get; set; } + public DateTimeOffset Creation { get; set; } + public DateTimeOffset? Obsolete { get; set; } + } +} diff --git a/Persistence.Database/Model/IPersistenceDbContext.cs b/Persistence.Database/Model/IPersistenceDbContext.cs index af837d6..3fcea74 100644 --- a/Persistence.Database/Model/IPersistenceDbContext.cs +++ b/Persistence.Database/Model/IPersistenceDbContext.cs @@ -11,6 +11,7 @@ namespace Persistence.Database.Model; public interface IPersistenceDbContext : IDisposable { DbSet DataSaub { get; } + DbSet ChangeLog { get; } DatabaseFacade Database { get; } Task SaveChangesAsync(CancellationToken cancellationToken); } diff --git a/Persistence.Database/Model/PersistenceDbContext.cs b/Persistence.Database/Model/PersistenceDbContext.cs index 3baf334..0879f9c 100644 --- a/Persistence.Database/Model/PersistenceDbContext.cs +++ b/Persistence.Database/Model/PersistenceDbContext.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Diagnostics.Metrics; @@ -10,9 +10,12 @@ using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace Persistence.Database.Model; public partial class PersistenceDbContext : DbContext, IPersistenceDbContext { - public DbSet DataSaub => Set(); + public DbSet DataSaub => Set(); + public DbSet ChangeLog => Set(); - public PersistenceDbContext(DbContextOptions options) + public PersistenceDbContext() { } // + + public PersistenceDbContext(DbContextOptions options) { } diff --git a/Persistence.Repository/Data/LogDto.cs b/Persistence.Repository/Data/LogDto.cs new file mode 100644 index 0000000..1068146 --- /dev/null +++ b/Persistence.Repository/Data/LogDto.cs @@ -0,0 +1,16 @@ +using Persistence.Models; + +namespace Persistence.Repository.Data +{ + internal class LogDto : IChangeLogAbstract + { + public int Id { get; set; } + public int IdAuthor { get; set; } + public int? IdNext { get; set; } + public int? IdPrevious { get; set; } + public int? IdEditor { get; set; } + public int IdState { get; set; } + public DateTimeOffset Creation { get; set; } + public DateTimeOffset? Obsolete { get; set; } + } +} diff --git a/Persistence.Repository/DependencyInjection.cs b/Persistence.Repository/DependencyInjection.cs index 17904c8..1228b98 100644 --- a/Persistence.Repository/DependencyInjection.cs +++ b/Persistence.Repository/DependencyInjection.cs @@ -5,6 +5,7 @@ using Persistence.Repositories; using Persistence.Database.Model; using Persistence.Repository.Data; using Persistence.Repository.Repositories; +using Persistence.Models; namespace Persistence.Repository; public static class DependencyInjection @@ -24,7 +25,8 @@ public static class DependencyInjection services.AddScoped(provider => provider.GetRequiredService()); services.AddTransient, TimeSeriesDataRepository>(); + services.AddTransient>, ChangeLogRepository>>(); - return services; + return services; } } diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs new file mode 100644 index 0000000..45c6d3e --- /dev/null +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -0,0 +1,71 @@ +using Microsoft.EntityFrameworkCore; +using Persistence.Models; +using Persistence.Repositories; + +namespace Persistence.Repository.Repositories +{ + public abstract class ChangeLogRepository : IChangeLogRepository + where TEntity : class + where TDto : class, IChangeLogAbstract, new() + where TChangeLogDto : ChangeLogDto + { + private DbContext db; + + public ChangeLogRepository(DbContext db) + { + this.db = db; + } + + protected virtual IQueryable GetQueryReadOnly() => db.Set(); + + public Task Clear(int idUser, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task ClearAndInsertRange(int idUser, IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task> GetCurrent(DateTimeOffset moment, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task> GetDatesChange(CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task> GetGtDate(DateTimeOffset dateBegin, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task MarkAsDeleted(int idUser, IEnumerable ids, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task UpdateOrInsertRange(int idUser, IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + + public Task UpdateRange(int idUser, IEnumerable dtos, CancellationToken token) + { + throw new NotImplementedException(); + } + } +} diff --git a/Persistence/Models/IChangeLogAbstract.cs b/Persistence/Models/IChangeLogAbstract.cs index a23ab1b..6214fbe 100644 --- a/Persistence/Models/IChangeLogAbstract.cs +++ b/Persistence/Models/IChangeLogAbstract.cs @@ -59,4 +59,9 @@ public interface IChangeLogAbstract /// Id заменяемой записи /// public int? IdPrevious { get; set; } + + /// + /// Id последующей записи + /// + public int? IdNext { get; set; } } diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index c12c61b..2278d8e 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -7,7 +7,7 @@ namespace Persistence.Repositories; /// /// public interface IChangeLogRepository : ISyncRepository - where TDto : class, ITimeSeriesAbstractDto, new() + where TDto : class, IChangeLogAbstract, new() where TChangeLogDto : ChangeLogDto { ///