From fa19d41fa58db717857646107076250be961aee5 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Thu, 17 Aug 2023 16:08:05 +0330 Subject: [PATCH] Support for Filter and readablequesry controller --- .../EasyMicroservices.Cores.AspCoreApi.csproj | 2 +- .../ReadableQueryServiceController.cs | 116 ++++++++++++++++++ .../SimpleQueryServiceController.cs | 86 ++----------- .../Requests/FilterRequestContract.cs | 61 +++++++++ .../EasyMicroservices.Cores.Contracts.csproj | 6 +- .../Database/Interfaces/IReadableLogic.cs | 21 +++- .../Database/Logics/DatabaseLogicBase.cs | 30 ++++- .../Logics/DatabaseLogicInfrastructure.cs | 79 +++++++++++- .../Logics/DatabaseMappedLogicBase.cs | 35 +++++- .../Logics/IdSchemaDatabaseMappedLogicBase.cs | 33 ++++- .../EasyMicroservices.Cores.Database.csproj | 2 +- ...oservices.Cores.EntityFrameworkCore.csproj | 2 +- ...ores.Relational.EntityFrameworkCore.csproj | 2 +- .../LongIdMappedDatabaseLogicBaseTest.cs | 5 + 14 files changed, 377 insertions(+), 103 deletions(-) create mode 100644 src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs create mode 100644 src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj index 1c412e2..2f301c2 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/EasyMicroservices.Cores.AspCoreApi.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.17 + 0.0.0.18 asp core servces. EasyMicroservices@gmail.com core,cores,base,database,services,asp,aspnet diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs new file mode 100644 index 0000000..99a8b00 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/ReadableQueryServiceController.cs @@ -0,0 +1,116 @@ +using EasyMicroservices.Cores.Contracts.Requests; +using EasyMicroservices.Cores.Database.Interfaces; +using EasyMicroservices.ServiceContracts; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace EasyMicroservices.Cores.AspCoreApi +{ + /// + /// + /// + /// + /// + /// + /// + [ApiController] + [Route("api/[controller]/[action]")] + public class ReadableQueryServiceController : ControllerBase + where TFilterContract : FilterRequestContract + { + /// + /// + /// + protected IContractReadableLogic ContractLogic { get; private set; } + /// + /// + /// + /// + public ReadableQueryServiceController(IContractReadableLogic contractReadable) + { + ContractLogic = contractReadable; + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual Task> GetById(GetIdRequestContract request, CancellationToken cancellationToken = default) + { + return ContractLogic.GetById(request, OnGetQuery(), cancellationToken); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual Task> GetByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + { + return ContractLogic.GetByUniqueIdentity(request, OnGetQuery(), cancellationToken); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual Task> Filter(TFilterContract filterRequest, CancellationToken cancellationToken = default) + { + return ContractLogic.Filter(filterRequest, OnGetAllQuery(), cancellationToken); + } + + /// + /// + /// + /// + /// + [HttpGet] + public virtual Task> GetAll(CancellationToken cancellationToken = default) + { + return ContractLogic.GetAll(OnGetAllQuery(), cancellationToken); + } + + /// + /// + /// + /// + /// + /// + [HttpPost] + public virtual Task> GetAllByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) + { + return ContractLogic.GetAllByUniqueIdentity(request, OnGetAllQuery(), cancellationToken); + } + + /// + /// + /// + /// + protected virtual Func, IQueryable> OnGetQuery() + { + return null; + } + + /// + /// + /// + /// + protected virtual Func, IQueryable> OnGetAllQuery() + { + return null; + } + } +} \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs index 226e250..7669e7f 100644 --- a/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs +++ b/src/CSharp/EasyMicroservices.Cores.AspCoreApi/SimpleQueryServiceController.cs @@ -3,7 +3,6 @@ using EasyMicroservices.ServiceContracts; using Microsoft.AspNetCore.Mvc; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -20,43 +19,17 @@ namespace EasyMicroservices.Cores.AspCoreApi /// [ApiController] [Route("api/[controller]/[action]")] - public class SimpleQueryServiceController : ControllerBase + public class SimpleQueryServiceController : ReadableQueryServiceController { + private readonly IContractLogic writableContractLogic; /// /// - /// - protected IContractLogic ContractLogic { get; private set; } - /// - /// - /// - /// - public SimpleQueryServiceController(IContractLogic contractReadable) - { - ContractLogic = contractReadable; - } - - /// /// /// - /// - /// - /// - [HttpPost] - public virtual Task> GetById(GetIdRequestContract request, CancellationToken cancellationToken = default) + /// + public SimpleQueryServiceController(IContractLogic contractLogic):base(contractLogic) { - return ContractLogic.GetById(request, OnGetQuery(), cancellationToken); - } - - /// - /// - /// - /// - /// - /// - [HttpPost] - public virtual Task> GetByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) - { - return ContractLogic.GetByUniqueIdentity(request, OnGetQuery(), cancellationToken); + writableContractLogic = contractLogic; } /// @@ -68,7 +41,7 @@ public virtual Task> GetByUniqueIdentity(GetU [HttpPost] public virtual Task> Add(TCreateRequestContract request, CancellationToken cancellationToken = default) { - return ContractLogic.Add(request, cancellationToken); + return writableContractLogic.Add(request, cancellationToken); } /// @@ -80,7 +53,7 @@ public virtual Task> Add(TCreateRequestContract request, Ca [HttpPut] public virtual Task> Update(TUpdateRequestContract request, CancellationToken cancellationToken = default) { - return ContractLogic.Update(request, cancellationToken); + return writableContractLogic.Update(request, cancellationToken); } /// @@ -92,7 +65,7 @@ public virtual Task> Update(TUpdateRequestCon [HttpDelete] public virtual Task HardDeleteById(DeleteRequestContract request, CancellationToken cancellationToken = default) { - return ContractLogic.HardDeleteById(request, cancellationToken); + return writableContractLogic.HardDeleteById(request, cancellationToken); } /// @@ -104,48 +77,7 @@ public virtual Task HardDeleteById(DeleteRequestContract r [HttpDelete] public virtual Task SoftDeleteById(SoftDeleteRequestContract request, CancellationToken cancellationToken = default) { - return ContractLogic.SoftDeleteById(request, cancellationToken); - } - - /// - /// - /// - /// - /// - [HttpGet] - public virtual Task>> GetAll(CancellationToken cancellationToken = default) - { - return ContractLogic.GetAll(OnGetAllQuery(), cancellationToken); - } - - /// - /// - /// - /// - /// - /// - [HttpPost] - public virtual Task>> GetAllByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default) - { - return ContractLogic.GetAllByUniqueIdentity(request, OnGetAllQuery(), cancellationToken); - } - - /// - /// - /// - /// - protected virtual Func, IQueryable> OnGetQuery() - { - return null; - } - - /// - /// - /// - /// - protected virtual Func, IQueryable> OnGetAllQuery() - { - return null; + return writableContractLogic.SoftDeleteById(request, cancellationToken); } } } \ No newline at end of file diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs new file mode 100644 index 0000000..8e0d258 --- /dev/null +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/Contracts/Requests/FilterRequestContract.cs @@ -0,0 +1,61 @@ +using System; + +namespace EasyMicroservices.Cores.Contracts.Requests +{ + /// + /// + /// + public class FilterRequestContract + { + /// + /// + /// + public bool? IsDeleted { get; set; } + /// + /// + /// + public DateTime? FromDeletedDateTime { get; set; } + /// + /// + /// + public DateTime? ToDeletedDateTime { get; set; } + + /// + /// + /// + public DateTime? FromCreationDateTime { get; set; } + /// + /// + /// + public DateTime? ToCreationDateTime { get; set; } + + /// + /// + /// + public DateTime? FromModificationDateTime { get; set; } + /// + /// + /// + public DateTime? ToModificationDateTime { get; set; } + /// + /// + /// + public string UniqueIdentity { get; set; } + /// + /// + /// + public long? Index { get; set; } + /// + /// + /// + public long? Length { get; set; } + /// + /// + /// + public string SortColumnName { get; set; } + /// + /// + /// + public bool IsDescending { get; set; } + } +} diff --git a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj index 2590a51..bde1388 100644 --- a/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Contracts/EasyMicroservices.Cores.Contracts.csproj @@ -5,10 +5,10 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.4 - core. + 0.0.0.5 + core contracts. EasyMicroservices@gmail.com - core,cores,base + core,cores,base,contract,contracts,dto,dtos https://github.com/EasyMicroservices/Cores latest true diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs index 7ece1a9..0f02f9e 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Interfaces/IReadableLogic.cs @@ -29,7 +29,14 @@ public interface IReadableLogic /// /// /// - Task>> GetAll(CancellationToken cancellationToken = default); + Task> GetAll(CancellationToken cancellationToken = default); + /// + /// + /// + /// + /// + /// + Task> Filter(FilterRequestContract filterRequest, CancellationToken cancellationToken = default); } /// @@ -65,6 +72,14 @@ public interface IContractReadableLogic : IReadableLogi /// /// Task> GetByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = default, CancellationToken cancellationToken = default); + /// + /// + /// + /// + /// + /// + /// + Task> Filter(FilterRequestContract filterRequest, Func, IQueryable> query = default, CancellationToken cancellationToken = default); /// /// @@ -72,7 +87,7 @@ public interface IContractReadableLogic : IReadableLogi /// /// /// - Task>> GetAll(Func, IQueryable> query = default, CancellationToken cancellationToken = default); + Task> GetAll(Func, IQueryable> query = default, CancellationToken cancellationToken = default); /// /// /// @@ -80,6 +95,6 @@ public interface IContractReadableLogic : IReadableLogi /// /// /// - Task>> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = default, CancellationToken cancellationToken = default); + Task> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = default, CancellationToken cancellationToken = default); } } diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs index 8406809..aa3ded6 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicBase.cs @@ -90,7 +90,7 @@ public async Task> GetById(GetIdRequestContract id /// /// /// - public async Task>> GetAll(CancellationToken cancellationToken = default) + public async Task> GetAll(CancellationToken cancellationToken = default) { return await GetAll(_easyReadableQueryable, null, cancellationToken); } @@ -101,7 +101,7 @@ public async Task>> GetAll(CancellationToken cance /// /// /// - public async Task>> GetAll(Func, IQueryable> query = default, CancellationToken cancellationToken = default) + public async Task> GetAll(Func, IQueryable> query = default, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) @@ -109,6 +109,32 @@ public async Task>> GetAll(Func + /// + /// + /// + /// + /// + /// + public Task> Filter(FilterRequestContract filterRequest, Func, IQueryable> query = null, CancellationToken cancellationToken = default) + { + Func, IEasyReadableQueryableAsync> func = null; + if (query != null) + func = (q) => _easyReadableQueryable.ConvertToReadable(query(_easyReadableQueryable)); + return Filter(filterRequest, _easyReadableQueryable, func, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + public Task> Filter(FilterRequestContract filterRequest, CancellationToken cancellationToken = default) + { + return Filter(filterRequest, _easyReadableQueryable, null, cancellationToken); + } + /// /// /// diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs index 1f14064..20ae671 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseLogicInfrastructure.cs @@ -5,9 +5,9 @@ using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -223,11 +223,78 @@ public async Task> GetByUniqueIdentity /// + /// /// /// /// /// - protected async Task>> GetAll(IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + protected async Task> Filter(FilterRequestContract filterRequest, IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + where TEntity : class + { + IEasyReadableQueryableAsync queryable = easyReadableQueryable; + if (query != null) + queryable = query(queryable); + + if (filterRequest.Index.HasValue) + queryable = queryable.ConvertToReadable(queryable.Skip((int)filterRequest.Index.Value)); + if (filterRequest.Length.HasValue) + queryable = queryable.ConvertToReadable(queryable.Take((int)filterRequest.Length.Value)); + + if (filterRequest.UniqueIdentity.HasValue() && typeof(IUniqueIdentitySchema).IsAssignableFrom(typeof(TEntity))) + queryable = UniqueIdentityQueryMaker(easyReadableQueryable, filterRequest.UniqueIdentity); + + if (filterRequest.FromCreationDateTime.HasValue && typeof(IDateTimeSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as IDateTimeSchema).CreationDateTime >= filterRequest.FromCreationDateTime)); + if (filterRequest.ToCreationDateTime.HasValue && typeof(IDateTimeSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as IDateTimeSchema).CreationDateTime <= filterRequest.ToCreationDateTime)); + + if (filterRequest.FromModificationDateTime.HasValue && typeof(IDateTimeSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as IDateTimeSchema).ModificationDateTime >= filterRequest.FromModificationDateTime)); + if (filterRequest.ToModificationDateTime.HasValue && typeof(IDateTimeSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as IDateTimeSchema).ModificationDateTime <= filterRequest.ToModificationDateTime)); + + if (filterRequest.FromDeletedDateTime.HasValue && typeof(ISoftDeleteSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as ISoftDeleteSchema).DeletedDateTime >= filterRequest.FromDeletedDateTime)); + if (filterRequest.ToDeletedDateTime.HasValue && typeof(ISoftDeleteSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as ISoftDeleteSchema).DeletedDateTime <= filterRequest.ToDeletedDateTime)); + + if (filterRequest.IsDeleted.HasValue && typeof(ISoftDeleteSchema).IsAssignableFrom(typeof(TEntity))) + queryable = queryable.ConvertToReadable(queryable.Where(x => (x as ISoftDeleteSchema).IsDeleted == filterRequest.IsDeleted)); + + return await queryable.ToListAsync(cancellationToken); + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected async Task> Filter(FilterRequestContract filterRequest, IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + where TEntity : class + where TContract : class + { + var entityResult = await Filter(filterRequest, easyReadableQueryable, query, cancellationToken); + if (!entityResult) + return entityResult.ToAnotherListContract(); + var result = await _mapperProvider.MapToListAsync(entityResult.Result); + ValidateMappedResult(ref result); + return result; + } + + /// + /// get all items + /// + /// + /// + /// + /// + /// + protected async Task> GetAll(IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) where TEntity : class { IEasyReadableQueryableAsync queryable = easyReadableQueryable; @@ -249,13 +316,13 @@ protected async Task>> GetAll(IEasyReadab /// /// /// - protected async Task>> GetAll(IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) + protected async Task> GetAll(IEasyReadableQueryableAsync easyReadableQueryable, Func, IEasyReadableQueryableAsync> query = default, CancellationToken cancellationToken = default) where TEntity : class where TContract : class { var entityResult = await GetAll(easyReadableQueryable, query, cancellationToken); if (!entityResult) - return entityResult.ToContract>(); + return entityResult.ToAnotherListContract(); var result = await _mapperProvider.MapToListAsync(entityResult.Result); ValidateMappedResult(ref result); return result; @@ -272,14 +339,14 @@ protected async Task>> GetAll /// /// - public async Task>> GetAllByUniqueIdentity(IEasyReadableQueryableAsync easyReadableQueryable, IUniqueIdentitySchema request, Func, IEasyReadableQueryableAsync> query = null, CancellationToken cancellationToken = default) + public async Task> GetAllByUniqueIdentity(IEasyReadableQueryableAsync easyReadableQueryable, IUniqueIdentitySchema request, Func, IEasyReadableQueryableAsync> query = null, CancellationToken cancellationToken = default) where TEntity : class where TContract : class { IEasyReadableQueryableAsync queryable = UniqueIdentityQueryMaker(easyReadableQueryable, request.UniqueIdentity); var entityResult = await GetAll(queryable, query, cancellationToken); if (!entityResult) - return entityResult.ToContract>(); + return entityResult.ToAnotherListContract(); var result = await _mapperProvider.MapToListAsync(entityResult.Result); ValidateMappedResult(ref result); return result; diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs index 9d72761..6d8065a 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/DatabaseMappedLogicBase.cs @@ -5,7 +5,6 @@ using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -67,7 +66,7 @@ public DatabaseMappedLogicBase(IEasyReadableQueryableAsync easyReadable /// /// /// - public async Task>> GetAll(CancellationToken cancellationToken = default) + public async Task> GetAll(CancellationToken cancellationToken = default) { return await GetAll(_easyReadableQueryable, null, cancellationToken); } @@ -131,11 +130,39 @@ public Task> AddEntity(TEntity entity, CancellationToke /// /// /// + /// /// /// /// /// - public async Task>> GetAll(Func, IQueryable> query = null, CancellationToken cancellationToken = default) + public Task> Filter(FilterRequestContract filterRequest, Func, IQueryable> query = null, CancellationToken cancellationToken = default) + { + Func, IEasyReadableQueryableAsync> func = null; + if (query != null) + func = (q) => _easyReadableQueryable.ConvertToReadable(query(_easyReadableQueryable)); + return Filter(filterRequest, _easyReadableQueryable, func, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + /// + public Task> Filter(FilterRequestContract filterRequest, CancellationToken cancellationToken = default) + { + return Filter(filterRequest, _easyReadableQueryable, null, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + /// + public async Task> GetAll(Func, IQueryable> query = null, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) @@ -231,7 +258,7 @@ public Task> GetByUniqueIdentity(IUniqueIdent /// /// /// - public Task>> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = null, CancellationToken cancellationToken = default) + public Task> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = null, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) diff --git a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs index 6382ae4..1463863 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs +++ b/src/CSharp/EasyMicroservices.Cores.Database/Database/Logics/IdSchemaDatabaseMappedLogicBase.cs @@ -5,7 +5,6 @@ using EasyMicroservices.Mapper.Interfaces; using EasyMicroservices.ServiceContracts; using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; @@ -68,7 +67,7 @@ public IdSchemaDatabaseMappedLogicBase(IEasyReadableQueryableAsync easy /// /// /// - public async Task>> GetAll(CancellationToken cancellationToken = default) + public async Task> GetAll(CancellationToken cancellationToken = default) { return await GetAll(_easyReadableQueryable, null, cancellationToken); } @@ -135,7 +134,7 @@ public Task> AddEntity(TEntity entity, CancellationToke /// /// /// - public async Task>> GetAll(Func, IQueryable> query = null, CancellationToken cancellationToken = default) + public async Task> GetAll(Func, IQueryable> query = null, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) @@ -143,6 +142,32 @@ public async Task>> GetAll(Func(_easyReadableQueryable, func, cancellationToken); } + /// + /// + /// + /// + /// + /// + /// + public Task> Filter(FilterRequestContract filterRequest, Func, IQueryable> query = null, CancellationToken cancellationToken = default) + { + Func, IEasyReadableQueryableAsync> func = null; + if (query != null) + func = (q) => _easyReadableQueryable.ConvertToReadable(query(_easyReadableQueryable)); + return Filter(filterRequest, _easyReadableQueryable, func, cancellationToken); + } + + /// + /// + /// + /// + /// + /// + public Task> Filter(FilterRequestContract filterRequest, CancellationToken cancellationToken = default) + { + return Filter(filterRequest, _easyReadableQueryable, null, cancellationToken); + } + /// /// /// @@ -229,7 +254,7 @@ public Task SoftDeleteById(SoftDeleteRequestContract delet /// /// /// - public Task>> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = null, CancellationToken cancellationToken = default) + public Task> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func, IQueryable> query = null, CancellationToken cancellationToken = default) { Func, IEasyReadableQueryableAsync> func = null; if (query != null) diff --git a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj index 8510a64..5af58b9 100644 --- a/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Database/EasyMicroservices.Cores.Database.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.19 + 0.0.0.20 core of database. EasyMicroservices@gmail.com core,cores,base,database diff --git a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj index 8f37a67..5005230 100644 --- a/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.EntityFrameworkCore/EasyMicroservices.Cores.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.10 + 0.0.0.11 ef core of database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore diff --git a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj index 2f6fae4..d03722d 100644 --- a/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj +++ b/src/CSharp/EasyMicroservices.Cores.Relational.EntityFrameworkCore/EasyMicroservices.Cores.Relational.EntityFrameworkCore.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.7 + 0.0.0.8 ef core of Relational database. EasyMicroservices@gmail.com core,cores,base,database,ef,efcore,Relational diff --git a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs index b5be1c6..664ee60 100644 --- a/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs +++ b/src/CSharp/EasyMicroservices.Cores.Tests/DatabaseLogics/LongIdMappedDatabaseLogicBaseTest.cs @@ -75,6 +75,11 @@ public async Task AddAsync(string userName) Assert.NotEmpty(foundUser.Result.UniqueIdentity); var allUsers = await logic.GetAll(); Assert.Contains(allUsers.Result, x => x.Id == user.Result); + var allFilterUsers = await logic.Filter(new FilterRequestContract() + { + IsDeleted = false + }); + Assert.True(allFilterUsers.Result.All(x => allUsers.Result.Any(i => x.Id == i.Id))); var ids = DefaultUniqueIdentityManager.DecodeUniqueIdentity(foundUser.Result.UniqueIdentity); Assert.Equal(ids.Last(), foundUser.Result.Id); Assert.Equal(TableContextId, ids[^2]);