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

47 lines
1.6 KiB
C#

using AutobusApi.Application.Common.Models;
using AutobusApi.Application.Routes.Commands.CreateRoute;
using AutobusApi.Application.Routes.Commands.DeleteRoute;
using AutobusApi.Application.Routes.Commands.UpdateRoute;
using AutobusApi.Application.Routes.Queries;
using AutobusApi.Application.Routes.Queries.GetRoutesWithPagination;
using AutobusApi.Application.Routes.Queries.GetRoute;
using Microsoft.AspNetCore.Mvc;
namespace AutobusApi.Api.Controllers;
[Route("routes")]
public class RouteController : BaseController
{
[HttpPost]
public async Task<int> Create([FromBody] CreateRouteCommand command, CancellationToken cancellationToken)
{
return await Mediator.Send(command, cancellationToken);
}
[HttpGet]
public async Task<PaginatedList<RouteDto>> GetPage([FromQuery] GetRoutesWithPaginationQuery query, CancellationToken cancellationToken)
{
return await Mediator.Send(query, cancellationToken);
}
[HttpGet("{id}")]
public async Task<RouteDto> Get(int id, /* [FromQuery] GetRouteQuery query, */ CancellationToken cancellationToken)
{
var query = new GetRouteQuery() { Id = id };
return await Mediator.Send(query, cancellationToken);
}
[HttpPut]
public async Task Update([FromBody] UpdateRouteCommand command, CancellationToken cancellationToken)
{
await Mediator.Send(command, cancellationToken);
}
[HttpDelete("{id}")]
public async Task Delete(int id, /* [FromBody] DeleteRouteCommand command, */ CancellationToken cancellationToken)
{
var command = new DeleteRouteCommand() { Id = id };
await Mediator.Send(command, cancellationToken);
}
}