Add endpoint for filtered OutRes results by actionId
Introduced a new `HttpGet` endpoint `fake/{actionId}` in the
`OutResController` to support fetching OutRes data filtered
by `actionId` and an optional `resultType` parameter.
Added logic to handle different `resultType` values (`Full`,
`Header`, `Body`) and return the appropriate part of the
result. Updated response `ContentType` for non-`Full` results
and ensured null-safe handling for `Body` and `Header`.
Included a new `ResultType` enum and added necessary `using`
directives for the new functionality.
This commit is contained in:
parent
5a226bfcea
commit
9165f9d746
@ -1,6 +1,9 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ReC.API.Models;
|
||||||
using ReC.Application.OutResults.Queries;
|
using ReC.Application.OutResults.Queries;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace ReC.API.Controllers;
|
namespace ReC.API.Controllers;
|
||||||
|
|
||||||
@ -16,4 +19,31 @@ public class OutResController(IMediator mediator, IConfiguration config) : Contr
|
|||||||
{
|
{
|
||||||
ProfileId = config.GetFakeProfileId()
|
ProfileId = config.GetFakeProfileId()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
[HttpGet("fake/{actionId}")]
|
||||||
|
public async Task<IActionResult> Get([FromRoute] long actionId, ResultType resultType = ResultType.Full)
|
||||||
|
{
|
||||||
|
var res = (await mediator.Send(new ReadOutResQuery()
|
||||||
|
{
|
||||||
|
ProfileId = config.GetFakeProfileId(),
|
||||||
|
ActionId = actionId
|
||||||
|
})).First();
|
||||||
|
|
||||||
|
if (resultType is not ResultType.Full)
|
||||||
|
HttpContext.Response.ContentType = MediaTypeNames.Application.Json;
|
||||||
|
|
||||||
|
return resultType switch
|
||||||
|
{
|
||||||
|
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(JsonSerializer.Deserialize<dynamic>(res.Body)),
|
||||||
|
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(JsonSerializer.Deserialize<dynamic>(res.Header)),
|
||||||
|
_ => Ok(res),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ResultType
|
||||||
|
{
|
||||||
|
Full,
|
||||||
|
Header,
|
||||||
|
Body
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user