Add JSON body/header support to CreateFakeAction method

Updated ActionController to support JSON serialization for
request body and headers in the CreateFakeAction method.
Replaced `bodyQuery` with `body` and `header` parameters,
serialized to JSON. Updated `BodyQuery` and added
`HeaderQuery` in `CreateRecActionCommand`. Refactored
endpoint URI construction and improved response handling.
This commit is contained in:
tekh 2025-12-03 10:00:37 +01:00
parent 1000be0c89
commit 50e092d9e2

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ReC.Application.RecActions.Commands; using ReC.Application.RecActions.Commands;
using System.IO; using System.IO;
using System.Text.Json;
namespace ReC.API.Controllers; namespace ReC.API.Controllers;
@ -29,18 +30,23 @@ public class ActionController(IMediator mediator) : ControllerBase
string endpointUri = "https://jsonplaceholder.typicode.com/posts", string endpointUri = "https://jsonplaceholder.typicode.com/posts",
string? endpointPath = null, string? endpointPath = null,
string type = "GET", string type = "GET",
string bodyQuery = "SELECT NULL AS REQUEST_BODY;") Dictionary<string, object>? body = null,
Dictionary<string, object>? header = null)
{ {
if (endpointPath is not null) if (endpointPath is not null)
endpointUri = new Uri(new Uri(endpointUri.TrimEnd('/') + "/"), endpointPath.TrimStart('/')).ToString(); endpointUri = new Uri(new Uri(endpointUri.TrimEnd('/') + "/"), endpointPath.TrimStart('/')).ToString();
var bodyJson = JsonSerializer.Serialize(body, options: new() { WriteIndented = false });
var headerJson = JsonSerializer.Serialize(header, options: new() { WriteIndented = false });
await mediator.Send(new CreateRecActionCommand() await mediator.Send(new CreateRecActionCommand()
{ {
ProfileId = 2, ProfileId = 2,
EndpointUri = endpointUri, EndpointUri = endpointUri,
Type = type, Type = type,
BodyQuery = bodyQuery, BodyQuery = $@"SELECT '{bodyJson}' AS REQUEST_BODY;",
Active = true, HeaderQuery = $@"SELECT '{headerJson}' AS REQUEST_HEADER;",
Active = true
}); });
return CreatedAtAction(nameof(CreateFakeAction), null); return CreatedAtAction(nameof(CreateFakeAction), null);