A new `DeleteObject` method has been added to the `CommonController` class to handle HTTP DELETE requests. This method is asynchronous and processes a `DeleteObjectProcedure` object passed in the request body using the `mediator.Send` function. The result is returned as an HTTP 200 OK response. The `[HttpDelete]` attribute has been applied to the method to designate it as a DELETE endpoint.
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ReC.Application.Common.Procedures.DeleteProcedure;
|
|
using ReC.Application.Common.Procedures.InsertProcedure;
|
|
using ReC.Application.Common.Procedures.UpdateProcedure;
|
|
|
|
namespace ReC.API.Controllers;
|
|
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class CommonController(IMediator mediator) : ControllerBase
|
|
{
|
|
[HttpPost]
|
|
public async Task<IActionResult> CreateObject([FromBody] InsertObjectProcedure procedure, CancellationToken cancel)
|
|
{
|
|
var id = await mediator.Send(procedure, cancel);
|
|
return StatusCode(StatusCodes.Status201Created, id);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<IActionResult> UpdateObject([FromBody] UpdateObjectProcedure procedure, CancellationToken cancel)
|
|
{
|
|
var result = await mediator.Send(procedure, cancel);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task<IActionResult> DeleteObject([FromBody] DeleteObjectProcedure procedure, CancellationToken cancel)
|
|
{
|
|
var result = await mediator.Send(procedure, cancel);
|
|
return Ok(result);
|
|
}
|
|
} |