From 50e092d9e2816cbe9b41869b70c807221b202ffc Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Dec 2025 10:00:37 +0100 Subject: [PATCH] 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. --- src/ReC.API/Controllers/ActionController.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ReC.API/Controllers/ActionController.cs b/src/ReC.API/Controllers/ActionController.cs index 8c3d496..471f638 100644 --- a/src/ReC.API/Controllers/ActionController.cs +++ b/src/ReC.API/Controllers/ActionController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using ReC.Application.RecActions.Commands; using System.IO; +using System.Text.Json; namespace ReC.API.Controllers; @@ -29,18 +30,23 @@ public class ActionController(IMediator mediator) : ControllerBase string endpointUri = "https://jsonplaceholder.typicode.com/posts", string? endpointPath = null, string type = "GET", - string bodyQuery = "SELECT NULL AS REQUEST_BODY;") + Dictionary? body = null, + Dictionary? header = null) { if (endpointPath is not null) 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() { ProfileId = 2, EndpointUri = endpointUri, Type = type, - BodyQuery = bodyQuery, - Active = true, + BodyQuery = $@"SELECT '{bodyJson}' AS REQUEST_BODY;", + HeaderQuery = $@"SELECT '{headerJson}' AS REQUEST_HEADER;", + Active = true }); return CreatedAtAction(nameof(CreateFakeAction), null);