autobus-api_old/AutobusApi.Api/Controllers/RegionController.cs

47 lines
1.7 KiB
C#

using AutobusApi.Application.Common.Models;
using AutobusApi.Application.Regions.Commands.CreateRegion;
using AutobusApi.Application.Regions.Commands.DeleteRegion;
using AutobusApi.Application.Regions.Commands.UpdateRegion;
using AutobusApi.Application.Regions.Queries;
using AutobusApi.Application.Regions.Queries.GetRegionsWithPagination;
using AutobusApi.Application.Regions.Queries.GetRegion;
using Microsoft.AspNetCore.Mvc;
namespace AutobusApi.Api.Controllers;
[Route("regions")]
public class RegionController : BaseController
{
[HttpPost]
public async Task<int> Create([FromBody] CreateRegionCommand command, CancellationToken cancellationToken)
{
return await Mediator.Send(command, cancellationToken);
}
[HttpGet]
public async Task<PaginatedList<RegionDto>> GetPage([FromQuery] GetRegionsWithPaginationQuery query, CancellationToken cancellationToken)
{
return await Mediator.Send(query, cancellationToken);
}
[HttpGet("{id}")]
public async Task<RegionDto> Get(int id, /* [FromQuery] GetRegionQuery query, */ CancellationToken cancellationToken)
{
var query = new GetRegionQuery() { Id = id };
return await Mediator.Send(query, cancellationToken);
}
[HttpPut]
public async Task Update([FromBody] UpdateRegionCommand command, CancellationToken cancellationToken)
{
await Mediator.Send(command, cancellationToken);
}
[HttpDelete("{id}")]
public async Task Delete(int id, /* [FromBody] DeleteRegionCommand command, */ CancellationToken cancellationToken)
{
var command = new DeleteRegionCommand() { Id = id };
await Mediator.Send(command, cancellationToken);
}
}