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:
@@ -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<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
|
||||
{
|
||||
@@ -23,7 +21,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
||||
[HttpPost("invoke/fake")]
|
||||
public async Task<IActionResult> 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<IActionResult> 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();
|
||||
|
||||
Reference in New Issue
Block a user