Убраны дженерики у всего, что касается changeLog
This commit is contained in:
parent
24046d8505
commit
44730bb66e
@ -9,27 +9,29 @@ namespace Persistence.API.Controllers;
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class ChangeLogController<TDto> : ControllerBase, IChangeLogApi<TDto, ChangeLogDto<TDto>>
|
||||
where TDto : class, IChangeLogDto, new()
|
||||
public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
{
|
||||
private IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository;
|
||||
private IChangeLogRepository repository;
|
||||
|
||||
public ChangeLogController(IChangeLogRepository<TDto, ChangeLogDto<TDto>> repository)
|
||||
public ChangeLogController(IChangeLogRepository repository)
|
||||
{
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
[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 result = await repository.InsertRange(userId, [dto], token);
|
||||
var result = await repository.InsertRange(userId, idDiscriminator, [dtos], token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
@ -47,25 +49,30 @@ public class ChangeLogController<TDto> : ControllerBase, IChangeLogApi<TDto, Cha
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token)
|
||||
public Task<ActionResult<IEnumerable<IDictionary<string, object>>>> GetChangeLogCurrent(CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[HttpGet("history")]
|
||||
public Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
|
||||
public Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//[HttpGet("history")]
|
||||
//public Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
|
||||
//{
|
||||
// throw new NotImplementedException();
|
||||
//}
|
||||
|
||||
[HttpPut]
|
||||
public Task<ActionResult<int>> Update(TDto dto, CancellationToken token)
|
||||
public Task<ActionResult<int>> Update(IDictionary<string, object> dto, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[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();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace Persistence.Database.Model;
|
||||
public class ChangeLog : IChangeLog
|
||||
{
|
||||
/// <summary>
|
||||
/// Ид записи
|
||||
/// Ключ записи
|
||||
/// </summary>
|
||||
[Key, Column("Id")]
|
||||
public Guid Id { get; set; }
|
||||
@ -55,5 +55,5 @@ public class ChangeLog : IChangeLog
|
||||
/// Значение
|
||||
/// </summary>
|
||||
[Column("Value", TypeName = "jsonb")]
|
||||
public required object Value { get; set; }
|
||||
public required IDictionary<string, object> Value { get; set; }
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Persistence.Database.Model;
|
||||
|
||||
/// <summary>
|
||||
@ -7,7 +9,7 @@ namespace Persistence.Database.Model;
|
||||
public interface IChangeLog
|
||||
{
|
||||
/// <summary>
|
||||
/// Ид записи
|
||||
/// Ключ записи
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
@ -36,8 +38,13 @@ public interface IChangeLog
|
||||
/// </summary>
|
||||
public Guid? IdNext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дискриминатор таблицы
|
||||
/// </summary>
|
||||
public Guid IdDiscriminator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Значение
|
||||
/// </summary>
|
||||
public object Value { get; set; }
|
||||
public IDictionary<string, object> Value { get; set; }
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public static class DependencyInjection
|
||||
MapsterSetup();
|
||||
|
||||
services.AddTransient<ITimeSeriesDataRepository<DataSaubDto>, TimeSeriesDataCachedRepository<DataSaub, DataSaubDto>>();
|
||||
services.AddTransient(typeof(IChangeLogRepository<,>), typeof(ChangeLogRepository<,>));
|
||||
services.AddTransient<IChangeLogRepository, ChangeLogRepository>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ using Persistence.Models;
|
||||
using Persistence.Repositories;
|
||||
|
||||
namespace Persistence.Repository.Repositories;
|
||||
public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDto, TChangeLogDto>
|
||||
where TDto : class, IChangeLogDto, new()
|
||||
where TChangeLogDto : ChangeLogDto<TDto>
|
||||
public class ChangeLogRepository : IChangeLogRepository
|
||||
{
|
||||
private DbContext db;
|
||||
|
||||
@ -21,17 +19,17 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
|
||||
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();
|
||||
}
|
||||
|
||||
public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
|
||||
public Task<IEnumerable<ChangeLogDto<IDictionary<string, object>>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
|
||||
{
|
||||
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();
|
||||
}
|
||||
@ -41,25 +39,32 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
|
||||
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();
|
||||
}
|
||||
|
||||
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() {
|
||||
Value = dtos,
|
||||
Creation = DateTimeOffset.UtcNow,
|
||||
Id = idUser,
|
||||
IdAuthor = idUser,
|
||||
IdDiscriminator = new Guid(),
|
||||
IdEditor = idUser
|
||||
};
|
||||
entity.Id = idUser;
|
||||
var entities = new List<ChangeLog>();
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var entity = new ChangeLog()
|
||||
{
|
||||
IdAuthor = idUser,
|
||||
IdDiscriminator = idDiscriminator,
|
||||
IdEditor = 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);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -68,12 +73,12 @@ public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDt
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -6,16 +6,14 @@ namespace Persistence.API;
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с API журнала изменений
|
||||
/// </summary>
|
||||
public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
where TDto : class, IChangeLogDto, new()
|
||||
where TChangeLogDto : ChangeLogDto<TDto>
|
||||
public interface IChangeLogApi
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение исторических данных на текущую дату
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<IEnumerable<TDto>>> GetChangeLogCurrent(CancellationToken token);
|
||||
Task<ActionResult<IEnumerable<IDictionary<string, object>>>> GetChangeLogCurrent(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение исторических данных на определенную дату
|
||||
@ -23,7 +21,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
/// <param name="historyMoment"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<IEnumerable<TChangeLogDto>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token);
|
||||
Task<ActionResult<IEnumerable<ChangeLogDto<IDictionary<string, object>>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить одну запись
|
||||
@ -31,7 +29,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> Add(TDto dto, CancellationToken token);
|
||||
Task<ActionResult<int>> Add(Guid idDiscriminator, IDictionary<string, object> dto, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить несколько записей
|
||||
@ -39,7 +37,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> AddRange(IEnumerable<TDto> dtos, CancellationToken token);
|
||||
Task<ActionResult<int>> AddRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить одну запись
|
||||
@ -47,7 +45,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> Update(TDto dto, CancellationToken token);
|
||||
Task<ActionResult<int>> Update(IDictionary<string, object> dto, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить несколько записей
|
||||
@ -55,7 +53,7 @@ public interface IChangeLogApi<TDto, TChangeLogDto>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> UpdateRange(IEnumerable<TDto> dtos, CancellationToken token);
|
||||
Task<ActionResult<int>> UpdateRange(IEnumerable<IDictionary<string, object>> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить одну запись
|
||||
|
@ -5,8 +5,12 @@ namespace Persistence.Models;
|
||||
/// Часть записи описывающая изменение
|
||||
/// </summary>
|
||||
public class ChangeLogDto<T> : IChangeLogDto
|
||||
where T: class, IChangeLogDto, new()
|
||||
where T: IDictionary<string, object>
|
||||
{
|
||||
public ChangeLogDto()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Запись
|
||||
/// </summary>
|
||||
@ -15,35 +19,35 @@ public class ChangeLogDto<T> : IChangeLogDto
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Создатель записи
|
||||
/// </summary>
|
||||
public int IdAuthor { get; set; }
|
||||
public Guid IdAuthor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Пользователь, изменивший запись
|
||||
/// </summary>
|
||||
public int? IdEditor { get; set; }
|
||||
public Guid? IdEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Дата создания
|
||||
/// </summary>
|
||||
public DateTimeOffset Creation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Дата устаревания
|
||||
/// </summary>
|
||||
public DateTimeOffset? Obsolete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Ключ следующей записи
|
||||
/// </summary>
|
||||
public int? IdNext { get; set; }
|
||||
public Guid? IdNext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Объект записи
|
||||
/// </summary>
|
||||
public required object Value { get; set; }
|
||||
}
|
||||
|
@ -6,18 +6,17 @@ namespace Persistence.Repositories;
|
||||
/// Интерфейс для работы с историческими данными
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto>
|
||||
where TDto : class, IChangeLogDto, new()
|
||||
where TChangeLogDto : ChangeLogDto<TDto>
|
||||
public interface IChangeLogRepository //: ISyncRepository<TDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление записей
|
||||
/// </summary>
|
||||
/// <param name="idUser">пользователь, который добавляет</param>
|
||||
/// <param name="idDiscriminator">ключ справочника</param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <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>
|
||||
/// Редактирование записей
|
||||
@ -26,7 +25,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <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>
|
||||
/// Добавляет Dto у которых id == 0, изменяет dto у которых id != 0
|
||||
@ -35,7 +34,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <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>
|
||||
/// Помечает записи как удаленные
|
||||
@ -52,7 +51,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <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>
|
||||
/// Пометить записи как удаленные
|
||||
@ -77,7 +76,7 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
|
||||
/// <param name="updateFrom"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token);
|
||||
Task<IEnumerable<ChangeLogDto<IDictionary<string, object>>>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение текущих сейчас записей по параметрам
|
||||
@ -85,5 +84,5 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token);
|
||||
Task<IEnumerable<IDictionary<string, object>>> GetCurrent(DateTimeOffset moment, CancellationToken token);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user