Template
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using RT.Application.Services;
|
|
|
|
namespace RT.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public abstract class BaseController<TCreate, TUpdate, TResponse>(
|
|
IService<TCreate, TUpdate, TResponse> service) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAll(CancellationToken ct)
|
|
{
|
|
var result = await service.GetAllAsync(ct);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpGet("{id:guid}")]
|
|
public async Task<IActionResult> GetById(Guid id, CancellationToken ct)
|
|
{
|
|
var result = await service.GetByIdAsync(id, ct);
|
|
return result is null ? NotFound() : Ok(result);
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create([FromBody] TCreate dto, CancellationToken ct)
|
|
{
|
|
var result = await service.CreateAsync(dto, ct);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpPut("{id:guid}")]
|
|
public async Task<IActionResult> Update(Guid id, [FromBody] TUpdate dto, CancellationToken ct)
|
|
{
|
|
var result = await service.UpdateAsync(id, dto, ct);
|
|
return Ok(result);
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
|
{
|
|
await service.DeleteAsync(id, ct);
|
|
return NoContent();
|
|
}
|
|
}
|