47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using AutobusApi.Application.Common.Models;
|
|
using AutobusApi.Application.Buses.Commands.CreateBus;
|
|
using AutobusApi.Application.Buses.Commands.DeleteBus;
|
|
using AutobusApi.Application.Buses.Commands.UpdateBus;
|
|
using AutobusApi.Application.Buses.Queries;
|
|
using AutobusApi.Application.Buses.Queries.GetBusesWithPagination;
|
|
using AutobusApi.Application.Buses.Queries.GetBus;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AutobusApi.Api.Controllers;
|
|
|
|
[Route("vehicle/buses")]
|
|
public class BusController : BaseController
|
|
{
|
|
[HttpPost]
|
|
public async Task<int> Create([FromBody] CreateBusCommand command, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<PaginatedList<BusDto>> GetPage([FromQuery] GetBusesWithPaginationQuery query, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<BusDto> Get(int id, /* [FromQuery] GetBusQuery query, */ CancellationToken cancellationToken)
|
|
{
|
|
var query = new GetBusQuery() { Id = id };
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task Update([FromBody] UpdateBusCommand command, CancellationToken cancellationToken)
|
|
{
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task Delete(int id, /* [FromBody] DeleteBusCommand command, */ CancellationToken cancellationToken)
|
|
{
|
|
var command = new DeleteBusCommand() { Id = id };
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
}
|