forked from ddrilling/AsbCloudServer
Add IChangeLogQueryBuilderWithKnownTimezone
This commit is contained in:
parent
9322d2874b
commit
96e9cd3f16
62
AsbCloudApp/Repositories/IChangeLogQueryBuilder.cs
Normal file
62
AsbCloudApp/Repositories/IChangeLogQueryBuilder.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектами, содержащими историю изменений
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
/// <typeparam name="TRequest"></typeparam>
|
||||
public interface IChangeLogQueryBuilder<TDto, TRequest>
|
||||
where TDto : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Применение запроса
|
||||
/// </summary>
|
||||
/// <param name="request">Запрос</param>
|
||||
/// <returns></returns>
|
||||
IChangeLogQueryBuilderWithKnownTimezone<TDto, TRequest> ApplyRequest(TRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Материализация записей
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetData(TimeSpan offset, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Материализация записей с историей
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(TimeSpan offset, CancellationToken token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектами, содержащими историю изменений. С известной временной зоной
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
/// <typeparam name="TRequest"></typeparam>
|
||||
public interface IChangeLogQueryBuilderWithKnownTimezone<TDto, TRequest>: IChangeLogQueryBuilder<TDto, TRequest>
|
||||
where TDto : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Материализация записей. Временная зона определяется по запросу из последнего ApplyRequest
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetData(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Материализация записей с историей. Временная зона определяется по запросу из последнего ApplyRequest
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(CancellationToken token);
|
||||
}
|
@ -93,11 +93,10 @@ public interface IChangeLogRepository<TDto, TRequest>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetCurrent(TRequest request, CancellationToken token);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта, реализующего интерфейс IChangeLogRepositoryBuilder
|
||||
/// для последующих вызовов методов фильтрации по запросам
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IChangeLogRepositoryBuilder<TDto, TRequest> GetRequestBuilder(ChangeLogRequest request);
|
||||
IChangeLogQueryBuilder<TDto, TRequest> GetQueryBuilder(ChangeLogRequest request);
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектами, содержащими историю изменений
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
/// <typeparam name="TRequest"></typeparam>
|
||||
public interface IChangeLogRepositoryBuilder<TDto, TRequest>
|
||||
where TDto : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Применение запроса
|
||||
/// </summary>
|
||||
/// <param name="request">Запрос</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
IChangeLogRepositoryBuilder<TDto, TRequest> ApplyRequest(TRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Материализация записей
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetData(TimeSpan offset, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Материализация записей с историей
|
||||
/// </summary>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(TimeSpan offset, CancellationToken token);
|
||||
}
|
@ -25,12 +25,12 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
private class ChangeLogRepositoryBuilder<TEntityChangeLog, TDtoChangeLog, TRequestChangeLog> : IChangeLogRepositoryBuilder<TDto, TRequest>
|
||||
private class ChangeLogQueryBuilder: IChangeLogQueryBuilder<TDto, TRequest>
|
||||
{
|
||||
private readonly ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> Repository;
|
||||
private IQueryable<TEntity> Query;
|
||||
protected readonly ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> Repository;
|
||||
protected IQueryable<TEntity> Query;
|
||||
|
||||
public ChangeLogRepositoryBuilder(
|
||||
public ChangeLogQueryBuilder(
|
||||
ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> repository,
|
||||
ChangeLogRequest request)
|
||||
{
|
||||
@ -49,15 +49,20 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
|
||||
}
|
||||
}
|
||||
|
||||
public IChangeLogRepositoryBuilder<TDto, TRequest> ApplyRequest(TRequest request, CancellationToken token)
|
||||
public ChangeLogQueryBuilder(ChangeLogQueryBuilder builder)
|
||||
{
|
||||
Repository = builder.Repository;
|
||||
Query = builder.Query;
|
||||
}
|
||||
|
||||
public virtual IChangeLogQueryBuilderWithKnownTimezone<TDto, TRequest> ApplyRequest(TRequest request)
|
||||
{
|
||||
this.Query = Repository.BuildQuery(request, Query);
|
||||
return this;
|
||||
return new ChangeLogQueryBuilderWithKnownTimezone(this, request);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetData(TimeSpan offset, CancellationToken token)
|
||||
{
|
||||
|
||||
var dtos = await this.Query.Select(e => Repository.Convert(e, offset))
|
||||
.ToArrayAsync(token);
|
||||
return dtos;
|
||||
@ -71,10 +76,43 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
|
||||
}
|
||||
}
|
||||
|
||||
public IChangeLogRepositoryBuilder<TDto, TRequest> GetRequestBuilder(ChangeLogRequest request)
|
||||
private class ChangeLogQueryBuilderWithKnownTimezone: ChangeLogQueryBuilder, IChangeLogQueryBuilderWithKnownTimezone<TDto, TRequest>
|
||||
{
|
||||
var builder = new ChangeLogRepositoryBuilder<TEntity, TDto, TRequest>(this, request);
|
||||
TRequest request;
|
||||
|
||||
public ChangeLogQueryBuilderWithKnownTimezone(
|
||||
ChangeLogQueryBuilder parentBuilder,
|
||||
TRequest request)
|
||||
:base(parentBuilder)
|
||||
{
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public override IChangeLogQueryBuilderWithKnownTimezone<TDto, TRequest> ApplyRequest(TRequest request)
|
||||
{
|
||||
Query = Repository.BuildQuery(request, Query);
|
||||
this.request = request;
|
||||
return this;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetData(CancellationToken token)
|
||||
{
|
||||
TimeSpan timezoneOffset = Repository.GetTimezoneOffset(request);
|
||||
var dtos = await this.GetData(timezoneOffset, token);
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ChangeLogDto<TDto>>> GetChangeLogData(CancellationToken token)
|
||||
{
|
||||
TimeSpan timezoneOffset = Repository.GetTimezoneOffset(request);
|
||||
var dtos = await this.GetChangeLogData(timezoneOffset, token);
|
||||
return dtos;
|
||||
}
|
||||
}
|
||||
|
||||
public IChangeLogQueryBuilder<TDto, TRequest> GetQueryBuilder(ChangeLogRequest request)
|
||||
{
|
||||
var builder = new ChangeLogQueryBuilder(this, request);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ -311,11 +349,9 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
|
||||
Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, TimeSpan.Zero)
|
||||
};
|
||||
|
||||
var builder = new ChangeLogRepositoryBuilder<TEntity, TDto, TRequest>(this, changeLogRequest);
|
||||
builder.ApplyRequest(request, token);
|
||||
|
||||
var offset = GetTimezoneOffset(request);
|
||||
var dtos = await builder.GetData(offset, token);
|
||||
var builder = GetQueryBuilder(changeLogRequest)
|
||||
.ApplyRequest(request);
|
||||
var dtos = await builder.GetData(token);
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
@ -172,11 +172,11 @@ public abstract class ProcessMapPlanBaseController<TEntity, TDto> : ControllerBa
|
||||
Moment = moment
|
||||
};
|
||||
|
||||
var builder = repository.GetRequestBuilder(changeLogRequest);
|
||||
builder.ApplyRequest(dataRequest, token);
|
||||
var builder = repository
|
||||
.GetQueryBuilder(changeLogRequest)
|
||||
.ApplyRequest(dataRequest);
|
||||
|
||||
var offset = wellService.GetTimezone(idWell).Offset;
|
||||
var dtos = await builder.GetChangeLogData(offset, token);
|
||||
var dtos = await builder.GetChangeLogData(token);
|
||||
|
||||
return Ok(dtos);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user