From b5b1f53e2148ad6dd44331d6997c6e33d72c7c44 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Dec 2025 10:27:34 +0100 Subject: [PATCH] Refactor CreateFakeAction to use FakeRequest model Refactored the `CreateFakeAction` method in `ActionController`: - Replaced individual parameters with a strongly-typed `FakeRequest` model for the request body. - Added `[FromQuery]` attributes for `endpointUri`, `endpointPath`, and `type` to allow query parameter overrides. - Updated serialization logic for `Body` and `Header` to handle null values more explicitly. - Adjusted `BodyQuery` and `HeaderQuery` assignments to improve null handling. Also updated `using` directives to include `ReC.API.Models` and `ReC.Application.RecActions.Commands`. --- src/ReC.API/Controllers/ActionController.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ReC.API/Controllers/ActionController.cs b/src/ReC.API/Controllers/ActionController.cs index 471f638..a6ae6ab 100644 --- a/src/ReC.API/Controllers/ActionController.cs +++ b/src/ReC.API/Controllers/ActionController.cs @@ -1,5 +1,6 @@ using MediatR; using Microsoft.AspNetCore.Mvc; +using ReC.API.Models; using ReC.Application.RecActions.Commands; using System.IO; using System.Text.Json; @@ -27,25 +28,24 @@ public class ActionController(IMediator mediator) : ControllerBase [HttpPost("fake")] public async Task CreateFakeAction( - string endpointUri = "https://jsonplaceholder.typicode.com/posts", - string? endpointPath = null, - string type = "GET", - Dictionary? body = null, - Dictionary? header = null) + [FromBody] FakeRequest? request = null, + [FromQuery] string endpointUri = "https://jsonplaceholder.typicode.com/posts", + [FromQuery] string? endpointPath = null, + [FromQuery] string type = "GET") { 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 }); + var bodyJson = request?.Body is not null ? JsonSerializer.Serialize(request.Body, options: new() { WriteIndented = false }) : null; + var headerJson = request?.Header is not null ? JsonSerializer.Serialize(request.Header, options: new() { WriteIndented = false }) : null; await mediator.Send(new CreateRecActionCommand() { ProfileId = 2, EndpointUri = endpointUri, Type = type, - BodyQuery = $@"SELECT '{bodyJson}' AS REQUEST_BODY;", - HeaderQuery = $@"SELECT '{headerJson}' AS REQUEST_HEADER;", + BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;", + HeaderQuery = headerJson is not null ? $@"SELECT '{headerJson}' AS REQUEST_HEADER;" : null, Active = true });