2023-10-02 11:25:45 -04:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using PoweredSoft.CQRS.Abstractions;
|
2021-02-04 21:09:29 -05:00
|
|
|
|
using PoweredSoft.CQRS.AspNetCore.Mvc;
|
2021-02-02 19:01:29 -05:00
|
|
|
|
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
|
|
|
|
|
using PoweredSoft.DynamicQuery.Core;
|
|
|
|
|
|
|
|
|
|
namespace PoweredSoft.CQRS.DynamicQuery.AspNetCore.Mvc
|
|
|
|
|
{
|
|
|
|
|
[ApiController, Route("api/query/[controller]")]
|
2023-10-02 11:25:45 -04:00
|
|
|
|
public class DynamicQueryController<TSource, TDestination> : Controller
|
2021-02-02 19:01:29 -05:00
|
|
|
|
where TSource : class
|
|
|
|
|
where TDestination : class
|
|
|
|
|
{
|
2021-02-04 21:09:29 -05:00
|
|
|
|
[HttpPost, QueryControllerAuthorization]
|
2021-02-02 19:01:29 -05:00
|
|
|
|
public async Task<IQueryExecutionResult<TDestination>> HandleAsync(
|
|
|
|
|
[FromBody] DynamicQuery<TSource, TDestination> query,
|
2023-10-02 11:25:45 -04:00
|
|
|
|
[FromServices]IQueryHandler<IDynamicQuery<TSource, TDestination>, IQueryExecutionResult<TDestination>> queryHandler
|
2021-02-02 19:01:29 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-05 14:05:18 -05:00
|
|
|
|
|
|
|
|
|
[HttpGet, QueryControllerAuthorization]
|
|
|
|
|
public async Task<IQueryExecutionResult<TDestination>> HandleGetAsync(
|
|
|
|
|
[FromQuery] DynamicQuery<TSource, TDestination> query,
|
2023-10-02 11:25:45 -04:00
|
|
|
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination>, IQueryExecutionResult<TDestination>> queryHandler
|
2021-02-05 14:05:18 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-02 19:01:29 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiController, Route("api/query/[controller]")]
|
2023-10-02 11:25:45 -04:00
|
|
|
|
public class DynamicQueryController<TSource, TDestination, TParams> : Controller
|
2021-02-02 19:01:29 -05:00
|
|
|
|
where TSource : class
|
|
|
|
|
where TDestination : class
|
|
|
|
|
where TParams : class
|
|
|
|
|
{
|
2021-02-04 21:09:29 -05:00
|
|
|
|
[HttpPost, QueryControllerAuthorization]
|
2021-02-02 19:01:29 -05:00
|
|
|
|
public async Task<IQueryExecutionResult<TDestination>> HandleAsync(
|
|
|
|
|
[FromBody] DynamicQuery<TSource, TDestination, TParams> query,
|
2023-10-02 11:25:45 -04:00
|
|
|
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination, TParams>, IQueryExecutionResult<TDestination>> queryHandler
|
2021-02-02 19:01:29 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-05 14:05:18 -05:00
|
|
|
|
|
|
|
|
|
[HttpGet, QueryControllerAuthorization]
|
|
|
|
|
public async Task<IQueryExecutionResult<TDestination>> HandleGetAsync(
|
|
|
|
|
[FromQuery] DynamicQuery<TSource, TDestination, TParams> query,
|
2023-10-02 11:25:45 -04:00
|
|
|
|
[FromServices] IQueryHandler<IDynamicQuery<TSource, TDestination, TParams>, IQueryExecutionResult<TDestination>> queryHandler
|
2021-02-05 14:05:18 -05:00
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-02-02 19:01:29 -05:00
|
|
|
|
}
|
|
|
|
|
}
|