diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs index de0ef2f..dd92e04 100644 --- a/Persistence.API/Controllers/ChangeLogController.cs +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -20,12 +20,12 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost] public async Task> Add( - [FromRoute] Guid idDiscriminator, - [FromBody]IDictionary dtos, + [FromRoute] Guid idDiscriminator, + ChangeLogDto dto, CancellationToken token) { var userId = User.GetUserId(); - var result = await repository.InsertRange(userId, idDiscriminator, [dtos], token); + var result = await repository.InsertRange(userId, idDiscriminator, [dto], token); return Ok(result); } @@ -54,7 +54,8 @@ public class ChangeLogController : ControllerBase, IChangeLogApi throw new NotImplementedException(); } - public Task>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token) + [HttpGet("history")] + public Task>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token) { throw new NotImplementedException(); } diff --git a/Persistence.Database.Postgres/DependencyInjection.cs b/Persistence.Database.Postgres/DependencyInjection.cs index 3acd55c..0fec635 100644 --- a/Persistence.Database.Postgres/DependencyInjection.cs +++ b/Persistence.Database.Postgres/DependencyInjection.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Npgsql; namespace Persistence.Database.Model; @@ -10,8 +11,12 @@ public static class DependencyInjection { string connectionStringName = "DefaultConnection"; - services.AddDbContext(options => - options.UseNpgsql(configuration.GetConnectionString(connectionStringName))); + services.AddDbContext(options => + { + var dataSourceBuilder = new NpgsqlDataSourceBuilder(configuration.GetConnectionString(connectionStringName)); + dataSourceBuilder.EnableDynamicJson(); + options.UseNpgsql(dataSourceBuilder.Build()); + }); services.AddScoped(provider => provider.GetRequiredService()); diff --git a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs b/Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.Designer.cs similarity index 82% rename from Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs rename to Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.Designer.cs index df89efd..c17da2b 100644 --- a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.Designer.cs +++ b/Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.Designer.cs @@ -1,5 +1,6 @@ // using System; +using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; @@ -12,8 +13,8 @@ using Persistence.Database.Model; namespace Persistence.Database.Postgres.Migrations { [DbContext(typeof(PersistenceDbContext))] - [Migration("20241122124437_AddChangeLog")] - partial class AddChangeLog + [Migration("20241126071115_Add_ChangeLog")] + partial class Add_ChangeLog { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -38,23 +39,39 @@ namespace Persistence.Database.Postgres.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("Creation"); - b.Property("IdAuthor") - .HasColumnType("integer") + b.Property("DepthEnd") + .HasColumnType("double precision") + .HasColumnName("DepthEnd"); + + b.Property("DepthStart") + .HasColumnType("double precision") + .HasColumnName("DepthStart"); + + b.Property("IdAuthor") + .HasColumnType("uuid") .HasColumnName("IdAuthor"); - b.Property("IdEditor") - .HasColumnType("integer") + b.Property("IdDiscriminator") + .HasColumnType("uuid") + .HasColumnName("IdDiscriminator"); + + b.Property("IdEditor") + .HasColumnType("uuid") .HasColumnName("IdEditor"); - b.Property("IdNext") - .HasColumnType("integer") + b.Property("IdNext") + .HasColumnType("uuid") .HasColumnName("IdNext"); + b.Property("IdSection") + .HasColumnType("uuid") + .HasColumnName("IdSection"); + b.Property("Obsolete") .HasColumnType("timestamp with time zone") .HasColumnName("Obsolete"); - b.Property("Value") + b.Property>("Value") .IsRequired() .HasColumnType("jsonb") .HasColumnName("Value"); diff --git a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs b/Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.cs similarity index 58% rename from Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs rename to Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.cs index 70aad1d..0802b00 100644 --- a/Persistence.Database.Postgres/Migrations/20241122124437_AddChangeLog.cs +++ b/Persistence.Database.Postgres/Migrations/20241126071115_Add_ChangeLog.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable @@ -6,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace Persistence.Database.Postgres.Migrations { /// - public partial class AddChangeLog : Migration + public partial class Add_ChangeLog : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -16,12 +17,16 @@ namespace Persistence.Database.Postgres.Migrations columns: table => new { Id = table.Column(type: "uuid", nullable: false), - IdAuthor = table.Column(type: "integer", nullable: false), - IdEditor = table.Column(type: "integer", nullable: true), + IdDiscriminator = table.Column(type: "uuid", nullable: false), + IdAuthor = table.Column(type: "uuid", nullable: false), + IdEditor = table.Column(type: "uuid", nullable: true), Creation = table.Column(type: "timestamp with time zone", nullable: false), Obsolete = table.Column(type: "timestamp with time zone", nullable: true), - IdNext = table.Column(type: "integer", nullable: true), - Value = table.Column(type: "jsonb", nullable: false) + IdNext = table.Column(type: "uuid", nullable: true), + DepthStart = table.Column(type: "double precision", nullable: false), + DepthEnd = table.Column(type: "double precision", nullable: false), + IdSection = table.Column(type: "uuid", nullable: false), + Value = table.Column>(type: "jsonb", nullable: false) }, constraints: table => { diff --git a/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs index 99dab9a..230d3ab 100644 --- a/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs +++ b/Persistence.Database.Postgres/Migrations/PersistenceDbContextModelSnapshot.cs @@ -1,5 +1,6 @@ // using System; +using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -35,23 +36,39 @@ namespace Persistence.Database.Postgres.Migrations .HasColumnType("timestamp with time zone") .HasColumnName("Creation"); - b.Property("IdAuthor") - .HasColumnType("integer") + b.Property("DepthEnd") + .HasColumnType("double precision") + .HasColumnName("DepthEnd"); + + b.Property("DepthStart") + .HasColumnType("double precision") + .HasColumnName("DepthStart"); + + b.Property("IdAuthor") + .HasColumnType("uuid") .HasColumnName("IdAuthor"); - b.Property("IdEditor") - .HasColumnType("integer") + b.Property("IdDiscriminator") + .HasColumnType("uuid") + .HasColumnName("IdDiscriminator"); + + b.Property("IdEditor") + .HasColumnType("uuid") .HasColumnName("IdEditor"); - b.Property("IdNext") - .HasColumnType("integer") + b.Property("IdNext") + .HasColumnType("uuid") .HasColumnName("IdNext"); + b.Property("IdSection") + .HasColumnType("uuid") + .HasColumnName("IdSection"); + b.Property("Obsolete") .HasColumnType("timestamp with time zone") .HasColumnName("Obsolete"); - b.Property("Value") + b.Property>("Value") .IsRequired() .HasColumnType("jsonb") .HasColumnName("Value"); diff --git a/Persistence.Database.Postgres/Readme.md b/Persistence.Database.Postgres/Readme.md index 756a8f5..7172774 100644 --- a/Persistence.Database.Postgres/Readme.md +++ b/Persistence.Database.Postgres/Readme.md @@ -2,4 +2,10 @@ ``` dotnet ef migrations add --project Persistence.Database.Postgres -``` \ No newline at end of file +``` + +## Откатить миграцию +``` +dotnet ef migrations remove --project Persistence.Database.Postgres +``` +Удаляется последняя созданная миграция. \ No newline at end of file diff --git a/Persistence.Database/Entity/ChangeLog.cs b/Persistence.Database/Entity/ChangeLog.cs index 59802ae..7100fc1 100644 --- a/Persistence.Database/Entity/ChangeLog.cs +++ b/Persistence.Database/Entity/ChangeLog.cs @@ -51,6 +51,24 @@ public class ChangeLog : IChangeLog [Column("IdNext")] public Guid? IdNext { get; set; } + /// + /// Глубина забоя на дату начала интервала + /// + [Column("DepthStart")] + public double DepthStart { get; set; } + + /// + /// Глубина забоя на дату окончания интервала + /// + [Column("DepthEnd")] + public double DepthEnd { get; set; } + + /// + /// Ключ секции + /// + [Column("IdSection")] + public Guid IdSection { get; set; } + /// /// Значение /// diff --git a/Persistence.Database/Entity/ChangeLogWithWellDepthAndSectionId.cs b/Persistence.Database/Entity/ChangeLogWithWellDepthAndSectionId.cs deleted file mode 100644 index abbe58f..0000000 --- a/Persistence.Database/Entity/ChangeLogWithWellDepthAndSectionId.cs +++ /dev/null @@ -1,29 +0,0 @@ - -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; - -namespace Persistence.Database.Model; - -/// -/// Часть записи, описывающая изменение данных, содержащие начальную и конечную глубину, а также секцию -/// -public class ChangeLogWithWellDepthAndSectionId : ChangeLog -{ - /// - /// Глубина забоя на дату начала интервала - /// - [Column("DepthStart")] - public double? DepthStart { get; set; } - - /// - /// Глубина забоя на дату окончания интервала - /// - [Column("DepthEnd")] - public double? DepthEnd { get; set; } - - /// - /// Ключ секции - /// - [Column("IdSection")] - public Guid IdSection { get; set; } -} diff --git a/Persistence.Database/Entity/IChangeLog.cs b/Persistence.Database/Entity/IChangeLog.cs index 449c691..04e08a4 100644 --- a/Persistence.Database/Entity/IChangeLog.cs +++ b/Persistence.Database/Entity/IChangeLog.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace Persistence.Database.Model; /// -/// Часть записи описывающая изменение +/// Часть записи, описывающая изменение /// public interface IChangeLog { diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index f0d8141..f659697 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -24,7 +24,7 @@ public class ChangeLogRepository : IChangeLogRepository throw new NotImplementedException(); } - public Task>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token) + public Task> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token) { throw new NotImplementedException(); } @@ -44,7 +44,7 @@ public class ChangeLogRepository : IChangeLogRepository throw new NotImplementedException(); } - public Task InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable> dtos, CancellationToken token) + public Task InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable dtos, CancellationToken token) { var entities = new List(); foreach (var dto in dtos) @@ -54,8 +54,11 @@ public class ChangeLogRepository : IChangeLogRepository IdAuthor = idUser, IdDiscriminator = idDiscriminator, IdEditor = idUser, - Value = dto, - Creation = DateTimeOffset.UtcNow + Value = dto.Value, + Creation = DateTimeOffset.UtcNow, + IdSection = dto.IdSection, + DepthStart = dto.DepthStart, + DepthEnd = dto.DepthEnd, }; entity.Id = idUser; diff --git a/Persistence/API/IChangeLogApi.cs b/Persistence/API/IChangeLogApi.cs index 6cb0896..4752fb7 100644 --- a/Persistence/API/IChangeLogApi.cs +++ b/Persistence/API/IChangeLogApi.cs @@ -21,7 +21,7 @@ public interface IChangeLogApi /// /// /// - Task>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token); + Task>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token); /// /// Добавить одну запись @@ -29,7 +29,7 @@ public interface IChangeLogApi /// /// /// - Task> Add(Guid idDiscriminator, IDictionary dto, CancellationToken token); + Task> Add(Guid idDiscriminator, ChangeLogDto dto, CancellationToken token); /// /// Добавить несколько записей diff --git a/Persistence/Models/ChangeLogDto.cs b/Persistence/Models/ChangeLogDto.cs index 8f716f4..14cbccc 100644 --- a/Persistence/Models/ChangeLogDto.cs +++ b/Persistence/Models/ChangeLogDto.cs @@ -1,20 +1,14 @@ - namespace Persistence.Models; /// /// Часть записи описывающая изменение /// -public class ChangeLogDto : IChangeLogDto - where T: IDictionary +public class ChangeLogDto { public ChangeLogDto() { - + } - /// - /// Запись - /// - public required T Item { get; set; } /// /// @@ -46,8 +40,23 @@ public class ChangeLogDto : IChangeLogDto /// public Guid? IdNext { get; set; } + /// + /// Глубина забоя на дату начала интервала + /// + public double DepthStart { get; set; } + + /// + /// Глубина забоя на дату окончания интервала + /// + public double DepthEnd { get; set; } + + /// + /// Ключ секции + /// + public Guid IdSection { get; set; } + /// /// Объект записи /// - public required object Value { get; set; } + public required IDictionary Value { get; set; } } diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index 06fbeb2..38b5dd2 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -16,7 +16,7 @@ public interface IChangeLogRepository //: ISyncRepository /// /// /// - Task InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable> dtos, CancellationToken token); + Task InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Редактирование записей @@ -76,7 +76,7 @@ public interface IChangeLogRepository //: ISyncRepository /// /// /// - Task>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token); + Task> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token); /// /// Получение текущих сейчас записей по параметрам