47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using AutobusApi.Application.Common.Models;
|
|
using AutobusApi.Application.Countries.Commands.CreateCountry;
|
|
using AutobusApi.Application.Countries.Commands.DeleteCountry;
|
|
using AutobusApi.Application.Countries.Commands.UpdateCountry;
|
|
using AutobusApi.Application.Countries.Queries;
|
|
using AutobusApi.Application.Countries.Queries.GetCountriesWithPagination;
|
|
using AutobusApi.Application.Countries.Queries.GetCountry;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AutobusApi.Api.Controllers;
|
|
|
|
[Route("countries")]
|
|
public class CountryController : BaseController
|
|
{
|
|
[HttpPost]
|
|
public async Task<int> Create([FromBody] CreateCountryCommand command, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<PaginatedList<CountryDto>> GetPage([FromQuery] GetCountriesWithPaginationQuery query, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<CountryDto> Get(int id, /* [FromQuery] GetCountryQuery query, */ CancellationToken cancellationToken)
|
|
{
|
|
var query = new GetCountryQuery() { Id = id };
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task Update([FromBody] UpdateCountryCommand command, CancellationToken cancellationToken)
|
|
{
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
public async Task Delete(int id, /* [FromBody] DeleteCountryCommand command, */ CancellationToken cancellationToken)
|
|
{
|
|
var command = new DeleteCountryCommand() { Id = id };
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
}
|