Skip to content

Controllers

anton-martyniuk edited this page Sep 2, 2022 · 2 revisions

Modern generic controller has the following HTTP endpoints:

[Route("api/[controller]")]
public class ModernController<TCreateRequest, TUpdateRequest, TEntityDto, TEntityDbo, TId> : ControllerBase
{
    [HttpGet("get/{id}")]
    Task<IActionResult> GetById([Required] TId id)
    
    [HttpGet("get")]
    Task<IActionResult> GetAll(CancellationToken cancellationToken)
    
    [HttpPost("create")]
    Task<IActionResult> Create([FromBody, Required] TCreateRequest request)
    
    [HttpPost("create-many")]
    Task<IActionResult> CreateMany([FromBody, Required] List<TCreateRequest> requests)
    
    [HttpPut("update/{id}")]
    Task<IActionResult> Update([Required] TId id, [FromBody, Required] TUpdateRequest request)
    
    [HttpPut("update-many")]
    Task<IActionResult> UpdateMany([FromBody, Required] List<TUpdateRequest> requests)
    
    [HttpPatch("patch/{id}")]
    Task<IActionResult> Patch([Required] TId id, [FromBody] JsonPatchDocument<TEntityDto> patch)
    
    [HttpDelete("delete/{id}")]
    Task<IActionResult> Delete([Required] TId id)
    
    [HttpDelete("delete-many")]
    Task<IActionResult> DeleteMany([Required] List<TId> ids)
}
Clone this wiki locally