From bddf4eec25a113b52bdc774fdeb5580891945b52 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Tue, 2 Feb 2021 13:36:24 -0500 Subject: [PATCH] advance query started, next step is to see how to implement the differences between aspnetcore and eventual gql. --- .../IAggregatableQuery.cs | 10 +++ .../IFilterableQuery.cs | 12 ++++ .../IGroupableQuery.cs | 10 +++ .../IPageableQuery.cs | 11 +++ .../ISortableQuery.cs | 10 +++ ...weredSoft.AdvanceQuery.Abstractions.csproj | 11 +++ .../AdvanceQueryHandlerBase.cs | 68 +++++++++++++++++++ .../PoweredSoft.CQRS.AdvanceQuery.csproj | 15 ++++ PoweredSoft.CQRS.sln | 12 ++++ 9 files changed, 159 insertions(+) create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs create mode 100644 PoweredSoft.AdvanceQuery.Abstractions/PoweredSoft.AdvanceQuery.Abstractions.csproj create mode 100644 PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs create mode 100644 PoweredSoft.CQRS.AdvanceQuery/PoweredSoft.CQRS.AdvanceQuery.csproj diff --git a/PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs b/PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs new file mode 100644 index 0000000..4060e34 --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/IAggregatableQuery.cs @@ -0,0 +1,10 @@ +using PoweredSoft.DynamicQuery.Core; +using System.Collections.Generic; + +namespace PoweredSoft.AdvanceQuery.Abstractions +{ + public interface IAggregatableQuery + { + List GetAggregates(); + } +} diff --git a/PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs b/PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs new file mode 100644 index 0000000..c4a8c69 --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/IFilterableQuery.cs @@ -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 GetFilters(); + } +} diff --git a/PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs b/PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs new file mode 100644 index 0000000..9f2fd74 --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/IGroupableQuery.cs @@ -0,0 +1,10 @@ +using PoweredSoft.DynamicQuery.Core; +using System.Collections.Generic; + +namespace PoweredSoft.AdvanceQuery.Abstractions +{ + public interface IGroupableQuery + { + List GetGroups(); + } +} diff --git a/PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs b/PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs new file mode 100644 index 0000000..ea921bc --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/IPageableQuery.cs @@ -0,0 +1,11 @@ +using System; + +namespace PoweredSoft.AdvanceQuery.Abstractions +{ + + public interface IPageableQuery + { + int? GetPage(); + int? GetPageSize(); + } +} diff --git a/PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs b/PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs new file mode 100644 index 0000000..a064d77 --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/ISortableQuery.cs @@ -0,0 +1,10 @@ +using PoweredSoft.DynamicQuery.Core; +using System.Collections.Generic; + +namespace PoweredSoft.AdvanceQuery.Abstractions +{ + public interface ISortableQuery + { + List GetSorts(); + } +} diff --git a/PoweredSoft.AdvanceQuery.Abstractions/PoweredSoft.AdvanceQuery.Abstractions.csproj b/PoweredSoft.AdvanceQuery.Abstractions/PoweredSoft.AdvanceQuery.Abstractions.csproj new file mode 100644 index 0000000..6dc5922 --- /dev/null +++ b/PoweredSoft.AdvanceQuery.Abstractions/PoweredSoft.AdvanceQuery.Abstractions.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs b/PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs new file mode 100644 index 0000000..fb17d54 --- /dev/null +++ b/PoweredSoft.CQRS.AdvanceQuery/AdvanceQueryHandlerBase.cs @@ -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 + where TQuery : class + { + private readonly IQueryHandlerAsync queryHandlerAsync; + + protected AdvanceQueryHandlerBase(IQueryHandlerAsync queryHandlerAsync) + { + this.queryHandlerAsync = queryHandlerAsync; + } + + protected async Task> ProcessQuery(TQuery query, IQueryable 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(source, criteria, options, cancellationToken); + return result; + } + + protected virtual IEnumerable GetInterceptors(TQuery query) + { + return Enumerable.Empty(); + } + + 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; + } + } +} diff --git a/PoweredSoft.CQRS.AdvanceQuery/PoweredSoft.CQRS.AdvanceQuery.csproj b/PoweredSoft.CQRS.AdvanceQuery/PoweredSoft.CQRS.AdvanceQuery.csproj new file mode 100644 index 0000000..b999a35 --- /dev/null +++ b/PoweredSoft.CQRS.AdvanceQuery/PoweredSoft.CQRS.AdvanceQuery.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + + + + + + + + + + diff --git a/PoweredSoft.CQRS.sln b/PoweredSoft.CQRS.sln index 0271202..5a9f39d 100644 --- a/PoweredSoft.CQRS.sln +++ b/PoweredSoft.CQRS.sln @@ -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