Убраны дженерики у всего, что касается changeLog

This commit is contained in:
Olga Nemt 2024-11-26 11:47:42 +05:00
parent 24046d8505
commit 44730bb66e
8 changed files with 86 additions and 66 deletions

View File

@ -9,27 +9,29 @@ namespace Persistence.API.Controllers;
[ApiController] [ApiController]
[Authorize] [Authorize]
[Route("api/[controller]")] [Route("api/[controller]")]
public class ChangeLogController<TDto> : ControllerBase, IChangeLogApi<TDto, ChangeLogDto<TDto>> public class ChangeLogController : ControllerBase, IChangeLogApi
where TDto : class, IChangeLogDto, new()
{ {
private IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository; private IChangeLogRepository repository;
public ChangeLogController(IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository) public ChangeLogController(IChangeLogRepository repository)
{ {
this.repository = repository; this.repository = repository;
} }
[HttpPost] [HttpPost]
public async Task<ActionResult<int>> Add(TDto dto, CancellationToken token) public async Task<ActionResult<int>> Add(
[FromRoute] Guid idDiscriminator,
[FromBody]IDictionary<string, object> dtos,
CancellationToken token)
{ {
var userId = User.GetUserId<Guid>(); var userId = User.GetUserId<Guid>();
var result = await repository.InsertRange(userId, [dto], token); var result = await repository.InsertRange(userId, idDiscriminator, [dtos], token);
return Ok(result); return Ok(result);
} }
[HttpPost("range")] [HttpPost("range")]
public Task<ActionResult<int>> AddRange(IEnumerable<TDto> dtos, CancellationToken token) public Task<ActionResult<int>> AddRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -47,25 +49,30 @@ public class ChangeLogController<TDto> : ControllerBase, IChangeLogApi<TDto, Cha
} }
[HttpGet] [HttpGet]
public Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token) public Task<ActionResult<IEnumerable<IDictionary<string, object>>>> GetChangeLogCurrent(CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
[HttpGet("history")] public Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
public Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
//[HttpGet("history")]
//public Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
//{
// throw new NotImplementedException();
//}
[HttpPut] [HttpPut]
public Task<ActionResult<int>> Update(TDto dto, CancellationToken token) public Task<ActionResult<int>> Update(IDictionary<string, object> dto, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
[HttpPut("range")] [HttpPut("range")]
public Task<ActionResult<int>> UpdateRange(IEnumerable<TDto> dtos, CancellationToken token) public Task<ActionResult<int>> UpdateRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -10,7 +10,7 @@ namespace Persistence.Database.Model;
public class ChangeLog : IChangeLog public class ChangeLog : IChangeLog
{ {
/// <summary> /// <summary>
/// Ид записи /// Ключ записи
/// </summary> /// </summary>
[Key, Column("Id")] [Key, Column("Id")]
public Guid Id { get; set; } public Guid Id { get; set; }
@ -55,5 +55,5 @@ public class ChangeLog : IChangeLog
/// Значение /// Значение
/// </summary> /// </summary>
[Column("Value", TypeName = "jsonb")] [Column("Value", TypeName = "jsonb")]
public required object Value { get; set; } public required IDictionary<string, object> Value { get; set; }
} }

View File

@ -1,4 +1,6 @@
 
using System.ComponentModel.DataAnnotations.Schema;
namespace Persistence.Database.Model; namespace Persistence.Database.Model;
/// <summary> /// <summary>
@ -7,7 +9,7 @@ namespace Persistence.Database.Model;
public interface IChangeLog public interface IChangeLog
{ {
/// <summary> /// <summary>
/// Ид записи /// Ключ записи
/// </summary> /// </summary>
public Guid Id { get; set; } public Guid Id { get; set; }
@ -36,8 +38,13 @@ public interface IChangeLog
/// </summary> /// </summary>
public Guid? IdNext { get; set; } public Guid? IdNext { get; set; }
/// <summary>
/// Дискриминатор таблицы
/// </summary>
public Guid IdDiscriminator { get; set; }
/// <summary> /// <summary>
/// Значение /// Значение
/// </summary> /// </summary>
public object Value { get; set; } public IDictionary<string, object> Value { get; set; }
} }

View File

@ -17,7 +17,7 @@ public static class DependencyInjection
MapsterSetup(); MapsterSetup();
services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataCachedRepository<DataSaub, DataSaubDto>>(); services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataCachedRepository<DataSaub, DataSaubDto>>();
services.AddTransient(typeof(IChangeLogRepository<,>), typeof(ChangeLogRepository<,>)); services.AddTransient<IChangeLogRepository, ChangeLogRepository>();
return services; return services;
} }

