Правки после ревью (окончание)
This commit is contained in:
parent
ca816da076
commit
6447b5e94f
@ -27,7 +27,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
CancellationToken token)
|
||||
{
|
||||
var userId = User.GetUserId<Guid>();
|
||||
var result = await repository.InsertRange(userId, idDiscriminator, [dto], token);
|
||||
var result = await repository.AddRange(userId, idDiscriminator, [dto], token);
|
||||
|
||||
return CreatedAtAction(nameof(Add), result);
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var userId = User.GetUserId<Guid>();
|
||||
var result = await repository.InsertRange(userId, idDiscriminator, dtos, token);
|
||||
var result = await repository.AddRange(userId, idDiscriminator, dtos, token);
|
||||
|
||||
return CreatedAtAction(nameof(AddRange), result);
|
||||
}
|
||||
@ -67,25 +67,24 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
|
||||
[HttpPost("replace")]
|
||||
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> ClearAndInsertRange(
|
||||
public async Task<IActionResult> ClearAndAddRange(
|
||||
Guid idDiscriminator,
|
||||
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var userId = User.GetUserId<Guid>();
|
||||
var result = await repository.ClearAndInsertRange(userId, idDiscriminator, dtos, token);
|
||||
var result = await repository.ClearAndAddRange(userId, idDiscriminator, dtos, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPut]
|
||||
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> Update(
|
||||
Guid idDiscriminator,
|
||||
DataWithWellDepthAndSectionDto dto,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var userId = User.GetUserId<Guid>();
|
||||
var result = await repository.UpdateRange(userId, idDiscriminator, [dto], token);
|
||||
var result = await repository.UpdateRange(userId, [dto], token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -93,12 +92,11 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
[HttpPut("range")]
|
||||
[ProducesResponseType(typeof(int), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateRange(
|
||||
Guid idDiscriminator,
|
||||
IEnumerable<DataWithWellDepthAndSectionDto> dtos,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var userId = User.GetUserId<Guid>();
|
||||
var result = await repository.UpdateRange(userId, idDiscriminator, dtos, token);
|
||||
var result = await repository.UpdateRange(userId, dtos, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -107,11 +105,12 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
[ProducesResponseType(typeof(PaginationContainer<DataWithWellDepthAndSectionDto>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetCurrent(
|
||||
Guid idDiscriminator,
|
||||
[FromQuery]SectionPartRequest request,
|
||||
[FromQuery]SectionPartRequest filterRequest,
|
||||
[FromQuery] PaginationRequest paginationRequest,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero);
|
||||
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
||||
var result = await repository.GetByDate(idDiscriminator, moment, filterRequest, paginationRequest, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -121,10 +120,11 @@ public class ChangeLogController : ControllerBase, IChangeLogApi
|
||||
public async Task<IActionResult> GetByDate(
|
||||
Guid idDiscriminator,
|
||||
DateTimeOffset moment,
|
||||
[FromQuery] SectionPartRequest request,
|
||||
[FromQuery] SectionPartRequest filterRequest,
|
||||
[FromQuery] PaginationRequest paginationRequest,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var result = await repository.GetByDate(idDiscriminator, moment, request, token);
|
||||
var result = await repository.GetByDate(idDiscriminator, moment, filterRequest, paginationRequest, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
@ -18,17 +18,22 @@ public interface IChangeLogClient
|
||||
/// <param name="dtos"></param>
|
||||
/// <returns></returns>
|
||||
[Post($"{BaseRoute}/replace")]
|
||||
Task<IApiResponse<int>> ClearAndInsertRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos);
|
||||
Task<IApiResponse<int>> ClearAndAddRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos);
|
||||
|
||||
/// <summary>
|
||||
/// Получение актуальных данных на определенную дату (с пагинацией)
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="moment"></param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <param name="filterRequest">параметры запроса фильтрации</param>
|
||||
/// <param name="paginationRequest">параметры запроса пагинации</param>
|
||||
/// <returns></returns>
|
||||
[Get($"{BaseRoute}/moment")]
|
||||
Task<IApiResponse<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, [Query] SectionPartRequest request);
|
||||
Task<IApiResponse<PaginationContainer<DataWithWellDepthAndSectionDto>>> GetByDate(
|
||||
Guid idDiscriminator,
|
||||
DateTimeOffset moment,
|
||||
[Query] SectionPartRequest filterRequest,
|
||||
[Query] PaginationRequest paginationRequest);
|
||||
|
||||
/// <summary>
|
||||
/// Получение исторических данных за определенный период времени
|
||||
|
@ -31,7 +31,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
var dtos = Generate(2, DateTimeOffset.UtcNow);
|
||||
|
||||
// act
|
||||
var result = await client.ClearAndInsertRange(idDiscriminator, dtos);
|
||||
var result = await client.ClearAndAddRange(idDiscriminator, dtos);
|
||||
|
||||
// assert
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
@ -51,7 +51,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
var result = await client.Add(idDiscriminator, dto);
|
||||
|
||||
// assert
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Created, result.StatusCode);
|
||||
Assert.Equal(count, result.Content);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
var result = await client.AddRange(idDiscriminator, dtos);
|
||||
|
||||
// assert
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Created, result.StatusCode);
|
||||
Assert.Equal(count, result.Content);
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
var dtos = Generate(1, DateTimeOffset.UtcNow);
|
||||
var dto = dtos.FirstOrDefault()!;
|
||||
var result = await client.Add(idDiscriminator, dto);
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Created, result.StatusCode);
|
||||
|
||||
var entity = dbContext.ChangeLog
|
||||
.Where(x => x.IdDiscriminator == idDiscriminator)
|
||||
@ -230,7 +230,13 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
|
||||
var deletedCount = await client.DeleteRange(idsToDelete);
|
||||
|
||||
var request = new SectionPartRequest()
|
||||
var filterRequest = new SectionPartRequest()
|
||||
{
|
||||
DepthStart = 0,
|
||||
DepthEnd = 1000,
|
||||
};
|
||||
|
||||
var paginationRequest = new PaginationRequest()
|
||||
{
|
||||
Skip = 0,
|
||||
Take = 10,
|
||||
@ -238,7 +244,7 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
};
|
||||
|
||||
var moment = DateTimeOffset.UtcNow.AddDays(16);
|
||||
var result = await client.GetByDate(idDiscriminator, moment, request);
|
||||
var result = await client.GetByDate(idDiscriminator, moment, filterRequest, paginationRequest);
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
||||
Assert.NotNull(result.Content);
|
||||
@ -256,16 +262,16 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
[InlineData(5, -15, -10, -16, -9, 5)]
|
||||
public async Task GetChangeLogForInterval_returns_success(
|
||||
int insertedCount,
|
||||
int leftCreationFromCurrentDate,
|
||||
int rightCreationFromCurrentDate,
|
||||
int leftPointFromCurrentDate,
|
||||
int rightPointFromCurrentDate,
|
||||
int daysBeforeNowChangeLog,
|
||||
int daysAfterNowChangeLog,
|
||||
int daysBeforeNowFilter,
|
||||
int daysAfterNowFilter,
|
||||
int changeLogCount)
|
||||
{
|
||||
// arrange
|
||||
//создаем записи
|
||||
var count = insertedCount;
|
||||
var daysRange = (leftCreationFromCurrentDate, rightCreationFromCurrentDate);
|
||||
var daysRange = (daysBeforeNowChangeLog, daysAfterNowChangeLog);
|
||||
var changeLogItems = CreateChangeLogItems(count, daysRange);
|
||||
var idDiscriminator = changeLogItems.Item1;
|
||||
var entities = changeLogItems.Item2;
|
||||
@ -278,8 +284,8 @@ public class ChangeLogControllerTest : BaseIntegrationTest
|
||||
await client.UpdateRange(idDiscriminator, dtos);
|
||||
|
||||
//act
|
||||
var dateBegin = DateTimeOffset.UtcNow.AddDays(leftPointFromCurrentDate);
|
||||
var dateEnd = DateTimeOffset.UtcNow.AddDays(rightPointFromCurrentDate);
|
||||
var dateBegin = DateTimeOffset.UtcNow.AddDays(daysBeforeNowFilter);
|
||||
var dateEnd = DateTimeOffset.UtcNow.AddDays(daysAfterNowFilter);
|
||||
var result = await client.GetChangeLogForInterval(idDiscriminator, dateBegin, dateEnd);
|
||||
|
||||
//assert
|
||||
|
@ -15,11 +15,11 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public async Task<int> InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
public async Task<int> AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
{
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var entity = CreateEntityFromDto(idUser, idDiscriminator, dto);
|
||||
var entity = CreateEntityFromDto(idAuthor, idDiscriminator, dto);
|
||||
db.Set<ChangeLog>().Add(entity);
|
||||
}
|
||||
|
||||
@ -28,49 +28,49 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> MarkAsDeleted(Guid idUser, IEnumerable<Guid> ids, CancellationToken token)
|
||||
public async Task<int> MarkAsDeleted(Guid idEditor, IEnumerable<Guid> ids, CancellationToken token)
|
||||
{
|
||||
var query = db.Set<ChangeLog>().Where(s => ids.Contains(s.Id));
|
||||
var entities = await query.ToArrayAsync(token);
|
||||
|
||||
var result = await Clear(idUser, entities, token);
|
||||
var result = await Clear(idEditor, entities, token);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> MarkAsDeleted(Guid idUser, Guid idDiscriminator, CancellationToken token)
|
||||
public async Task<int> MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token)
|
||||
{
|
||||
var query = db.Set<ChangeLog>()
|
||||
.Where(s => s.IdDiscriminator == idDiscriminator)
|
||||
.Where(e => e.Obsolete == null);
|
||||
var entities = await query.ToArrayAsync(token);
|
||||
|
||||
var result = await Clear(idUser, entities, token);
|
||||
var result = await Clear(idEditor, entities, token);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<int> Clear(Guid idUser, IEnumerable<ChangeLog> entities, CancellationToken token)
|
||||
private async Task<int> Clear(Guid idEditor, IEnumerable<ChangeLog> entities, CancellationToken token)
|
||||
{
|
||||
var updateTime = DateTimeOffset.UtcNow;
|
||||
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
entity.Obsolete = updateTime;
|
||||
entity.IdEditor = idUser;
|
||||
entity.IdEditor = idEditor;
|
||||
}
|
||||
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<int> ClearAndInsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
public async Task<int> ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
{
|
||||
var result = 0;
|
||||
using var transaction = await db.Database.BeginTransactionAsync(token);
|
||||
try
|
||||
{
|
||||
result += await MarkAsDeleted(idUser, idDiscriminator, token);
|
||||
result += await InsertRange(idUser, idDiscriminator, dtos, token);
|
||||
result += await MarkAsDeleted(idAuthor, idDiscriminator, token);
|
||||
result += await AddRange(idAuthor, idDiscriminator, dtos, token);
|
||||
|
||||
await transaction.CommitAsync(token);
|
||||
return result;
|
||||
@ -82,7 +82,7 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> UpdateRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
public async Task<int> UpdateRange(Guid idEditor, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token)
|
||||
{
|
||||
var dbSet = db.Set<ChangeLog>();
|
||||
|
||||
@ -97,13 +97,18 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
{
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var newEntity = CreateEntityFromDto(idUser, idDiscriminator, dto);
|
||||
var updatedEntity = updatedEntities.GetValueOrDefault(dto.Id);
|
||||
if(updatedEntity is null)
|
||||
{
|
||||
throw new ArgumentNullException($"Entity with id = {dto.Id} doesn't exist in Db", nameof(dto));
|
||||
}
|
||||
|
||||
var newEntity = CreateEntityFromDto(idEditor, updatedEntity.IdDiscriminator, dto);
|
||||
dbSet.Add(newEntity);
|
||||
|
||||
var updatedEntity = updatedEntities.GetValueOrDefault(dto.Id)!;
|
||||
updatedEntity.IdNext = newEntity.Id;
|
||||
updatedEntity.Obsolete = DateTimeOffset.UtcNow;
|
||||
updatedEntity.IdEditor = idUser;
|
||||
updatedEntity.IdEditor = idEditor;
|
||||
}
|
||||
|
||||
result = await db.SaveChangesAsync(token);
|
||||
@ -121,11 +126,12 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
public async Task<PaginationContainer<DataWithWellDepthAndSectionDto>> GetByDate(
|
||||
Guid idDiscriminator,
|
||||
DateTimeOffset momentUtc,
|
||||
SectionPartRequest request,
|
||||
SectionPartRequest filterRequest,
|
||||
PaginationRequest paginationRequest,
|
||||
CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(idDiscriminator, momentUtc, request);
|
||||
var result = await BuildPaginationContainer(query, request, token);
|
||||
var query = BuildQuery(idDiscriminator, momentUtc, filterRequest);
|
||||
var result = await BuildPaginationContainer(query, paginationRequest, token);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -173,7 +179,7 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
|
||||
|
||||
|
||||
private async Task<PaginationContainer<DataWithWellDepthAndSectionDto>> BuildPaginationContainer(IQueryable<ChangeLog> query, SectionPartRequest request, CancellationToken token)
|
||||
private async Task<PaginationContainer<DataWithWellDepthAndSectionDto>> BuildPaginationContainer(IQueryable<ChangeLog> query, PaginationRequest request, CancellationToken token)
|
||||
{
|
||||
var result = new PaginationContainer<DataWithWellDepthAndSectionDto>
|
||||
{
|
||||
@ -232,15 +238,15 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
return datesOnly;
|
||||
}
|
||||
|
||||
private ChangeLog CreateEntityFromDto(Guid idUser, Guid idDiscriminator, DataWithWellDepthAndSectionDto dto)
|
||||
private ChangeLog CreateEntityFromDto(Guid idAuthor, Guid idDiscriminator, DataWithWellDepthAndSectionDto dto)
|
||||
{
|
||||
var entity = new ChangeLog()
|
||||
{
|
||||
Id = default,
|
||||
Creation = DateTimeOffset.UtcNow,
|
||||
IdAuthor = idUser,
|
||||
IdAuthor = idAuthor,
|
||||
IdDiscriminator = idDiscriminator,
|
||||
IdEditor = idUser,
|
||||
IdEditor = idAuthor,
|
||||
|
||||
Value = dto.Value,
|
||||
IdSection = dto.IdSection,
|
||||
|
@ -16,26 +16,28 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi<DataWithWellDepthAndS
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IActionResult> ClearAndInsertRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
Task<IActionResult> ClearAndAddRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных на текущую дату (с пагинацией)
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <param name="filterRequest">параметры запроса фильтрации</param>
|
||||
/// <param name="paginationRequest">параметры запроса пагинации</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IActionResult> GetCurrent(Guid idDiscriminator, SectionPartRequest request, CancellationToken token);
|
||||
Task<IActionResult> GetCurrent(Guid idDiscriminator, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных на определенную дату (с пагинацией)
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="moment"></param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <param name="filterRequest">параметры запроса фильтрации</param>
|
||||
/// <param name="paginationRequest">параметры запроса пагинации</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IActionResult> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest request, CancellationToken token);
|
||||
Task<IActionResult> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение исторических данных за определенный период времени
|
||||
@ -68,20 +70,18 @@ public interface IChangeLogApi : ISyncWithDiscriminatorApi<DataWithWellDepthAndS
|
||||
/// <summary>
|
||||
/// Обновить одну запись
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IActionResult> Update(Guid idDiscriminator, DataWithWellDepthAndSectionDto dto, CancellationToken token);
|
||||
Task<IActionResult> Update(DataWithWellDepthAndSectionDto dto, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить несколько записей
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IActionResult> UpdateRange(Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
Task<IActionResult> UpdateRange(IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить одну запись
|
||||
|
@ -7,7 +7,7 @@ namespace Persistence.API;
|
||||
/// Интерфейс для API, предназначенного для работы с табличными данными
|
||||
public interface ITableDataApi<TDto, TRequest>
|
||||
where TDto : class, new()
|
||||
where TRequest : Request
|
||||
where TRequest : PaginationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить страницу списка объектов
|
||||
|
@ -4,7 +4,7 @@
|
||||
/// Контейнер для поддержки постраничного просмотра таблиц
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class Request
|
||||
public class PaginationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Кол-во записей пропущенных с начала таблицы в запросе от api
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Запрос для фильтрации данных по секции и глубине
|
||||
/// </summary>
|
||||
public class SectionPartRequest : Request
|
||||
public class SectionPartRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Глубина забоя на дату начала интервала
|
||||
|
@ -1,165 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Persistence.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace Persistence.Repositories;
|
||||
//public abstract class AbstractChangeLogRepository<TEntity, TChangeLogDto, TDto> : IChangeLogRepository<TDto, TChangeLogDto>
|
||||
// where TDto : class, new()
|
||||
// where TEntity : class, IChangeLogAbstract
|
||||
// where TChangeLogDto : ChangeLogDto<TDto>
|
||||
//{
|
||||
// private readonly DbContext dbContext;
|
||||
|
||||
// protected AbstractChangeLogRepository(DbContext dbContext)
|
||||
// {
|
||||
// this.dbContext = dbContext;
|
||||
// }
|
||||
|
||||
// public abstract TEntity Convert(TDto entity);
|
||||
// public async Task<int> Clear(int idUser,CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
|
||||
// //var updateTime = DateTimeOffset.UtcNow;
|
||||
|
||||
// ////todo
|
||||
// //var query = BuildQuery(request);
|
||||
// //query = query.Where(e => e.Obsolete == null);
|
||||
|
||||
// //var entitiesToDelete = await query.ToArrayAsync(token);
|
||||
|
||||
// //foreach (var entity in entitiesToDelete)
|
||||
// //{
|
||||
// // entity.IdState = IChangeLogAbstract.IdCleared;
|
||||
// // entity.Obsolete = updateTime;
|
||||
// // entity.IdEditor = idUser;
|
||||
// //}
|
||||
|
||||
// //var result = await SaveChangesWithExceptionHandling(token);
|
||||
// //return result;
|
||||
// }
|
||||
|
||||
// public async Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
// {
|
||||
// var result = 0;
|
||||
// using var transaction = await dbContext.Database.BeginTransactionAsync(token);
|
||||
// try
|
||||
// {
|
||||
// result += await Clear(idUser, token);
|
||||
// result += await InsertRangeWithoutTransaction(idUser, dtos, token);
|
||||
|
||||
// await transaction.CommitAsync(token);
|
||||
// return result;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// await transaction.RollbackAsync(token);
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
|
||||
// public Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public Task<IEnumerable<DateOnly>> GetDatesChange(CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset date, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
// {
|
||||
// using var transaction = dbContext.Database.BeginTransaction();
|
||||
// try
|
||||
// {
|
||||
// var result = await InsertRangeWithoutTransaction(idUser, dtos, token);
|
||||
// await transaction.CommitAsync(token);
|
||||
// return result;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// await transaction.RollbackAsync(token);
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
|
||||
// protected abstract DatabaseFacade GetDataBase();
|
||||
|
||||
// public Task<int> MarkAsDeleted(int idUser, IEnumerable<int> ids, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
// private async Task<int> InsertRangeWithoutTransaction(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
|
||||
// {
|
||||
// var result = 0;
|
||||
// if (dtos.Any())
|
||||
// {
|
||||
// var entities = dtos.Select(Convert);
|
||||
// var creation = DateTimeOffset.UtcNow;
|
||||
// var dbSet = dbContext.Set<TEntity>();
|
||||
// foreach (var entity in entities)
|
||||
// {
|
||||
// entity.Id = default;
|
||||
// entity.IdAuthor = idUser;
|
||||
// entity.Creation = creation;
|
||||
// entity.IdState = IChangeLogAbstract.IdStateActual;
|
||||
// entity.IdEditor = null;
|
||||
// entity.IdPrevious = null;
|
||||
// entity.Obsolete = null;
|
||||
// dbSet.Add(entity);
|
||||
// }
|
||||
|
||||
// result += await SaveChangesWithExceptionHandling(token);
|
||||
// }
|
||||
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// private async Task<int> SaveChangesWithExceptionHandling(CancellationToken token)
|
||||
// {
|
||||
// var result = await dbContext.SaveChangesAsync(token);
|
||||
// return result;
|
||||
// //try
|
||||
// //{
|
||||
// // var result = await dbContext.SaveChangesAsync(token);
|
||||
// // return result;
|
||||
// //}
|
||||
// //catch (DbUpdateException ex)
|
||||
// //{
|
||||
// // if (ex.InnerException is PostgresException pgException)
|
||||
// // TryConvertPostgresExceptionToValidateException(pgException);
|
||||
// // throw;
|
||||
// //}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// //private static void TryConvertPostgresExceptionToValidateException(PostgresException pgException)
|
||||
// //{
|
||||
// // if (pgException.SqlState == PostgresErrorCodes.ForeignKeyViolation)
|
||||
// // throw new ArgumentInvalidException("dtos", pgException.Message + "\r\n" + pgException.Detail);
|
||||
// //}
|
||||
//}
|
@ -12,60 +12,60 @@ public interface IChangeLogRepository : ISyncWithDiscriminatorRepository<DataWit
|
||||
/// <summary>
|
||||
/// Добавление записей
|
||||
/// </summary>
|
||||
/// <param name="idUser">пользователь, который добавляет</param>
|
||||
/// <param name="idAuthor">пользователь, который добавляет</param>
|
||||
/// <param name="idDiscriminator">ключ справочника</param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
Task<int> AddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Пометить записи как удаленные
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="ids">ключи записей</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> MarkAsDeleted(Guid idUser, IEnumerable<Guid> ids, CancellationToken token);
|
||||
Task<int> MarkAsDeleted(Guid idEditor, IEnumerable<Guid> ids, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Пометить записи как удаленные
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="idDiscriminator">дискриминатор таблицы</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> MarkAsDeleted(Guid idUser, Guid idDiscriminator, CancellationToken token);
|
||||
Task<int> MarkAsDeleted(Guid idEditor, Guid idDiscriminator, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Очистить и добавить новые
|
||||
/// </summary>
|
||||
/// <param name="idUser"></param>
|
||||
/// <param name="idAuthor"></param>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> ClearAndInsertRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
Task<int> ClearAndAddRange(Guid idAuthor, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование записей
|
||||
/// </summary>
|
||||
/// <param name="idUser">пользователь, который редактирует</param>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="idEditor">пользователь, который редактирует</param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateRange(Guid idUser, Guid idDiscriminator, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
Task<int> UpdateRange(Guid idEditor, IEnumerable<DataWithWellDepthAndSectionDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение актуальных записей на определенный момент времени (с пагинацией)
|
||||
/// </summary>
|
||||
/// <param name="idDiscriminator"></param>
|
||||
/// <param name="moment">текущий момент времени</param>
|
||||
/// <param name="request">параметры запроса</param>
|
||||
/// <param name="filterRequest">параметры запроса фильтрации</param>
|
||||
/// <param name="paginationRequest">параметры запроса пагинации</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<PaginationContainer<DataWithWellDepthAndSectionDto>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest request, CancellationToken token);
|
||||
Task<PaginationContainer<DataWithWellDepthAndSectionDto>> GetByDate(Guid idDiscriminator, DateTimeOffset moment, SectionPartRequest filterRequest, PaginationRequest paginationRequest, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение измененных записей за период времени
|
||||
|
@ -7,7 +7,7 @@ namespace Persistence.Repositories;
|
||||
/// </summary>
|
||||
public interface ITableDataRepository<TDto, TRequest>
|
||||
where TDto : class, new()
|
||||
where TRequest : Request
|
||||
where TRequest : PaginationRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить страницу списка объектов
|
||||
|
Loading…
Reference in New Issue
Block a user