Files
ReC/src/ReC.API/Controllers/ResultViewController.cs
TekH 9b3bb925f9 Refactor ResultType enum location and naming for clarity
Move ResultType enum to ReC.API.Models/ResultType.cs and update its values from Header/Body to OnlyHeader/OnlyBody for improved clarity. Update all controller usages and documentation to reflect these changes.
2025-12-17 09:35:24 +01:00

41 lines
1.5 KiB
C#

using MediatR;
using Microsoft.AspNetCore.Mvc;
using ReC.API.Extensions;
using ReC.API.Models;
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<IActionResult> Get([FromQuery] ReadResultViewQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
[HttpGet("fake")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadResultViewQuery()
{
ProfileId = config.GetFakeProfileId()
}, cancel));
[HttpGet("fake/{actionId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> 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.OnlyBody => res.Body is null ? NotFound() : Ok(res.Body.JsonToDynamic()),
ResultType.OnlyHeader => res.Header is null ? NotFound() : Ok(res.Header.JsonToDynamic()),
_ => Ok(res),
};
}
}