32 lines
1007 B
C#
32 lines
1007 B
C#
using AutoMapper;
|
|
using MediatR;
|
|
using ExpenseTracker.Application.Common.Interfaces.Repositories;
|
|
using ExpenseTracker.Domain.Entities;
|
|
|
|
namespace ExpenseTracker.Application.Accounts.Queries.Get;
|
|
|
|
public class GetAccountQueryHandler : IRequestHandler<GetAccountQuery, AccountDto>
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IAccountRepository _accountRepository;
|
|
private readonly ITransactionRepository _transactionRepository;
|
|
|
|
public GetAccountQueryHandler(
|
|
IMapper mapper,
|
|
IAccountRepository repository,
|
|
ITransactionRepository transactionRepository)
|
|
{
|
|
_mapper = mapper;
|
|
_accountRepository = repository;
|
|
_transactionRepository = transactionRepository;
|
|
}
|
|
|
|
public async Task<AccountDto> Handle(GetAccountQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = _accountRepository.Queryable
|
|
.FirstOrDefault(e => e.Id == request.Id);
|
|
|
|
return _mapper.Map<AccountDto>(entity);
|
|
}
|
|
}
|