Skip to content

Commit

Permalink
Merge pull request #27 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Support for Filter and readablequesry controller
  • Loading branch information
Ali-YousefiTelori authored Aug 17, 2023
2 parents 1ce5b0f + fa19d41 commit afa2879
Show file tree
Hide file tree
Showing 14 changed files with 377 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.17</Version>
<Version>0.0.0.18</Version>
<Description>asp core servces.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base,database,services,asp,aspnet</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TFilterContract"></typeparam>
/// <typeparam name="TResponseContract"></typeparam>
/// <typeparam name="TId"></typeparam>
[ApiController]
[Route("api/[controller]/[action]")]
public class ReadableQueryServiceController<TEntity, TFilterContract, TResponseContract, TId> : ControllerBase
where TFilterContract : FilterRequestContract
{
/// <summary>
///
/// </summary>
protected IContractReadableLogic<TEntity, TResponseContract, TId> ContractLogic { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="contractReadable"></param>
public ReadableQueryServiceController(IContractReadableLogic<TEntity, TResponseContract, TId> contractReadable)
{
ContractLogic = contractReadable;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<MessageContract<TResponseContract>> GetById(GetIdRequestContract<TId> request, CancellationToken cancellationToken = default)
{
return ContractLogic.GetById(request, OnGetQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<MessageContract<TResponseContract>> GetByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.GetByUniqueIdentity(request, OnGetQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="filterRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<ListMessageContract<TResponseContract>> Filter(TFilterContract filterRequest, CancellationToken cancellationToken = default)
{
return ContractLogic.Filter(filterRequest, OnGetAllQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
public virtual Task<ListMessageContract<TResponseContract>> GetAll(CancellationToken cancellationToken = default)
{
return ContractLogic.GetAll(OnGetAllQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<ListMessageContract<TResponseContract>> GetAllByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.GetAllByUniqueIdentity(request, OnGetAllQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
protected virtual Func<IQueryable<TEntity>, IQueryable<TEntity>> OnGetQuery()
{
return null;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
protected virtual Func<IQueryable<TEntity>, IQueryable<TEntity>> OnGetAllQuery()
{
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,43 +19,17 @@ namespace EasyMicroservices.Cores.AspCoreApi
/// <typeparam name="TResponseContract"></typeparam>
[ApiController]
[Route("api/[controller]/[action]")]
public class SimpleQueryServiceController<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> : ControllerBase
public class SimpleQueryServiceController<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> : ReadableQueryServiceController<TEntity,FilterRequestContract,TResponseContract,TId>
{
private readonly IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> writableContractLogic;
/// <summary>
///
/// </summary>
protected IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> ContractLogic { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="contractReadable"></param>
public SimpleQueryServiceController(IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> contractReadable)
{
ContractLogic = contractReadable;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<MessageContract<TResponseContract>> GetById(GetIdRequestContract<TId> request, CancellationToken cancellationToken = default)
/// <param name="contractLogic"></param>
public SimpleQueryServiceController(IContractLogic<TEntity, TCreateRequestContract, TUpdateRequestContract, TResponseContract, TId> contractLogic):base(contractLogic)
{
return ContractLogic.GetById(request, OnGetQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<MessageContract<TResponseContract>> GetByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.GetByUniqueIdentity(request, OnGetQuery(), cancellationToken);
writableContractLogic = contractLogic;
}

/// <summary>
Expand All @@ -68,7 +41,7 @@ public virtual Task<MessageContract<TResponseContract>> GetByUniqueIdentity(GetU
[HttpPost]
public virtual Task<MessageContract<TId>> Add(TCreateRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.Add(request, cancellationToken);
return writableContractLogic.Add(request, cancellationToken);
}

/// <summary>
Expand All @@ -80,7 +53,7 @@ public virtual Task<MessageContract<TId>> Add(TCreateRequestContract request, Ca
[HttpPut]
public virtual Task<MessageContract<TResponseContract>> Update(TUpdateRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.Update(request, cancellationToken);
return writableContractLogic.Update(request, cancellationToken);
}

/// <summary>
Expand All @@ -92,7 +65,7 @@ public virtual Task<MessageContract<TResponseContract>> Update(TUpdateRequestCon
[HttpDelete]
public virtual Task<MessageContract> HardDeleteById(DeleteRequestContract<TId> request, CancellationToken cancellationToken = default)
{
return ContractLogic.HardDeleteById(request, cancellationToken);
return writableContractLogic.HardDeleteById(request, cancellationToken);
}

/// <summary>
Expand All @@ -104,48 +77,7 @@ public virtual Task<MessageContract> HardDeleteById(DeleteRequestContract<TId> r
[HttpDelete]
public virtual Task<MessageContract> SoftDeleteById(SoftDeleteRequestContract<TId> request, CancellationToken cancellationToken = default)
{
return ContractLogic.SoftDeleteById(request, cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet]
public virtual Task<MessageContract<List<TResponseContract>>> GetAll(CancellationToken cancellationToken = default)
{
return ContractLogic.GetAll(OnGetAllQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost]
public virtual Task<MessageContract<List<TResponseContract>>> GetAllByUniqueIdentity(GetUniqueIdentityRequestContract request, CancellationToken cancellationToken = default)
{
return ContractLogic.GetAllByUniqueIdentity(request, OnGetAllQuery(), cancellationToken);
}

/// <summary>
///
/// </summary>
/// <returns></returns>
protected virtual Func<IQueryable<TEntity>, IQueryable<TEntity>> OnGetQuery()
{
return null;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
protected virtual Func<IQueryable<TEntity>, IQueryable<TEntity>> OnGetAllQuery()
{
return null;
return writableContractLogic.SoftDeleteById(request, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;

namespace EasyMicroservices.Cores.Contracts.Requests
{
/// <summary>
///
/// </summary>
public class FilterRequestContract
{
/// <summary>
///
/// </summary>
public bool? IsDeleted { get; set; }
/// <summary>
///
/// </summary>
public DateTime? FromDeletedDateTime { get; set; }
/// <summary>
///
/// </summary>
public DateTime? ToDeletedDateTime { get; set; }

/// <summary>
///
/// </summary>
public DateTime? FromCreationDateTime { get; set; }
/// <summary>
///
/// </summary>
public DateTime? ToCreationDateTime { get; set; }

/// <summary>
///
/// </summary>
public DateTime? FromModificationDateTime { get; set; }
/// <summary>
///
/// </summary>
public DateTime? ToModificationDateTime { get; set; }
/// <summary>
///
/// </summary>
public string UniqueIdentity { get; set; }
/// <summary>
///
/// </summary>
public long? Index { get; set; }
/// <summary>
///
/// </summary>
public long? Length { get; set; }
/// <summary>
///
/// </summary>
public string SortColumnName { get; set; }
/// <summary>
///
/// </summary>
public bool IsDescending { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.4</Version>
<Description>core.</Description>
<Version>0.0.0.5</Version>
<Description>core contracts.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>core,cores,base</PackageTags>
<PackageTags>core,cores,base,contract,contracts,dto,dtos</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Cores</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public interface IReadableLogic<TResultSchema, TId>
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageContract<List<TResultSchema>>> GetAll(CancellationToken cancellationToken = default);
Task<ListMessageContract<TResultSchema>> GetAll(CancellationToken cancellationToken = default);
/// <summary>
///
/// </summary>
/// <param name="filterRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<ListMessageContract<TResultSchema>> Filter(FilterRequestContract filterRequest, CancellationToken cancellationToken = default);
}

/// <summary>
Expand Down Expand Up @@ -65,21 +72,29 @@ public interface IContractReadableLogic<TEntity, TContract, TId> : IReadableLogi
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageContract<TContract>> GetByUniqueIdentity(IUniqueIdentitySchema request, Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);
/// <summary>
///
/// </summary>
/// <param name="filterRequest"></param>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<ListMessageContract<TContract>> Filter(FilterRequestContract filterRequest, Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);

/// <summary>
///
/// </summary>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageContract<List<TContract>>> GetAll(Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);
Task<ListMessageContract<TContract>> GetAll(Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <param name="query"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageContract<List<TContract>>> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);
Task<ListMessageContract<TContract>> GetAllByUniqueIdentity(IUniqueIdentitySchema request, Func<IQueryable<TEntity>, IQueryable<TEntity>> query = default, CancellationToken cancellationToken = default);
}
}
Loading

0 comments on commit afa2879

Please sign in to comment.