Add CommonController with POST endpoint using MediatR
Introduced CommonController in the ReC.API.Controllers namespace with a POST endpoint at "api/common". The endpoint accepts an InsertObjectProcedure from the request body, sends it via MediatR, and returns a 201 Created response with the generated ID.
This commit is contained in:
17
src/ReC.API/Controllers/CommonController.cs
Normal file
17
src/ReC.API/Controllers/CommonController.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ReC.Application.Common.Procedures.InsertProcedure;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user