Refactor RecActionController to use MediatR Send only
Simplified controller by removing IConfiguration dependency and unused usings. Refactored all endpoints to use MediatR's Send method with command objects, eliminating custom mediator extension methods and route parameters like id. This streamlines command handling and reduces dependencies.
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using ReC.Application.Common.Procedures.DeleteProcedure;
|
|
||||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
|
||||||
using ReC.Application.Common.Procedures.UpdateProcedure;
|
|
||||||
using ReC.Application.RecActions.Commands;
|
using ReC.Application.RecActions.Commands;
|
||||||
using ReC.Application.RecActions.Queries;
|
using ReC.Application.RecActions.Queries;
|
||||||
|
|
||||||
@@ -10,19 +7,19 @@ namespace ReC.API.Controllers;
|
|||||||
|
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase
|
public class RecActionController(IMediator mediator) : ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invokes a batch of RecActions for a given profile.
|
/// Invokes a batch of RecActions for a given profile.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="profileId">The ID of the profile.</param>
|
/// <param name="command">The command containing the profile ID.</param>
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
||||||
[HttpPost("invoke/{profileId}")]
|
[HttpPost("invoke/{command}")]
|
||||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||||
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
|
public async Task<IActionResult> Invoke([FromRoute] InvokeBatchRecActionViewsCommand command, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.InvokeBatchRecActionView(profileId, cancel);
|
await mediator.Send(command, cancel);
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +44,7 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
|
|||||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||||
public async Task<IActionResult> Create([FromBody] InsertActionProcedure command, CancellationToken cancel)
|
public async Task<IActionResult> Create([FromBody] InsertActionProcedure command, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.ExecuteInsertProcedure(command, config["AddedWho"], cancel);
|
await mediator.Send(command, cancel);
|
||||||
|
|
||||||
return StatusCode(StatusCodes.Status201Created);
|
return StatusCode(StatusCodes.Status201Created);
|
||||||
}
|
}
|
||||||
@@ -55,15 +52,14 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a RecAction via the ACTION update procedure.
|
/// Updates a RecAction via the ACTION update procedure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">RecAction identifier to update.</param>
|
|
||||||
/// <param name="procedure">UpdateActionProcedure payload.</param>
|
/// <param name="procedure">UpdateActionProcedure payload.</param>
|
||||||
/// <param name="cancel">A token to cancel the operation.</param>
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
/// <returns>No content on success.</returns>
|
/// <returns>No content on success.</returns>
|
||||||
[HttpPut("{id:long}")]
|
[HttpPut("{id:long}")]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
public async Task<IActionResult> Update([FromRoute] long id, [FromBody] UpdateActionProcedure procedure, CancellationToken cancel)
|
public async Task<IActionResult> Update([FromBody] UpdateActionProcedure procedure, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
|
await mediator.Send(procedure, cancel);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +73,7 @@ public class RecActionController(IMediator mediator, IConfiguration config) : Co
|
|||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
public async Task<IActionResult> Delete([FromBody] DeleteActionProcedure procedure, CancellationToken cancel)
|
public async Task<IActionResult> Delete([FromBody] DeleteActionProcedure procedure, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.ExecuteDeleteProcedure(procedure, cancel);
|
await mediator.Send(procedure, cancel);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
#endregion CRUD
|
#endregion CRUD
|
||||||
|
|||||||
Reference in New Issue
Block a user