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.
This commit is contained in:
tekh 2025-12-04 11:14:37 +01:00
parent 906d99105c
commit f4390d992a
4 changed files with 21 additions and 10 deletions

View File

@ -0,0 +1,6 @@
namespace ReC.API;
public static class ConfigurationExtensions
{
public static int GetFakeProfileId(this IConfiguration config) => config.GetValue<int>("FakeProfileId", 2);
}

View File

@ -6,8 +6,14 @@ namespace ReC.API.Controllers;
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class OutResController(IMediator mediator) : ControllerBase public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase
{ {
[HttpGet] [HttpGet]
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query) => Ok(await mediator.Send(query)); public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query) => Ok(await mediator.Send(query));
[HttpGet("fake")]
public async Task<IActionResult> Get() => Ok(await mediator.Send(new ReadOutResQuery()
{
ProfileId = config.GetFakeProfileId()
}));
} }

View File

@ -9,10 +9,8 @@ namespace ReC.API.Controllers;
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class RecActionController(IMediator mediator) : ControllerBase public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase
{ {
private const long FakeProfileId = 2;
[HttpPost("invoke/{profileId}")] [HttpPost("invoke/{profileId}")]
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel) public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
{ {
@ -23,7 +21,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
[HttpPost("invoke/fake")] [HttpPost("invoke/fake")]
public async Task<IActionResult> Invoke(CancellationToken cancel) public async Task<IActionResult> Invoke(CancellationToken cancel)
{ {
await mediator.InvokeBatchRecAction(FakeProfileId, cancel); await mediator.InvokeBatchRecAction(config.GetFakeProfileId(), cancel);
return Accepted(); return Accepted();
} }
@ -37,7 +35,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
[HttpGet("fake")] [HttpGet("fake")]
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery() public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery()
{ {
ProfileId = FakeProfileId ProfileId = config.GetFakeProfileId()
}, cancel)); }, cancel));
[HttpPost] [HttpPost]
@ -64,7 +62,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
await mediator.Send(new CreateRecActionCommand() await mediator.Send(new CreateRecActionCommand()
{ {
ProfileId = FakeProfileId, ProfileId = config.GetFakeProfileId(),
EndpointUri = endpointUri, EndpointUri = endpointUri,
Type = type, Type = type,
BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;", BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;",
@ -81,7 +79,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
{ {
await mediator.Send(new DeleteRecActionsCommand() await mediator.Send(new DeleteRecActionsCommand()
{ {
ProfileId = FakeProfileId ProfileId = config.GetFakeProfileId()
}, cancel); }, cancel);
return NoContent(); return NoContent();
@ -92,7 +90,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
{ {
await mediator.Send(new DeleteRecActionsCommand() await mediator.Send(new DeleteRecActionsCommand()
{ {
ProfileId = FakeProfileId ProfileId = config.GetFakeProfileId()
}, cancel); }, cancel);
return NoContent(); return NoContent();

View File

@ -13,5 +13,6 @@
"RecAction": { "RecAction": {
"MaxConcurrentInvocations": 5 "MaxConcurrentInvocations": 5
}, },
"AddedWho": "ReC.API" "AddedWho": "ReC.API",
"FakeProfileId": 2
} }