From 39fcee2b50456199b669d64a7199839d09f485ac Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 16 Dec 2025 12:51:17 +0100 Subject: [PATCH] Add ResultViewController for output result retrieval Introduce ResultViewController with endpoints to fetch output results by query, for fake/test profiles, and by action ID. Supports returning full, header, or body parts of results via a new ViewResultType enum. Utilizes MediatR and configuration injection for flexible and testable result access. Includes XML docs for improved API clarity. --- .../Controllers/ResultViewController.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/ReC.API/Controllers/ResultViewController.cs diff --git a/src/ReC.API/Controllers/ResultViewController.cs b/src/ReC.API/Controllers/ResultViewController.cs new file mode 100644 index 0000000..d411f43 --- /dev/null +++ b/src/ReC.API/Controllers/ResultViewController.cs @@ -0,0 +1,40 @@ +using MediatR; +using Microsoft.AspNetCore.Mvc; +using ReC.API.Extensions; +using ReC.Application.ResultViews.Queries; + +namespace ReC.API.Controllers; + +[Route("api/[controller]")] +[ApiController] +public class ResultViewController(IMediator mediator, IConfiguration config) : ControllerBase +{ + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Get([FromQuery] ReadResultViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel)); + + [HttpGet("fake")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadResultViewQuery() + { + ProfileId = config.GetFakeProfileId() + }, cancel)); + + [HttpGet("fake/{actionId}")] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full) + { + var res = (await mediator.Send(new ReadResultViewQuery() + { + ProfileId = config.GetFakeProfileId(), + ActionId = actionId + }, cancel)).First(); + + return resultType switch + { + ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()), + ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()), + _ => Ok(res), + }; + } +} \ No newline at end of file