advance query started, next step is to see how to implement the differences between aspnetcore and eventual gql.
This commit is contained in:
parent
73e3f6b8a4
commit
bddf4eec25
10
PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs
Normal file
10
PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PoweredSoft.AdvanceQuery.Abstractions
|
||||
{
|
||||
public interface IAggregatableQuery
|
||||
{
|
||||
List<IAggregate> GetAggregates();
|
||||
}
|
||||
}
|
12
PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs
Normal file
12
PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace PoweredSoft.AdvanceQuery.Abstractions
|
||||
{
|
||||
public interface IFilterableQuery
|
||||
{
|
||||
List<IFilter> GetFilters();
|
||||
}
|
||||
}
|
10
PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs
Normal file
10
PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PoweredSoft.AdvanceQuery.Abstractions
|
||||
{
|
||||
public interface IGroupableQuery
|
||||
{
|
||||
List<IGroup> GetGroups();
|
||||
}
|
||||
}
|
11
PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs
Normal file
11
PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace PoweredSoft.AdvanceQuery.Abstractions
|
||||
{
|
||||
|
||||
public interface IPageableQuery
|
||||
{
|
||||
int? GetPage();
|
||||
int? GetPageSize();
|
||||
}
|
||||
}
|
10
PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs
Normal file
10
PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PoweredSoft.AdvanceQuery.Abstractions
|
||||
{
|
||||
public interface ISortableQuery
|
||||
{
|
||||
List<ISort> GetSorts();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PoweredSoft.DynamicQuery.Core" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
68
PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs
Normal file
68
PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using PoweredSoft.AdvanceQuery.Abstractions;
|
||||
using PoweredSoft.DynamicQuery;
|
||||
using PoweredSoft.DynamicQuery.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PoweredSoft.CQRS.AdvanceQuery
|
||||
{
|
||||
public abstract class AdvanceQueryHandlerBase<TQuery, TSource, TDestination>
|
||||
where TQuery : class
|
||||
{
|
||||
private readonly IQueryHandlerAsync queryHandlerAsync;
|
||||
|
||||
protected AdvanceQueryHandlerBase(IQueryHandlerAsync queryHandlerAsync)
|
||||
{
|
||||
this.queryHandlerAsync = queryHandlerAsync;
|
||||
}
|
||||
|
||||
protected async Task<IQueryExecutionResult<TDestination>> ProcessQuery(TQuery query, IQueryable<TSource> source,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var criteria = CreateCriteria(query);
|
||||
var options = GetOptions(query);
|
||||
var interceptors = GetInterceptors(query);
|
||||
|
||||
foreach (var interceptor in interceptors)
|
||||
queryHandlerAsync.AddInterceptor(interceptor);
|
||||
|
||||
var result = await queryHandlerAsync.ExecuteAsync<TSource, TDestination>(source, criteria, options, cancellationToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<IQueryInterceptor> GetInterceptors(TQuery query)
|
||||
{
|
||||
return Enumerable.Empty<IQueryInterceptor>();
|
||||
}
|
||||
|
||||
protected virtual IQueryExecutionOptions GetOptions(TQuery query)
|
||||
{
|
||||
return new QueryExecutionOptions();
|
||||
}
|
||||
|
||||
protected virtual IQueryCriteria CreateCriteria(TQuery query)
|
||||
{
|
||||
var ret = new QueryCriteria();
|
||||
|
||||
if (query is IPageableQuery pageableQuery)
|
||||
{
|
||||
ret.Page = pageableQuery.GetPage();
|
||||
ret.PageSize = pageableQuery.GetPageSize();
|
||||
}
|
||||
|
||||
if (query is IFilterableQuery filterableQuery)
|
||||
ret.Filters = filterableQuery.GetFilters();
|
||||
|
||||
if (query is IGroupableQuery groupableQuery)
|
||||
ret.Groups = groupableQuery.GetGroups();
|
||||
|
||||
if (query is IAggregatableQuery aggregatableQuery)
|
||||
ret.Aggregates = aggregatableQuery.GetAggregates();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PoweredSoft.DynamicQuery" Version="2.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PoweredSoft.AdvanceQuery.Abstractions\PoweredSoft.AdvanceQuery.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -19,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.CQRS.AdvanceQuery", "PoweredSoft.CQRS.AdvanceQuery\PoweredSoft.CQRS.AdvanceQuery.csproj", "{7A6DCAD7-4C01-426A-86AB-2F9AC5F19FB5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoweredSoft.AdvanceQuery.Abstractions", "PoweredSoft.AdvanceQuery.Abstractions\PoweredSoft.AdvanceQuery.Abstractions.csproj", "{FEE14DBC-7D3F-4805-8080-918CD5D52C7D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -45,6 +49,14 @@ Global
|
||||
{F15B1E11-8D4C-489E-AFF7-AA144105FE46}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F15B1E11-8D4C-489E-AFF7-AA144105FE46}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F15B1E11-8D4C-489E-AFF7-AA144105FE46}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7A6DCAD7-4C01-426A-86AB-2F9AC5F19FB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7A6DCAD7-4C01-426A-86AB-2F9AC5F19FB5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7A6DCAD7-4C01-426A-86AB-2F9AC5F19FB5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7A6DCAD7-4C01-426A-86AB-2F9AC5F19FB5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FEE14DBC-7D3F-4805-8080-918CD5D52C7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FEE14DBC-7D3F-4805-8080-918CD5D52C7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FEE14DBC-7D3F-4805-8080-918CD5D52C7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FEE14DBC-7D3F-4805-8080-918CD5D52C7D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user