From 1e8d478b68adfa109695ddae57fb1f3e2f2f25a1 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Wed, 11 Dec 2024 14:31:50 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=B8=D1=81=D0=BA=D1=80=D0=B8=D0=BC=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D1=8B=20=D0=BA=20=D1=82=D0=B8=D0=BF=D1=83=20Guid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ChangeLogController.cs | 18 +++++------ .../Controllers/WitsDataController.cs | 6 ++-- .../Clients/IChangeLogClient.cs | 12 +++---- Persistence.Client/Clients/IWitsDataClient.cs | 6 ++-- .../20241203120141_ParameterDataMigration.cs | 2 +- Persistence.Database/Entity/ChangeLog.cs | 2 +- Persistence.Database/Entity/IChangeLog.cs | 2 +- Persistence.Database/Entity/ParameterData.cs | 2 +- .../Controllers/ChangeLogControllerTest.cs | 14 ++++----- .../Controllers/WitsDataControllerTest.cs | 11 ++++--- .../Repositories/ChangeLogRepository.cs | 20 ++++++------ .../Repositories/ParameterRepository.cs | 6 ++-- Persistence/API/IChangeLogApi.cs | 31 ++++++++++--------- Persistence/API/ISyncWithDiscriminatorApi.cs | 4 +-- Persistence/API/IWitsDataApi.cs | 2 +- Persistence/Models/ParameterDto.cs | 3 +- Persistence/Models/WitsDataDto.cs | 3 +- .../Repositories/IChangeLogRepository.cs | 12 +++---- .../Repositories/IParameterRepository.cs | 6 ++-- .../ISyncWithDiscriminatorRepository.cs | 4 +-- .../Services/Interfaces/IWitsDataService.cs | 6 ++-- Persistence/Services/WitsDataService.cs | 6 ++-- 22 files changed, 89 insertions(+), 89 deletions(-) diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs index 83a7fb6..52a68dd 100644 --- a/Persistence.API/Controllers/ChangeLogController.cs +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -22,7 +22,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] public async Task Add( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, [FromBody] DataWithWellDepthAndSectionDto dto, CancellationToken token) { @@ -35,7 +35,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("range/{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.Created)] public async Task AddRange( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, [FromBody] IEnumerable dtos, CancellationToken token) { @@ -68,7 +68,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpPost("replace/{idDiscriminator}")] [ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)] public async Task ClearAndAddRange( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, [FromBody] IEnumerable dtos, CancellationToken token) { @@ -104,7 +104,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("{idDiscriminator}")] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetCurrent( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, [FromQuery] SectionPartRequest filterRequest, [FromQuery] PaginationRequest paginationRequest, CancellationToken token) @@ -118,7 +118,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("moment/{idDiscriminator}")] [ProducesResponseType(typeof(PaginationContainer), (int)HttpStatusCode.OK)] public async Task GetByDate( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, DateTimeOffset moment, [FromQuery] SectionPartRequest filterRequest, [FromQuery] PaginationRequest paginationRequest, @@ -133,7 +133,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] public async Task GetChangeLogForDate( - [FromRoute] int idDiscriminator, + [FromRoute] Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) @@ -146,7 +146,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("datesChange/{idDiscriminator}")] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task GetDatesChange([FromRoute] int idDiscriminator, CancellationToken token) + public async Task GetDatesChange([FromRoute] Guid idDiscriminator, CancellationToken token) { var result = await repository.GetDatesChange(idDiscriminator, token); @@ -156,7 +156,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("part/{idDiscriminator}")] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task>> GetPart([FromRoute] int idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) + public async Task>> GetPart([FromRoute] Guid idDiscriminator, DateTimeOffset dateBegin, int take = 86400, CancellationToken token = default) { var result = await repository.GetGtDate(idDiscriminator, dateBegin, token); @@ -166,7 +166,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi [HttpGet("datesRange/{idDiscriminator}")] [ProducesResponseType(typeof(DatesRangeDto), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - public async Task> GetDatesRangeAsync([FromRoute] int idDiscriminator, CancellationToken token) + public async Task> GetDatesRangeAsync([FromRoute] Guid idDiscriminator, CancellationToken token) { var result = await repository.GetDatesRange(idDiscriminator, token); diff --git a/Persistence.API/Controllers/WitsDataController.cs b/Persistence.API/Controllers/WitsDataController.cs index 10dd7c7..741b35c 100644 --- a/Persistence.API/Controllers/WitsDataController.cs +++ b/Persistence.API/Controllers/WitsDataController.cs @@ -28,7 +28,7 @@ public class WitsDataController : ControllerBase, IWitsDataApi /// /// [HttpGet("{discriminatorId}/datesRange")] - public async Task> GetDatesRangeAsync([FromRoute] int discriminatorId, CancellationToken token) + public async Task> GetDatesRangeAsync([FromRoute] Guid discriminatorId, CancellationToken token) { var result = await witsDataService.GetDatesRangeAsync(discriminatorId, token); @@ -44,7 +44,7 @@ public class WitsDataController : ControllerBase, IWitsDataApi /// /// [HttpGet("{discriminatorId}/part")] - public async Task>> GetPart([FromRoute] int discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token) + public async Task>> GetPart([FromRoute] Guid discriminatorId, [FromQuery] DateTimeOffset dateBegin, [FromQuery] int take, CancellationToken token) { var result = await witsDataService.GetPart(discriminatorId, dateBegin, take, token); @@ -61,7 +61,7 @@ public class WitsDataController : ControllerBase, IWitsDataApi /// /// [HttpGet("{discriminatorId}/graph")] - public async Task>> GetValuesForGraph([FromRoute] int discriminatorId, + public async Task>> GetValuesForGraph([FromRoute] Guid discriminatorId, [FromQuery] DateTimeOffset dateFrom, [FromQuery] DateTimeOffset dateTo, [FromQuery] int approxPointsCount, CancellationToken token) { var result = await witsDataService.GetValuesForGraph(discriminatorId, dateFrom, dateTo, approxPointsCount, token); diff --git a/Persistence.Client/Clients/IChangeLogClient.cs b/Persistence.Client/Clients/IChangeLogClient.cs index 3bb9832..8391e84 100644 --- a/Persistence.Client/Clients/IChangeLogClient.cs +++ b/Persistence.Client/Clients/IChangeLogClient.cs @@ -18,7 +18,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/replace/{{idDiscriminator}}")] - Task> ClearAndAddRange(int idDiscriminator, IEnumerable dtos); + Task> ClearAndAddRange(Guid idDiscriminator, IEnumerable dtos); /// /// Получение актуальных данных на определенную дату (с пагинацией) @@ -30,7 +30,7 @@ public interface IChangeLogClient /// [Get($"{BaseRoute}/moment/{{idDiscriminator}}")] Task>> GetByDate( - int idDiscriminator, + Guid idDiscriminator, DateTimeOffset moment, [Query] SectionPartRequest filterRequest, [Query] PaginationRequest paginationRequest); @@ -43,7 +43,7 @@ public interface IChangeLogClient /// /// [Get($"{BaseRoute}/history/{{idDiscriminator}}")] - Task>> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd); + Task>> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd); /// /// Добавить одну запись @@ -52,7 +52,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/{{idDiscriminator}}")] - Task> Add(int idDiscriminator, DataWithWellDepthAndSectionDto dto); + Task> Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto); /// /// Добавить несколько записей @@ -61,7 +61,7 @@ public interface IChangeLogClient /// /// [Post($"{BaseRoute}/range/{{idDiscriminator}}")] - Task> AddRange(int idDiscriminator, IEnumerable dtos); + Task> AddRange(Guid idDiscriminator, IEnumerable dtos); /// /// Обновить одну запись @@ -101,6 +101,6 @@ public interface IChangeLogClient /// /// [Get($"{BaseRoute}/datesRange/{{idDiscriminator}}")] - Task> GetDatesRange(int idDiscriminator); + Task> GetDatesRange(Guid idDiscriminator); } diff --git a/Persistence.Client/Clients/IWitsDataClient.cs b/Persistence.Client/Clients/IWitsDataClient.cs index 108a4d7..b89b3e5 100644 --- a/Persistence.Client/Clients/IWitsDataClient.cs +++ b/Persistence.Client/Clients/IWitsDataClient.cs @@ -8,14 +8,14 @@ public interface IWitsDataClient private const string BaseRoute = "/api/witsData"; [Get($"{BaseRoute}/{{discriminatorId}}/graph")] - Task>> GetValuesForGraph(int discriminatorId, [Query] DateTimeOffset dateFrom, [Query] DateTimeOffset dateTo, [Query] int approxPointsCount, CancellationToken token); + Task>> GetValuesForGraph(Guid discriminatorId, [Query] DateTimeOffset dateFrom, [Query] DateTimeOffset dateTo, [Query] int approxPointsCount, CancellationToken token); [Post($"{BaseRoute}/")] Task> AddRange(IEnumerable dtos, CancellationToken token); [Get($"{BaseRoute}/{{discriminatorId}}/part")] - Task>> GetPart(int discriminatorId, [Query] DateTimeOffset dateBegin, [Query] int take = 24 * 60 * 60, CancellationToken token = default); + Task>> GetPart(Guid discriminatorId, [Query] DateTimeOffset dateBegin, [Query] int take = 24 * 60 * 60, CancellationToken token = default); [Get($"{BaseRoute}/{{discriminatorId}}/datesRange")] - Task> GetDatesRangeAsync(int discriminatorId, CancellationToken token); + Task> GetDatesRangeAsync(Guid discriminatorId, CancellationToken token); } diff --git a/Persistence.Database.Postgres/Migrations/20241203120141_ParameterDataMigration.cs b/Persistence.Database.Postgres/Migrations/20241203120141_ParameterDataMigration.cs index 049e506..7e9bde6 100644 --- a/Persistence.Database.Postgres/Migrations/20241203120141_ParameterDataMigration.cs +++ b/Persistence.Database.Postgres/Migrations/20241203120141_ParameterDataMigration.cs @@ -15,7 +15,7 @@ namespace Persistence.Database.Postgres.Migrations name: "ParameterData", columns: table => new { - DiscriminatorId = table.Column(type: "integer", nullable: false, comment: "Дискриминатор системы"), + DiscriminatorId = table.Column(type: "uuid", nullable: false, comment: "Дискриминатор системы"), ParameterId = table.Column(type: "integer", nullable: false, comment: "Id параметра"), Timestamp = table.Column(type: "timestamp with time zone", nullable: false, comment: "Временная отметка"), Value = table.Column(type: "varchar(256)", nullable: false, comment: "Значение параметра в виде строки") diff --git a/Persistence.Database/Entity/ChangeLog.cs b/Persistence.Database/Entity/ChangeLog.cs index eb921aa..9a8001b 100644 --- a/Persistence.Database/Entity/ChangeLog.cs +++ b/Persistence.Database/Entity/ChangeLog.cs @@ -15,7 +15,7 @@ public class ChangeLog : IChangeLog, IWithSectionPart public Guid Id { get; set; } [Comment("Дискриминатор таблицы")] - public int IdDiscriminator { get; set; } + public Guid IdDiscriminator { get; set; } [Comment("Автор изменения")] public Guid IdAuthor { get; set; } diff --git a/Persistence.Database/Entity/IChangeLog.cs b/Persistence.Database/Entity/IChangeLog.cs index b68bb0b..c4dc962 100644 --- a/Persistence.Database/Entity/IChangeLog.cs +++ b/Persistence.Database/Entity/IChangeLog.cs @@ -39,7 +39,7 @@ public interface IChangeLog /// /// Дискриминатор таблицы /// - public int IdDiscriminator { get; set; } + public Guid IdDiscriminator { get; set; } /// /// Значение diff --git a/Persistence.Database/Entity/ParameterData.cs b/Persistence.Database/Entity/ParameterData.cs index 627bf48..f8257de 100644 --- a/Persistence.Database/Entity/ParameterData.cs +++ b/Persistence.Database/Entity/ParameterData.cs @@ -8,7 +8,7 @@ namespace Persistence.Database.Entity; public class ParameterData { [Required, Comment("Дискриминатор системы")] - public int DiscriminatorId { get; set; } + public Guid DiscriminatorId { get; set; } [Comment("Id параметра")] public int ParameterId { get; set; } diff --git a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs index 9641a1e..c4b5376 100644 --- a/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/ChangeLogControllerTest.cs @@ -30,7 +30,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest // arrange dbContext.CleanupDbSet(); - var idDiscriminator = 1; + var idDiscriminator = Guid.NewGuid(); var dtos = Generate(2, DateTimeOffset.UtcNow); // act @@ -63,7 +63,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest { // arrange var count = 1; - var idDiscriminator = 1; + var idDiscriminator = Guid.NewGuid(); var dtos = Generate(count, DateTimeOffset.UtcNow); var dto = dtos.FirstOrDefault()!; @@ -80,7 +80,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest { // arrange var count = 3; - var idDiscriminator = 1; + var idDiscriminator = Guid.NewGuid(); var dtos = Generate(count, DateTimeOffset.UtcNow); // act @@ -97,7 +97,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest // arrange dbContext.CleanupDbSet(); - var idDiscriminator = 1; + var idDiscriminator = Guid.NewGuid(); var dtos = Generate(1, DateTimeOffset.UtcNow); var dto = dtos.FirstOrDefault()!; var result = await client.Add(idDiscriminator, dto); @@ -298,7 +298,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest var count = insertedCount; var daysRange = (daysBeforeNowChangeLog, daysAfterNowChangeLog); var changeLogItems = CreateChangeLogItems(count, daysRange); - var idDiscriminator = 1; + var idDiscriminator = changeLogItems.Item1; var entities = changeLogItems.Item2; foreach (var entity in entities) @@ -337,12 +337,12 @@ public class ChangeLogControllerTest : BaseIntegrationTest } - private (int, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange) + private (Guid, ChangeLog[]) CreateChangeLogItems(int count, (int, int) daysRange) { var minDayCount = daysRange.Item1; var maxDayCount = daysRange.Item2; - var idDiscriminator = 1; + var idDiscriminator = Guid.NewGuid(); var dtos = Generate(count, DateTimeOffset.UtcNow); var entities = dtos.Select(d => { diff --git a/Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs b/Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs index 9ecae04..12866a4 100644 --- a/Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs +++ b/Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs @@ -26,7 +26,7 @@ public class WitsDataControllerTest : BaseIntegrationTest //arrange dbContext.CleanupDbSet(); - var discriminatorId = 1; + var discriminatorId = Guid.NewGuid(); //act var response = await witsDataClient.GetDatesRangeAsync(discriminatorId, CancellationToken.None); @@ -42,7 +42,7 @@ public class WitsDataControllerTest : BaseIntegrationTest //arrange dbContext.CleanupDbSet(); - var discriminatorId = 1; + var discriminatorId = Guid.NewGuid(); var dateBegin = DateTimeOffset.UtcNow; var take = 1; @@ -71,7 +71,7 @@ public class WitsDataControllerTest : BaseIntegrationTest //arrange dbContext.CleanupDbSet(); - var discriminatorId = 1; + var discriminatorId = Guid.NewGuid(); var dateFrom = DateTimeOffset.UtcNow; var dateTo = DateTimeOffset.UtcNow; var approxPointCount = 12; @@ -177,7 +177,7 @@ public class WitsDataControllerTest : BaseIntegrationTest { new WitsDataDto() { - DiscriminatorId = -1, // < 0 + DiscriminatorId = Guid.NewGuid(), Timestamped = DateTimeOffset.UtcNow, Values = new List() { @@ -201,13 +201,14 @@ public class WitsDataControllerTest : BaseIntegrationTest private async Task> AddRange(int countToCreate = 10) { var dtos = new List(); + var discriminatorId = Guid.NewGuid(); var timestamped = DateTimeOffset.UtcNow; for (var i = 0; i < countToCreate; i++) { var random = new Random(); dtos.Add(new WitsDataDto() { - DiscriminatorId = 1, + DiscriminatorId = discriminatorId, Timestamped = timestamped.AddSeconds(i), Values = new List() { diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index 0291c1b..dc3f5eb 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -16,7 +16,7 @@ public class ChangeLogRepository : IChangeLogRepository this.db = db; } - public async Task AddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token) + public async Task AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token) { var entities = new List(); foreach (var dto in dtos) @@ -49,7 +49,7 @@ public class ChangeLogRepository : IChangeLogRepository return result; } - public async Task MarkAsDeleted(Guid idEditor, int idDiscriminator, CancellationToken token) + public async Task MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token) { var query = db.Set() .Where(s => s.IdDiscriminator == idDiscriminator) @@ -75,7 +75,7 @@ public class ChangeLogRepository : IChangeLogRepository return await db.SaveChangesAsync(token); } - public async Task ClearAndAddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token) + public async Task ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token) { var result = 0; @@ -127,7 +127,7 @@ public class ChangeLogRepository : IChangeLogRepository } public async Task> GetByDate( - int idDiscriminator, + Guid idDiscriminator, DateTimeOffset momentUtc, SectionPartRequest filterRequest, PaginationRequest paginationRequest, @@ -142,14 +142,14 @@ public class ChangeLogRepository : IChangeLogRepository return result; } - private IQueryable CreateQuery(int idDiscriminator) + private IQueryable CreateQuery(Guid idDiscriminator) { var query = db.Set().Where(e => e.IdDiscriminator == idDiscriminator); return query; } - public async Task> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) + public async Task> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token) { var query = db.Set().Where(s => s.IdDiscriminator == idDiscriminator); @@ -169,7 +169,7 @@ public class ChangeLogRepository : IChangeLogRepository - public async Task> GetDatesChange(int idDiscriminator, CancellationToken token) + public async Task> GetDatesChange(Guid idDiscriminator, CancellationToken token) { var query = db.Set().Where(e => e.IdDiscriminator == idDiscriminator); @@ -195,7 +195,7 @@ public class ChangeLogRepository : IChangeLogRepository return datesOnly; } - private ChangeLog CreateEntityFromDto(Guid idAuthor, int idDiscriminator, DataWithWellDepthAndSectionDto dto) + private ChangeLog CreateEntityFromDto(Guid idAuthor, Guid idDiscriminator, DataWithWellDepthAndSectionDto dto) { var entity = new ChangeLog() { @@ -214,7 +214,7 @@ public class ChangeLogRepository : IChangeLogRepository return entity; } - public async Task> GetGtDate(int idDiscriminator, DateTimeOffset dateBegin, CancellationToken token) + public async Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token) { var date = dateBegin.ToUniversalTime(); var query = this.db.Set() @@ -228,7 +228,7 @@ public class ChangeLogRepository : IChangeLogRepository return dtos; } - public async Task GetDatesRange(int idDiscriminator, CancellationToken token) + public async Task GetDatesRange(Guid idDiscriminator, CancellationToken token) { var query = db.Set() .Where(e => e.IdDiscriminator == idDiscriminator) diff --git a/Persistence.Repository/Repositories/ParameterRepository.cs b/Persistence.Repository/Repositories/ParameterRepository.cs index dbf387f..325c08c 100644 --- a/Persistence.Repository/Repositories/ParameterRepository.cs +++ b/Persistence.Repository/Repositories/ParameterRepository.cs @@ -17,7 +17,7 @@ public class ParameterRepository : IParameterRepository protected virtual IQueryable GetQueryReadOnly() => db.Set(); - public async Task GetDatesRangeAsync(int idDiscriminator, CancellationToken token) + public async Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token) { var query = GetQueryReadOnly() .Where(e => e.DiscriminatorId == idDiscriminator) @@ -37,7 +37,7 @@ public class ParameterRepository : IParameterRepository return result; } - public async Task> GetPart(int idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token) + public async Task> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token) { var query = GetQueryReadOnly(); var universalDate = dateBegin.ToUniversalTime(); @@ -50,7 +50,7 @@ public class ParameterRepository : IParameterRepository return dtos; } - public async Task> GetValuesForGraph(int discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, + public async Task> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, int? ratio, CancellationToken token) { var query = db.Set().AsNoTracking(); diff --git a/Persistence/API/IChangeLogApi.cs b/Persistence/API/IChangeLogApi.cs index cbf2127..4a548bf 100644 --- a/Persistence/API/IChangeLogApi.cs +++ b/Persistence/API/IChangeLogApi.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using System; +using Microsoft.AspNetCore.Mvc; using Persistence.Models; using Persistence.Models.Requests; @@ -16,7 +17,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task ClearAndAddRange(int idDiscriminator, IEnumerable dtos, CancellationToken token); + Task ClearAndAddRange(Guid idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Получение данных на текущую дату (с пагинацией) @@ -26,7 +27,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApiпараметры запроса пагинации /// /// - Task GetCurrent(int idDiscriminator, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task GetCurrent(Guid idDiscriminator, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение данных на определенную дату (с пагинацией) @@ -37,7 +38,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApiпараметры запроса пагинации /// /// - Task GetByDate(int idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение исторических данных за определенный период времени @@ -47,16 +48,16 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task GetChangeLogForDate(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); + Task GetChangeLogForDate(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); - /// - /// Добавить одну запись - /// - /// - /// - /// - /// - Task Add(int idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token); + /// + /// Добавить одну запись + /// + /// + /// + /// + /// + Task Add(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token); /// /// Добавить несколько записей @@ -65,7 +66,7 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task AddRange(int idDiscriminator, IEnumerable dtos, CancellationToken token); + Task AddRange(Guid idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Обновить одну запись @@ -105,5 +106,5 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi /// /// - Task GetDatesChange(int idDiscriminator, CancellationToken token); + Task GetDatesChange(Guid idDiscriminator, CancellationToken token); } diff --git a/Persistence/API/ISyncWithDiscriminatorApi.cs b/Persistence/API/ISyncWithDiscriminatorApi.cs index 88b49dd..224b8df 100644 --- a/Persistence/API/ISyncWithDiscriminatorApi.cs +++ b/Persistence/API/ISyncWithDiscriminatorApi.cs @@ -16,7 +16,7 @@ public interface ISyncWithDiscriminatorApi /// количество записей /// /// - Task>> GetPart(int idDiscriminator, DateTimeOffset dateBegin, int take = 24 * 60 * 60, CancellationToken token = default); + Task>> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take = 24 * 60 * 60, CancellationToken token = default); /// /// Получить диапазон дат, для которых есть данные в репозитории @@ -24,5 +24,5 @@ public interface ISyncWithDiscriminatorApi /// /// /// - Task> GetDatesRangeAsync(int idDiscriminator, CancellationToken token); + Task> GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token); } \ No newline at end of file diff --git a/Persistence/API/IWitsDataApi.cs b/Persistence/API/IWitsDataApi.cs index 8bd3e6f..a8e5de8 100644 --- a/Persistence/API/IWitsDataApi.cs +++ b/Persistence/API/IWitsDataApi.cs @@ -17,7 +17,7 @@ public interface IWitsDataApi : ISyncWithDiscriminatorApi /// /// /// - Task>> GetValuesForGraph(int discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, + Task>> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token); /// diff --git a/Persistence/Models/ParameterDto.cs b/Persistence/Models/ParameterDto.cs index a1155ce..63a4660 100644 --- a/Persistence/Models/ParameterDto.cs +++ b/Persistence/Models/ParameterDto.cs @@ -10,8 +10,7 @@ public class ParameterDto /// /// Дискриминатор системы /// - [Range(0, int.MaxValue, ErrorMessage = "Дискриминатор системы не может быть меньше 0")] - public int DiscriminatorId { get; set; } + public Guid DiscriminatorId { get; set; } /// /// Id параметра diff --git a/Persistence/Models/WitsDataDto.cs b/Persistence/Models/WitsDataDto.cs index 7293067..e224f6d 100644 --- a/Persistence/Models/WitsDataDto.cs +++ b/Persistence/Models/WitsDataDto.cs @@ -15,8 +15,7 @@ public class WitsDataDto /// /// Дискриминатор системы /// - [Range(0, int.MaxValue, ErrorMessage = "Дискриминатор системы не может быть меньше 0")] - public required int DiscriminatorId { get; set; } + public required Guid DiscriminatorId { get; set; } /// /// Параметры diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index 3db37b6..e197090 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -17,7 +17,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task AddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token); + Task AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Пометить записи как удаленные @@ -35,7 +35,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepositoryдискриминатор таблицы /// /// - Task MarkAsDeleted(Guid idEditor, int idDiscriminator, CancellationToken token); + Task MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token); /// /// Очистить и добавить новые @@ -45,7 +45,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task ClearAndAddRange(Guid idAuthor, int idDiscriminator, IEnumerable dtos, CancellationToken token); + Task ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable dtos, CancellationToken token); /// /// Редактирование записей @@ -65,7 +65,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepositoryпараметры запроса пагинации /// /// - Task> GetByDate(int idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); + Task> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token); /// /// Получение измененных записей за период времени @@ -75,7 +75,7 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task> GetChangeLogForInterval(int idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); + Task> GetChangeLogForInterval(Guid idDiscriminator, DateTimeOffset dateBegin, DateTimeOffset dateEnd, CancellationToken token); /// /// Получение списка дат, в которые происходили изменения (день, месяц, год, без времени) @@ -83,5 +83,5 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository /// /// - Task> GetDatesChange(int idDiscriminator, CancellationToken token); + Task> GetDatesChange(Guid idDiscriminator, CancellationToken token); } diff --git a/Persistence/Repositories/IParameterRepository.cs b/Persistence/Repositories/IParameterRepository.cs index a3728da..c600898 100644 --- a/Persistence/Repositories/IParameterRepository.cs +++ b/Persistence/Repositories/IParameterRepository.cs @@ -10,14 +10,14 @@ public interface IParameterRepository /// /// /// - Task> GetPart(int idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token); + Task> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token); /// /// Получить диапазон дат, для которых есть данные в репозитории /// /// /// - Task GetDatesRangeAsync(int idDiscriminator, CancellationToken token); + Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token); /// /// Получить набор параметров (Wits) для построения графика @@ -29,7 +29,7 @@ public interface IParameterRepository /// /// /// - Task> GetValuesForGraph(int discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, + Task> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, int? ratio, CancellationToken token); /// diff --git a/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs index af8c807..7e0bd62 100644 --- a/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs +++ b/Persistence/Repositories/ISyncWithDiscriminatorRepository.cs @@ -15,7 +15,7 @@ public interface ISyncWithDiscriminatorRepository /// дата начала /// /// /// - Task> GetGtDate(int idDiscriminator, DateTimeOffset dateBegin, CancellationToken token); + Task> GetGtDate(Guid idDiscriminator, DateTimeOffset dateBegin, CancellationToken token); /// @@ -24,5 +24,5 @@ public interface ISyncWithDiscriminatorRepository /// дискриминатор таблицы /// /// - Task GetDatesRange(int idDiscriminator, CancellationToken token); + Task GetDatesRange(Guid idDiscriminator, CancellationToken token); } diff --git a/Persistence/Services/Interfaces/IWitsDataService.cs b/Persistence/Services/Interfaces/IWitsDataService.cs index 69137f1..dea77ab 100644 --- a/Persistence/Services/Interfaces/IWitsDataService.cs +++ b/Persistence/Services/Interfaces/IWitsDataService.cs @@ -13,7 +13,7 @@ public interface IWitsDataService /// /// /// - Task GetDatesRangeAsync(int idDiscriminator, CancellationToken token); + Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token); /// /// Получить порцию записей, начиная с заданной даты @@ -23,7 +23,7 @@ public interface IWitsDataService /// /// /// - Task> GetPart(int idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token); + Task> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token); /// /// Получить диапазон дат, для которых есть данные в репозитории @@ -34,7 +34,7 @@ public interface IWitsDataService /// /// /// - Task> GetValuesForGraph(int discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token); + Task> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token); /// /// Сохранить набор параметров diff --git a/Persistence/Services/WitsDataService.cs b/Persistence/Services/WitsDataService.cs index e93a213..3d99a3a 100644 --- a/Persistence/Services/WitsDataService.cs +++ b/Persistence/Services/WitsDataService.cs @@ -25,14 +25,14 @@ public class WitsDataService : IWitsDataService this.witsInfo = GetWitsInfo(); } - public Task GetDatesRangeAsync(int idDiscriminator, CancellationToken token) + public Task GetDatesRangeAsync(Guid idDiscriminator, CancellationToken token) { var result = witsDataRepository.GetDatesRangeAsync(idDiscriminator, token); return result; } - public async Task> GetPart(int idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token) + public async Task> GetPart(Guid idDiscriminator, DateTimeOffset dateBegin, int take, CancellationToken token) { var dtos = await witsDataRepository.GetPart(idDiscriminator, dateBegin, take, token); @@ -41,7 +41,7 @@ public class WitsDataService : IWitsDataService return result; } - public async Task> GetValuesForGraph(int discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, + public async Task> GetValuesForGraph(Guid discriminatorId, DateTimeOffset dateFrom, DateTimeOffset dateTo, int approxPointsCount, CancellationToken token) { var intervalSec = (dateTo - dateFrom).TotalSeconds;