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

47 lines
1.8 KiB
C#

using AutobusApi.Application.Common.Models;
using AutobusApi.Application.TicketGroups.Commands.CreateTicketGroup;
using AutobusApi.Application.TicketGroups.Commands.DeleteTicketGroup;
using AutobusApi.Application.TicketGroups.Commands.UpdateTicketGroup;
using AutobusApi.Application.TicketGroups.Queries;
using AutobusApi.Application.TicketGroups.Queries.GetTicketGroupsWithPagination;
using AutobusApi.Application.TicketGroups.Queries.GetTicketGroup;
using Microsoft.AspNetCore.Mvc;
namespace AutobusApi.Api.Controllers;
[Route("ticketgroups")]
public class TicketGroupController : BaseController
{
[HttpPost]
public async Task<int> Create([FromBody] CreateTicketGroupCommand command, CancellationToken cancellationToken)
{
return await Mediator.Send(command, cancellationToken);
}
[HttpGet]
public async Task<PaginatedList<TicketGroupDto>> GetPage([FromQuery] GetTicketGroupsWithPaginationQuery query, CancellationToken cancellationToken)
{
return await Mediator.Send(query, cancellationToken);
}
[HttpGet("{id}")]
public async Task<TicketGroupDto> Get(int id, /* [FromQuery] GetTicketGroupQuery query, */ CancellationToken cancellationToken)
{
var query = new GetTicketGroupQuery() { Id = id };
return await Mediator.Send(query, cancellationToken);
}
[HttpPut]
public async Task Update([FromBody] UpdateTicketGroupCommand command, CancellationToken cancellationToken)
{
await Mediator.Send(command, cancellationToken);
}
[HttpDelete("{id}")]
public async Task Delete(int id, /* [FromBody] DeleteTicketGroupCommand command, */ CancellationToken cancellationToken)
{
var command = new DeleteTicketGroupCommand() { Id = id };
await Mediator.Send(command, cancellationToken);
}
}