From f4390d992a992cc46939643b0c6727094d9c7cd7 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 4 Dec 2025 11:14:37 +0100 Subject: [PATCH] Refactor to use configurable FakeProfileId Replaced hardcoded FakeProfileId with a dynamic value retrieved from the configuration using a new GetFakeProfileId extension method. Updated OutResController and RecActionController to inject IConfiguration and use the new method. Added a new HttpGet endpoint in OutResController for fake profile queries. Modified appsettings.json to include a FakeProfileId setting with a default value of 2. Introduced ConfigurationExtensions to centralize configuration access logic, improving code maintainability and flexibility. --- src/ReC.API/ConfigExtensions.cs | 6 ++++++ src/ReC.API/Controllers/OutResController.cs | 8 +++++++- src/ReC.API/Controllers/RecActionController.cs | 14 ++++++-------- src/ReC.API/appsettings.json | 3 ++- 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 src/ReC.API/ConfigExtensions.cs diff --git a/src/ReC.API/ConfigExtensions.cs b/src/ReC.API/ConfigExtensions.cs new file mode 100644 index 0000000..aeb9345 --- /dev/null +++ b/src/ReC.API/ConfigExtensions.cs @@ -0,0 +1,6 @@ +namespace ReC.API; + +public static class ConfigurationExtensions +{ + public static int GetFakeProfileId(this IConfiguration config) => config.GetValue("FakeProfileId", 2); +} diff --git a/src/ReC.API/Controllers/OutResController.cs b/src/ReC.API/Controllers/OutResController.cs index a5fc458..70fb319 100644 --- a/src/ReC.API/Controllers/OutResController.cs +++ b/src/ReC.API/Controllers/OutResController.cs @@ -6,8 +6,14 @@ namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] -public class OutResController(IMediator mediator) : ControllerBase +public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase { [HttpGet] public async Task Get([FromQuery] ReadOutResQuery query) => Ok(await mediator.Send(query)); + + [HttpGet("fake")] + public async Task Get() => Ok(await mediator.Send(new ReadOutResQuery() + { + ProfileId = config.GetFakeProfileId() + })); } diff --git a/src/ReC.API/Controllers/RecActionController.cs b/src/ReC.API/Controllers/RecActionController.cs index 4783001..49f1bc4 100644 --- a/src/ReC.API/Controllers/RecActionController.cs +++ b/src/ReC.API/Controllers/RecActionController.cs @@ -9,10 +9,8 @@ namespace ReC.API.Controllers; [Route("api/[controller]")] [ApiController] -public class RecActionController(IMediator mediator) : ControllerBase +public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase { - private const long FakeProfileId = 2; - [HttpPost("invoke/{profileId}")] public async Task Invoke([FromRoute] int profileId, CancellationToken cancel) { @@ -23,7 +21,7 @@ public class RecActionController(IMediator mediator) : ControllerBase [HttpPost("invoke/fake")] public async Task Invoke(CancellationToken cancel) { - await mediator.InvokeBatchRecAction(FakeProfileId, cancel); + await mediator.InvokeBatchRecAction(config.GetFakeProfileId(), cancel); return Accepted(); } @@ -37,7 +35,7 @@ public class RecActionController(IMediator mediator) : ControllerBase [HttpGet("fake")] public async Task Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery() { - ProfileId = FakeProfileId + ProfileId = config.GetFakeProfileId() }, cancel)); [HttpPost] @@ -64,7 +62,7 @@ public class RecActionController(IMediator mediator) : ControllerBase await mediator.Send(new CreateRecActionCommand() { - ProfileId = FakeProfileId, + ProfileId = config.GetFakeProfileId(), EndpointUri = endpointUri, Type = type, BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;", @@ -81,7 +79,7 @@ public class RecActionController(IMediator mediator) : ControllerBase { await mediator.Send(new DeleteRecActionsCommand() { - ProfileId = FakeProfileId + ProfileId = config.GetFakeProfileId() }, cancel); return NoContent(); @@ -92,7 +90,7 @@ public class RecActionController(IMediator mediator) : ControllerBase { await mediator.Send(new DeleteRecActionsCommand() { - ProfileId = FakeProfileId + ProfileId = config.GetFakeProfileId() }, cancel); return NoContent(); diff --git a/src/ReC.API/appsettings.json b/src/ReC.API/appsettings.json index d120eff..bfd818e 100644 --- a/src/ReC.API/appsettings.json +++ b/src/ReC.API/appsettings.json @@ -13,5 +13,6 @@ "RecAction": { "MaxConcurrentInvocations": 5 }, - "AddedWho": "ReC.API" + "AddedWho": "ReC.API", + "FakeProfileId": 2 } \ No newline at end of file