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 });