From 24046d85056826ee6e73f14eb07f606a85a96d14 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 26 Nov 2024 10:32:44 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B5=D0=BD=D0=B4=D0=B6=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=20(=D0=BD=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ChangeLogController.cs | 35 ++++++++++++------- Persistence.Repository/DependencyInjection.cs | 2 ++ .../Repositories/ChangeLogRepository.cs | 16 +++++++-- Persistence/API/IChangeLogApi.cs | 2 +- Persistence/Models/ChangeLogDto.cs | 2 +- .../Repositories/IChangeLogRepository.cs | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Persistence.API/Controllers/ChangeLogController.cs b/Persistence.API/Controllers/ChangeLogController.cs index b982382..6060faa 100644 --- a/Persistence.API/Controllers/ChangeLogController.cs +++ b/Persistence.API/Controllers/ChangeLogController.cs @@ -9,52 +9,63 @@ namespace Persistence.API.Controllers; [ApiController] [Authorize] [Route("api/[controller]")] -public class ChangeLogRotorController : ControllerBase, IChangeLogApi> +public class ChangeLogController : ControllerBase, IChangeLogApi> + where TDto : class, IChangeLogDto, new() { - private IChangeLogRepository> repository; + private IChangeLogRepository> repository; - public ChangeLogRotorController(IChangeLogRepository> repository) + public ChangeLogController(IChangeLogRepository> repository) { this.repository = repository; } - public async Task> Add(ProcessMapRotorDto dto, CancellationToken token) - { - await repository.InsertRange(0, [dto], token); - return null; + [HttpPost] + public async Task> Add(TDto dto, CancellationToken token) + { + var userId = User.GetUserId(); + var result = await repository.InsertRange(userId, [dto], token); + + return Ok(result); } - public Task> AddRange(IEnumerable dtos, CancellationToken token) + [HttpPost("range")] + public Task> AddRange(IEnumerable dtos, CancellationToken token) { throw new NotImplementedException(); } + [HttpDelete] public Task> Delete(int id, CancellationToken token) { throw new NotImplementedException(); } + [HttpDelete("range")] public Task> DeleteRange(IEnumerable ids, CancellationToken token) { throw new NotImplementedException(); } - public Task>> GetChangeLogCurrent(CancellationToken token) + [HttpGet] + public Task>> GetChangeLogCurrent(CancellationToken token) { throw new NotImplementedException(); } - public Task>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token) + [HttpGet("history")] + public Task>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token) { throw new NotImplementedException(); } - public Task> Update(ProcessMapRotorDto dto, CancellationToken token) + [HttpPut] + public Task> Update(TDto dto, CancellationToken token) { throw new NotImplementedException(); } - public Task> UpdateRange(IEnumerable dtos, CancellationToken token) + [HttpPut("range")] + public Task> UpdateRange(IEnumerable dtos, CancellationToken token) { throw new NotImplementedException(); } diff --git a/Persistence.Repository/DependencyInjection.cs b/Persistence.Repository/DependencyInjection.cs index 8e2f759..d732434 100644 --- a/Persistence.Repository/DependencyInjection.cs +++ b/Persistence.Repository/DependencyInjection.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Persistence.Database.Model; +using Persistence.Models; using Persistence.Repositories; using Persistence.Repository.Data; using Persistence.Repository.Repositories; @@ -16,6 +17,7 @@ public static class DependencyInjection MapsterSetup(); services.AddTransient, TimeSeriesDataCachedRepository>(); + services.AddTransient(typeof(IChangeLogRepository<,>), typeof(ChangeLogRepository<,>)); return services; } diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index 046e2bd..9195788 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -46,9 +46,21 @@ public class ChangeLogRepository : IChangeLogRepository InsertRange(int idUser, IEnumerable dtos, CancellationToken token) + public Task InsertRange(Guid idUser, IEnumerable dtos, CancellationToken token) { - throw new NotImplementedException(); + var entity = new ChangeLog() { + Value = dtos, + Creation = DateTimeOffset.UtcNow, + Id = idUser, + IdAuthor = idUser, + IdDiscriminator = new Guid(), + IdEditor = idUser + }; + entity.Id = idUser; + + db.Set().Add(entity); + var result = db.SaveChangesAsync(token); + return result; } public Task MarkAsDeleted(int idUser, IEnumerable ids, CancellationToken token) diff --git a/Persistence/API/IChangeLogApi.cs b/Persistence/API/IChangeLogApi.cs index bb4a3c3..2a734ca 100644 --- a/Persistence/API/IChangeLogApi.cs +++ b/Persistence/API/IChangeLogApi.cs @@ -7,7 +7,7 @@ namespace Persistence.API; /// Интерфейс для работы с API журнала изменений /// public interface IChangeLogApi - where TDto : class, new() + where TDto : class, IChangeLogDto, new() where TChangeLogDto : ChangeLogDto { /// diff --git a/Persistence/Models/ChangeLogDto.cs b/Persistence/Models/ChangeLogDto.cs index 14e937b..deb0c2b 100644 --- a/Persistence/Models/ChangeLogDto.cs +++ b/Persistence/Models/ChangeLogDto.cs @@ -5,7 +5,7 @@ namespace Persistence.Models; /// Часть записи описывающая изменение /// public class ChangeLogDto : IChangeLogDto - where T: class + where T: class, IChangeLogDto, new() { /// /// Запись diff --git a/Persistence/Repositories/IChangeLogRepository.cs b/Persistence/Repositories/IChangeLogRepository.cs index 3435ee1..5e05652 100644 --- a/Persistence/Repositories/IChangeLogRepository.cs +++ b/Persistence/Repositories/IChangeLogRepository.cs @@ -17,7 +17,7 @@ public interface IChangeLogRepository : ISyncRepository /// /// - Task InsertRange(int idUser, IEnumerable dtos, CancellationToken token); + Task InsertRange(Guid idUser, IEnumerable dtos, CancellationToken token); /// /// Редактирование записей