using Microsoft.AspNetCore.Mvc; using PoweredSoft.CQRS.Abstractions; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace PoweredSoft.CQRS.AspNetCore.Mvc { [ApiController, Route("api/query/[controller]")] public class QueryController : Controller where TQuery : class { [HttpPost, QueryControllerAuthorization] public async Task> Handle([FromServices] IQueryHandler handler, [FromBody] TQuery query) { if (!ModelState.IsValid) 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)); } } }