Skip to content

Commit

Permalink
Use projections on the BankAccountQueryResolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Oct 31, 2024
1 parent 3d17715 commit 2a545d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HotChocolate.Types;
using HotChocolate.Data;
using HotChocolate.Types;
using RobinTTY.PersonalFinanceDashboard.Core.Models;
using RobinTTY.PersonalFinanceDashboard.Infrastructure.Repositories;

Expand All @@ -15,19 +16,21 @@ public sealed class BankAccountQueryResolvers
/// </summary>
/// <param name="repository">The repository to use for data retrieval.</param>
/// <param name="accountId">The id of the account to lookup.</param>
public async Task<BankAccount?> GetBankAccount(BankAccountRepository repository, Guid accountId)
[UseSingleOrDefault]
[UseProjection]
public IQueryable<BankAccount?> GetBankAccount(BankAccountRepository repository, Guid accountId)
{
return await repository.GetBankAccount(accountId);
return repository.GetBankAccount(accountId);
}

// TODO: there is no input here like the comment indicates
/// <summary>
/// Look up accounts by a list of ids.
/// Look up accounts.
/// </summary>
/// <param name="repository">The injected repository to use for data retrieval.</param>
[UsePaging]
public async Task<IEnumerable<BankAccount>> GetBankAccounts(BankAccountRepository repository)
[UseProjection]
public IQueryable<BankAccount> GetBankAccounts(BankAccountRepository repository)
{
return await repository.GetBankAccounts();
return repository.GetBankAccounts();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ public BankAccountRepository(ApplicationDbContext dbContext)
/// </summary>
/// <param name="accountId">The id of the <see cref="BankAccount"/> to retrieve.</param>
/// <returns>The <see cref="BankAccount"/> if one ist matched otherwise <see langword="null"/>.</returns>
public async Task<BankAccount?> GetBankAccount(Guid accountId)
public IQueryable<BankAccount?> GetBankAccount(Guid accountId)
{
return await _dbContext.BankAccounts.SingleOrDefaultAsync(account => account.Id == accountId);
return _dbContext.BankAccounts.Where(account => account.Id == accountId);
}

/// <summary>
/// Gets a list of <see cref="BankAccount"/>s.
/// </summary>
/// <returns>A list of <see cref="BankAccount"/>s.</returns>
public async Task<List<BankAccount>> GetBankAccounts()
public IQueryable<BankAccount> GetBankAccounts()
{
return await _dbContext.BankAccounts.ToListAsync();
return _dbContext.BankAccounts;
}

/// <summary>
Expand Down

0 comments on commit 2a545d8

Please sign in to comment.