dotnet-cqrs/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryController.cs

63 lines
2.6 KiB
C#
Raw Normal View History

2023-10-02 11:25:45 -04:00
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using PoweredSoft.CQRS.Abstractions;
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
{
[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
{
[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
}
}