namespace FinControl.Infrastructure.Repositories; using Microsoft.EntityFrameworkCore; using FinControl.Domain.Entities; using FinControl.Domain.Repositories; using FinControl.Infrastructure.Persistence; public class TransactionRepository : ITransactionRepository { private readonly FinControlContext _context; public TransactionRepository(FinControlContext context) { _context = context; } public async Task GetByIdAsync(Guid id) => await _context.Transactions .Include(t => t.Account) .Include(t => t.Category) .FirstOrDefaultAsync(t => t.Id == id); public async Task> GetByAccountIdAsync(Guid accountId) => await _context.Transactions .Where(t => t.AccountId == accountId) .Include(t => t.Category) .ToListAsync(); public async Task> GetByCategoryIdAsync(Guid categoryId) => await _context.Transactions .Where(t => t.CategoryId == categoryId) .Include(t => t.Account) .ToListAsync(); public async Task> GetByUserIdAsync(Guid userId) => await _context.Transactions .Where(t => t.Account!.UserId == userId) .Include(t => t.Account) .Include(t => t.Category) .ToListAsync(); public async Task AddAsync(Transaction transaction) { await _context.Transactions.AddAsync(transaction); await _context.SaveChangesAsync(); } public async Task UpdateAsync(Transaction transaction) { _context.Transactions.Update(transaction); await _context.SaveChangesAsync(); } public async Task DeleteAsync(Guid id) { var transaction = await _context.Transactions.FindAsync(id); if (transaction != null) { _context.Transactions.Remove(transaction); await _context.SaveChangesAsync(); } } }