62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
|
using System.Threading.Tasks;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using OpenHarbor.CQRS.Abstractions;
|
|||
|
using OpenHarbor.CQRS.AspNetCore.Mvc;
|
|||
|
using OpenHarbor.CQRS.DynamicQuery.Abstractions;
|
|||
|
using PoweredSoft.DynamicQuery.Core;
|
|||
|
|
|||
|
namespace OpenHarbor.CQRS.DynamicQuery.AspNetCore.Mvc;
|
|||
|
|
|||
|
[ApiController, Route("api/query/[controller]")]
|
|||
|
public class DynamicQueryController<TSource, TDestination> : Controller
|
|||
|
where TSource : class
|
|||
|
where TDestination : class
|
|||
|
{
|
|||
|
[HttpPost, QueryControllerAuthorization]
|
|||
|
public async Task<IQueryExecutionResult<TDestination>> HandleAsync(
|
|||
|
[FromBody] DynamicQuery<TSource, TDestination> query,
|
|||
|
[FromServices]IQueryHandler<IDynamicQuery<TSource, TDestination>, IQueryExecutionResult<TDestination>> queryHandler
|
|||
|
)
|
|||
|
{
|
|||
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet, QueryControllerAuthorization]
|
|||
|
public async Task<IQueryExecutionResult<TDestination>> HandleGetAsync(
|
|||
|
[FromQuery] DynamicQuery<TSource, TDestination> query,
|
|||
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination>, IQueryExecutionResult<TDestination>> queryHandler
|
|||
|
)
|
|||
|
{
|
|||
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[ApiController, Route("api/query/[controller]")]
|
|||
|
public class DynamicQueryController<TSource, TDestination, TParams> : Controller
|
|||
|
where TSource : class
|
|||
|
where TDestination : class
|
|||
|
where TParams : class
|
|||
|
{
|
|||
|
[HttpPost, QueryControllerAuthorization]
|
|||
|
public async Task<IQueryExecutionResult<TDestination>> HandleAsync(
|
|||
|
[FromBody] DynamicQuery<TSource, TDestination, TParams> query,
|
|||
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination, TParams>, IQueryExecutionResult<TDestination>> queryHandler
|
|||
|
)
|
|||
|
{
|
|||
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet, QueryControllerAuthorization]
|
|||
|
public async Task<IQueryExecutionResult<TDestination>> HandleGetAsync(
|
|||
|
[FromQuery] DynamicQuery<TSource, TDestination, TParams> query,
|
|||
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination, TParams>, IQueryExecutionResult<TDestination>> queryHandler
|
|||
|
)
|
|||
|
{
|
|||
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|