47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using AutobusApi.Application.Common.Models;
|
|
using AutobusApi.Application.Cities.Commands.CreateCity;
|
|
using AutobusApi.Application.Cities.Commands.DeleteCity;
|
|
using AutobusApi.Application.Cities.Commands.UpdateCity;
|
|
using AutobusApi.Application.Cities.Queries;
|
|
using AutobusApi.Application.Cities.Queries.GetCitiesWithPagination;
|
|
using AutobusApi.Application.Cities.Queries.GetCity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AutobusApi.Api.Controllers;
|
|
|
|
[Route("cities")]
|
|
public class CityController : BaseController
|
|
{
|
|
[HttpPost]
|
|
public async Task<int> Create([FromBody] CreateCityCommand command, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<PaginatedList<CityDto>> GetPage([FromQuery] GetCitiesWithPaginationQuery query, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<CityDto> Get(int id, /* [FromQuery] GetCityQuery query, */ CancellationToken cancellationToken)
|
|
{
|
|
var query = new GetCityQuery() { Id = id };
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task Update([FromBody] UpdateCityCommand command, CancellationToken cancellationToken)
|
|
{
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task Delete(int id, /* [FromBody] DeleteCityCommand command, */ CancellationToken cancellationToken)
|
|
{
|
|
var command = new DeleteCityCommand() { Id = id };
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
}
|