From cc0b01bfee6456bb2ca3c5d4e8ec670dce41fe41 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Fri, 5 Feb 2021 14:05:18 -0500 Subject: [PATCH] get support :) --- .../QueryODataController.cs | 4 ++-- .../Mvc/QueryController.cs | 11 ++++++++++ .../DynamicQueryFilter.cs | 16 ++++++++++++++- .../Mvc/DynamicQueryController.cs | 20 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/PoweredSoft.CQRS.AspNetCore.OData/QueryODataController.cs b/PoweredSoft.CQRS.AspNetCore.OData/QueryODataController.cs index 721c1d1..56feee5 100644 --- a/PoweredSoft.CQRS.AspNetCore.OData/QueryODataController.cs +++ b/PoweredSoft.CQRS.AspNetCore.OData/QueryODataController.cs @@ -13,9 +13,9 @@ namespace PoweredSoft.CQRS.AspNetCore.OData where TQuery : class { [EnableQuery, HttpGet, QueryControllerAuthorization] - public async Task Get([FromServices]IQueryHandler queryHandler) + public async Task Get([FromServices]IQueryHandler queryHandler, [FromQuery]TQuery query) { - var result = await queryHandler.HandleAsync(null, HttpContext.RequestAborted); + var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted); return result; } } diff --git a/PoweredSoft.CQRS.AspNetCore/Mvc/QueryController.cs b/PoweredSoft.CQRS.AspNetCore/Mvc/QueryController.cs index 3695bf2..24b8f6e 100644 --- a/PoweredSoft.CQRS.AspNetCore/Mvc/QueryController.cs +++ b/PoweredSoft.CQRS.AspNetCore/Mvc/QueryController.cs @@ -19,6 +19,17 @@ namespace PoweredSoft.CQRS.AspNetCore.Mvc return BadRequest(ModelState); + return Ok(await handler.HandleAsync(query, this.Request.HttpContext.RequestAborted)); + } + + [HttpGet, QueryControllerAuthorization] + public async Task> HandleGet([FromServices] IQueryHandler handler, + [FromQuery] TQuery query) + { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + return Ok(await handler.HandleAsync(query, this.Request.HttpContext.RequestAborted)); } } diff --git a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/DynamicQueryFilter.cs b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/DynamicQueryFilter.cs index 0b8c618..c6380ae 100644 --- a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/DynamicQueryFilter.cs +++ b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/DynamicQueryFilter.cs @@ -1,4 +1,5 @@ -using PoweredSoft.DynamicQuery; +using Microsoft.AspNetCore.Mvc; +using PoweredSoft.DynamicQuery; using PoweredSoft.DynamicQuery.Core; using System.Collections.Generic; using System.Linq; @@ -15,6 +16,19 @@ namespace PoweredSoft.CQRS.DynamicQuery.AspNetCore public string Path { get; set; } public object Value { get; set; } + [FromQuery(Name ="value")] + public string QueryValue + { + get + { + return null; + } + set + { + Value = value; + } + } + public IFilter ToFilter() { if (Type == FilterType.Composite) diff --git a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryController.cs b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryController.cs index 49b8ebc..12f9d37 100644 --- a/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryController.cs +++ b/PoweredSoft.CQRS.DynamicQuery.AspNetCore/Mvc/DynamicQueryController.cs @@ -23,6 +23,16 @@ namespace PoweredSoft.CQRS.DynamicQuery.AspNetCore.Mvc var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted); return result; } + + [HttpGet, QueryControllerAuthorization] + public async Task> HandleGetAsync( + [FromQuery] DynamicQuery query, + [FromServices] PoweredSoft.CQRS.Abstractions.IQueryHandler, IQueryExecutionResult> queryHandler + ) + { + var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted); + return result; + } } [ApiController, Route("api/query/[controller]")] @@ -40,5 +50,15 @@ namespace PoweredSoft.CQRS.DynamicQuery.AspNetCore.Mvc var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted); return result; } + + [HttpGet, QueryControllerAuthorization] + public async Task> HandleGetAsync( + [FromQuery] DynamicQuery query, + [FromServices] PoweredSoft.CQRS.Abstractions.IQueryHandler, IQueryExecutionResult> queryHandler + ) + { + var result = await queryHandler.HandleAsync(query, HttpContext.RequestAborted); + return result; + } } }