46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ExpenseTracker.Application.Transactions;
|
|
using ExpenseTracker.Application.Transactions.Commands.Create;
|
|
using ExpenseTracker.Application.Transactions.Commands.Delete;
|
|
using ExpenseTracker.Application.Transactions.Commands.Update;
|
|
using ExpenseTracker.Application.Transactions.Queries.Get;
|
|
using ExpenseTracker.Application.Common.Models;
|
|
using ExpenseTracker.Application.Transactions.Queries.GetWithPagination;
|
|
|
|
namespace ExpenseTracker.Api.Controllers;
|
|
|
|
[Route("transactions")]
|
|
public class TransactionController : BaseController
|
|
{
|
|
[HttpPost]
|
|
public async Task<TransactionDto> Create([FromBody] CreateTransactionCommand command, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<PaginatedList<TransactionDto>> GetPage([FromQuery] GetTransactionsWithPaginationQuery query, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
public async Task<TransactionDto> Get(string id, CancellationToken cancellationToken)
|
|
{
|
|
var query = new GetTransactionQuery() { Id = id };
|
|
return await Mediator.Send(query, cancellationToken);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<TransactionDto> Update([FromBody] UpdateTransactionCommand command, CancellationToken cancellationToken)
|
|
{
|
|
return await Mediator.Send(command, cancellationToken);
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task Delete([FromBody] DeleteTransactionCommand command, CancellationToken cancellationToken)
|
|
{
|
|
await Mediator.Send(command, cancellationToken);
|
|
}
|
|
}
|