Refactor ProfileController to use MediatR Send method
Replaces custom Execute*Procedure methods with MediatR's Send for insert, update, and delete operations. Removes obsolete using directives. Updates the PUT endpoint to accept the profile ID in the request body instead of the route.
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
using MediatR;
|
||||
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.Profile.Commands;
|
||||
using ReC.Application.Profile.Queries;
|
||||
|
||||
@@ -28,22 +25,21 @@ public class ProfileController(IMediator mediator) : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||
public async Task<IActionResult> Post([FromBody] InsertProfileProcedure procedure, CancellationToken cancel)
|
||||
{
|
||||
var id = await mediator.ExecuteInsertProcedure(procedure, cancel: cancel);
|
||||
var id = await mediator.Send(procedure, cancel);
|
||||
return CreatedAtAction(nameof(Get), new { id }, id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a profile via the PROFILE update procedure.
|
||||
/// </summary>
|
||||
/// <param name="id">Profile identifier to update.</param>
|
||||
/// <param name="procedure">UpdateProfileProcedure payload.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
/// <returns>No content on success.</returns>
|
||||
[HttpPut("{id:long}")]
|
||||
[HttpPut]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> Put([FromRoute] long id, [FromBody] UpdateProfileProcedure procedure, CancellationToken cancel)
|
||||
public async Task<IActionResult> Put([FromBody] UpdateProfileProcedure procedure, CancellationToken cancel)
|
||||
{
|
||||
await mediator.ExecuteUpdateProcedure(procedure, id, cancel: cancel);
|
||||
await mediator.Send(procedure, cancel);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
@@ -57,7 +53,7 @@ public class ProfileController(IMediator mediator) : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> Delete([FromBody] DeleteProfileProcedure procedure, CancellationToken cancel)
|
||||
{
|
||||
await mediator.ExecuteDeleteProcedure(procedure, cancel);
|
||||
await mediator.Send(procedure, cancel);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user