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

47 lines
1.7 KiB
C#

using AutobusApi.Application.Common.Models;
using AutobusApi.Application.Addresses.Commands.CreateAddress;
using AutobusApi.Application.Addresses.Commands.DeleteAddress;
using AutobusApi.Application.Addresses.Commands.UpdateAddress;
using AutobusApi.Application.Addresses.Queries;
using AutobusApi.Application.Addresses.Queries.GetAddressesWithPagination;
using AutobusApi.Application.Addresses.Queries.GetAddress;
using Microsoft.AspNetCore.Mvc;
namespace AutobusApi.Api.Controllers;
[Route("addresses")]
public class AddressController : BaseController
{
[HttpPost]
public async Task<int> Create([FromBody] CreateAddressCommand command, CancellationToken cancellationToken)
{
return await Mediator.Send(command, cancellationToken);
}
[HttpGet]
public async Task<PaginatedList<AddressDto>> GetPage([FromQuery] GetAddressesWithPaginationQuery query, CancellationToken cancellationToken)
{
return await Mediator.Send(query, cancellationToken);
}
[HttpGet("{id}")]
public async Task<AddressDto> Get(int id, /* [FromQuery] GetAddressQuery query, */ CancellationToken cancellationToken)
{
var query = new GetAddressQuery() { Id = id };
return await Mediator.Send(query, cancellationToken);
}
[HttpPut]
public async Task Update([FromBody] UpdateAddressCommand command, CancellationToken cancellationToken)
{
await Mediator.Send(command, cancellationToken);
}
[HttpDelete("{id}")]
public async Task Delete(int id, /* [FromBody] DeleteAddressCommand command, */ CancellationToken cancellationToken)
{
var command = new DeleteAddressCommand() { Id = id };
await Mediator.Send(command, cancellationToken);
}
}