Убран параметр TRequest

This commit is contained in:
Olga Nemt 2024-11-02 12:05:12 +05:00
parent 49c9a6107b
commit 65e2cb0977
4 changed files with 32 additions and 34 deletions

View File

@ -17,34 +17,36 @@ public abstract class AbstractChangeLogRepository<TEntity, TChangeLogDto, TDto>
} }
public abstract TEntity Convert(TDto entity); public abstract TEntity Convert(TDto entity);
public async Task<int> Clear(int idUser, TRequest request, CancellationToken token) public async Task<int> Clear(int idUser,CancellationToken token)
{ {
var updateTime = DateTimeOffset.UtcNow; throw new NotImplementedException();
//todo //var updateTime = DateTimeOffset.UtcNow;
var query = BuildQuery(request);
query = query.Where(e => e.Obsolete == null);
var entitiesToDelete = await query.ToArrayAsync(token); ////todo
//var query = BuildQuery(request);
//query = query.Where(e => e.Obsolete == null);
foreach (var entity in entitiesToDelete) //var entitiesToDelete = await query.ToArrayAsync(token);
{
entity.IdState = IChangeLogAbstract.IdCleared; //foreach (var entity in entitiesToDelete)
entity.Obsolete = updateTime; //{
entity.IdEditor = idUser; // entity.IdState = IChangeLogAbstract.IdCleared;
// entity.Obsolete = updateTime;
// entity.IdEditor = idUser;
//}
//var result = await SaveChangesWithExceptionHandling(token);
//return result;
} }
var result = await SaveChangesWithExceptionHandling(token); public async Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
return result;
}
public async Task<int> ClearAndInsertRange(int idUser, TRequest request, IEnumerable<TDto> dtos, CancellationToken token)
{ {
var result = 0; var result = 0;
using var transaction = await dbContext.Database.BeginTransactionAsync(token); using var transaction = await dbContext.Database.BeginTransactionAsync(token);
try try
{ {
result += await Clear(idUser, request, token); result += await Clear(idUser, token);
result += await InsertRangeWithoutTransaction(idUser, dtos, token); result += await InsertRangeWithoutTransaction(idUser, dtos, token);
await transaction.CommitAsync(token); await transaction.CommitAsync(token);
@ -57,12 +59,12 @@ public abstract class AbstractChangeLogRepository<TEntity, TChangeLogDto, TDto>
} }
} }
public Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token) public Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<DateOnly>> GetDatesChange(TRequest request, CancellationToken token) public Task<IEnumerable<DateOnly>> GetDatesChange(CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -74,9 +76,7 @@ public abstract class AbstractChangeLogRepository<TEntity, TChangeLogDto, TDto>
public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token) public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{ {
this.dbContext.Set<TEntity>(); using var transaction = dbContext.Database.BeginTransaction();
var db = GetDataBase();
using var transaction = db.BeginTransaction();
try try
{ {
var result = await InsertRangeWithoutTransaction(idUser, dtos, token); var result = await InsertRangeWithoutTransaction(idUser, dtos, token);
@ -107,7 +107,7 @@ public abstract class AbstractChangeLogRepository<TEntity, TChangeLogDto, TDto>
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token) public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -3,11 +3,12 @@
namespace Persistence.Repositories; namespace Persistence.Repositories;
/// <summary> /// <summary>
/// /// Интерфейс для работы с историческими данными
/// </summary> /// </summary>
/// <typeparam name="TDto"></typeparam> /// <typeparam name="TDto"></typeparam>
public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto> public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto>
where TDto : class where TDto : class
where TChangeLogDto : ChangeLogDto<TDto>
{ {
/// <summary> /// <summary>
/// Добавление записей /// Добавление записей
@ -40,20 +41,18 @@ public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDt
/// Помечает записи как удаленные /// Помечает записи как удаленные
/// </summary> /// </summary>
/// <param name="idUser">пользователь, который чистит</param> /// <param name="idUser">пользователь, который чистит</param>
/// <param name="request">Фильтр по свойствам конкретной сущности</param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<int> Clear(int idUser, TRequest request, CancellationToken token); Task<int> Clear(int idUser, CancellationToken token);
/// <summary> /// <summary>
/// Очистить и добавить новые /// Очистить и добавить новые
/// </summary> /// </summary>
/// <param name="idUser"></param> /// <param name="idUser"></param>
/// <param name="request"></param>
/// <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, TRequest request, IEnumerable<TDto> dtos, CancellationToken token); Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token);
/// <summary> /// <summary>
/// Пометить записи как удаленные /// Пометить записи как удаленные
@ -70,16 +69,15 @@ 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<DateOnly>> GetDatesChange(TRequest request, CancellationToken token); Task<IEnumerable<DateOnly>> GetDatesChange(CancellationToken token);
/// <summary> /// <summary>
/// Получение измененных записей за определенную дату /// Получение измененных записей за определенную дату
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="updateFrom"></param>
/// <param name="date">Фильтр по дате. Если null - вернет все записи, без привязки к дате</param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(TRequest request, DateOnly? date, CancellationToken token); Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token);
/// <summary> /// <summary>
/// Получение текущих сейчас записей по параметрам /// Получение текущих сейчас записей по параметрам
@ -87,5 +85,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(TRequest request, CancellationToken token); Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token);
} }

View File

@ -1,7 +1,7 @@
namespace Persistence.Repositories; namespace Persistence.Repositories;
/// <summary> /// <summary>
/// /// Интерфейс по работе с данными
/// </summary> /// </summary>
/// <typeparam name="TDto"></typeparam> /// <typeparam name="TDto"></typeparam>
public interface ISyncRepository<TDto> public interface ISyncRepository<TDto>

View File

@ -1,7 +1,7 @@
namespace Persistence.Repositories; namespace Persistence.Repositories;
/// <summary> /// <summary>
/// /// Интерфейс по работе с временными данными
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public interface ITimeSeriesDataRepository<TDto> : ISyncRepository<TDto> public interface ITimeSeriesDataRepository<TDto> : ISyncRepository<TDto>