View File

@ -5,9 +5,7 @@ using Persistence.Models;
using Persistence.Repositories; using Persistence.Repositories;
namespace Persistence.Repository.Repositories; namespace Persistence.Repository.Repositories;
public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDto, TChangeLogDto> public class ChangeLogRepository : IChangeLogRepository
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{ {
private DbContext db; private DbContext db;
@ -21,17 +19,17 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token) public Task<int> ClearAndInsertRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token) public Task<IEnumerable<ChangeLogDto<IDictionary<string, object>>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token) public Task<IEnumerable<IDictionary<string, object>>> GetCurrent(DateTimeOffset moment, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -41,25 +39,32 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset dateBegin, CancellationToken token) public Task<IEnumerable<IDictionary<string, object>>> GetGtDate(DateTimeOffset dateBegin, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> InsertRange(Guid idUser, IEnumerable<TDto> dtos, CancellationToken token) public Task<int> InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
var entity = new ChangeLog() { var entities = new List<ChangeLog>();
Value = dtos, foreach (var dto in dtos)
Creation = DateTimeOffset.UtcNow, {
Id = idUser, var entity = new ChangeLog()
IdAuthor = idUser, {
IdDiscriminator = new Guid(), IdAuthor = idUser,
IdEditor = idUser IdDiscriminator = idDiscriminator,
}; IdEditor = idUser,
entity.Id = idUser; Value = dto,
Creation = DateTimeOffset.UtcNow
};
entity.Id = idUser;
db.Set<ChangeLog>().Add(entity); entities.Add(entity);
}
db.Set<ChangeLog>().AddRange(entities);
var result = db.SaveChangesAsync(token); var result = db.SaveChangesAsync(token);
return result; return result;
} }
@ -68,12 +73,12 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token) public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token) public Task<int> UpdateRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -6,16 +6,14 @@ namespace Persistence.API;
/// <summary> /// <summary>
/// Интерфейс для работы с API журнала изменений /// Интерфейс для работы с API журнала изменений
/// </summary> /// </summary>
public interface IChangeLogApi<TDto, TChangeLogDto> public interface IChangeLogApi
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{ {
/// <summary> /// <summary>
/// Получение исторических данных на текущую дату /// Получение исторических данных на текущую дату
/// </summary> /// </summary>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token); Task<ActionResult<IEnumerable<IDictionary<string, object>>>> GetChangeLogCurrent(CancellationToken token);
/// <summary> /// <summary>
/// Получение исторических данных на определенную дату /// Получение исторических данных на определенную дату
@ -23,7 +21,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="historyMoment"></param> /// <param name="historyMoment"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<IEnumerable<TChangeLogDto>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token); Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token);
/// <summary> /// <summary>
/// Добавить одну запись /// Добавить одну запись
@ -31,7 +29,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<int>> Add(TDto dto, CancellationToken token); Task<ActionResult<int>> Add(Guid idDiscriminator, IDictionary<string, object> dto, CancellationToken token);
/// <summary> /// <summary>
/// Добавить несколько записей /// Добавить несколько записей
@ -39,7 +37,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<int>> AddRange(IEnumerable<TDto> dtos, CancellationToken token); Task<ActionResult<int>> AddRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Обновить одну запись /// Обновить одну запись
@ -47,7 +45,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<int>> Update(TDto dto, CancellationToken token); Task<ActionResult<int>> Update(IDictionary<string, object> dto, CancellationToken token);
/// <summary> /// <summary>
/// Обновить несколько записей /// Обновить несколько записей
@ -55,7 +53,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<ActionResult<int>> UpdateRange(IEnumerable<TDto> dtos, CancellationToken token); Task<ActionResult<int>> UpdateRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Удалить одну запись /// Удалить одну запись

View File

@ -5,8 +5,12 @@ namespace Persistence.Models;
/// Часть записи описывающая изменение /// Часть записи описывающая изменение
/// </summary> /// </summary>
public class ChangeLogDto<T> : IChangeLogDto public class ChangeLogDto<T> : IChangeLogDto
where T: class, IChangeLogDto, new() where T: IDictionary<string, object>
{ {
public ChangeLogDto()
{
}
/// <summary> /// <summary>
/// Запись /// Запись
/// </summary> /// </summary>
@ -15,35 +19,35 @@ public class ChangeLogDto<T> : IChangeLogDto
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public int Id { get; set; } public Guid Id { get; set; }
/// <summary> /// <summary>
/// /// Создатель записи
/// </summary> /// </summary>
public int IdAuthor { get; set; } public Guid IdAuthor { get; set; }
/// <summary> /// <summary>
/// /// Пользователь, изменивший запись
/// </summary> /// </summary>
public int? IdEditor { get; set; } public Guid? IdEditor { get; set; }
/// <summary> /// <summary>
/// /// Дата создания
/// </summary> /// </summary>
public DateTimeOffset Creation { get; set; } public DateTimeOffset Creation { get; set; }
/// <summary> /// <summary>
/// /// Дата устаревания
/// </summary> /// </summary>
public DateTimeOffset? Obsolete { get; set; } public DateTimeOffset? Obsolete { get; set; }
/// <summary> /// <summary>
/// /// Ключ следующей записи
/// </summary> /// </summary>
public int? IdNext { get; set; } public Guid? IdNext { get; set; }
/// <summary> /// <summary>
/// /// Объект записи
/// </summary> /// </summary>
public required object Value { get; set; } public required object Value { get; set; }
} }

View File

@ -6,18 +6,17 @@ namespace Persistence.Repositories;
/// Интерфейс для работы с историческими данными /// Интерфейс для работы с историческими данными
/// </summary> /// </summary>
/// <typeparam name="TDto"></typeparam> /// <typeparam name="TDto"></typeparam>
public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto> public interface IChangeLogRepository //: ISyncRepository<TDto>
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{ {
/// <summary> /// <summary>
/// Добавление записей /// Добавление записей
/// </summary> /// </summary>
/// <param name="idUser">пользователь, который добавляет</param> /// <param name="idUser">пользователь, который добавляет</param>
/// <param name="idDiscriminator">ключ справочника</param>
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> InsertRange(Guid idUser, IEnumerable<TDto> dtos, CancellationToken token); Task<int> InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Редактирование записей /// Редактирование записей
@ -26,7 +25,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token); Task<int> UpdateRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0 /// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0
@ -35,7 +34,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token); Task<int> UpdateOrInsertRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Помечает записи как удаленные /// Помечает записи как удаленные
@ -52,7 +51,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="dtos"></param> /// <param name="dtos"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token); Task<int> ClearAndInsertRange(int idUser, IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Пометить записи как удаленные /// Пометить записи как удаленные
@ -77,7 +76,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="updateFrom"></param> /// <param name="updateFrom"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token); Task<IEnumerable<ChangeLogDto<IDictionary<string, object>>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token);
/// <summary> /// <summary>
/// Получение текущих сейчас записей по параметрам /// Получение текущих сейчас записей по параметрам
@ -85,5 +84,5 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// <param name="request"></param> /// <param name="request"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token); Task<IEnumerable<IDictionary<string, object>>> GetCurrent(DateTimeOffset moment, CancellationToken token);
} }