From 2a545d81f62d2168470454eec8152218940b9e44 Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Thu, 31 Oct 2024 23:27:59 +0100 Subject: [PATCH] Use projections on the BankAccountQueryResolvers --- .../Queries/BankAccountQueryResolvers.cs | 17 ++++++++++------- .../Repositories/BankAccountRepository.cs | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Queries/BankAccountQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Queries/BankAccountQueryResolvers.cs index b64e22d..717cd66 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Queries/BankAccountQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Queries/BankAccountQueryResolvers.cs @@ -1,4 +1,5 @@ -using HotChocolate.Types; +using HotChocolate.Data; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.Infrastructure.Repositories; @@ -15,19 +16,21 @@ public sealed class BankAccountQueryResolvers /// /// The repository to use for data retrieval. /// The id of the account to lookup. - public async Task GetBankAccount(BankAccountRepository repository, Guid accountId) + [UseSingleOrDefault] + [UseProjection] + public IQueryable GetBankAccount(BankAccountRepository repository, Guid accountId) { - return await repository.GetBankAccount(accountId); + return repository.GetBankAccount(accountId); } - // TODO: there is no input here like the comment indicates /// - /// Look up accounts by a list of ids. + /// Look up accounts. /// /// The injected repository to use for data retrieval. [UsePaging] - public async Task> GetBankAccounts(BankAccountRepository repository) + [UseProjection] + public IQueryable GetBankAccounts(BankAccountRepository repository) { - return await repository.GetBankAccounts(); + return repository.GetBankAccounts(); } } diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/BankAccountRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/BankAccountRepository.cs index 10d2643..089b3f8 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/BankAccountRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/BankAccountRepository.cs @@ -24,18 +24,18 @@ public BankAccountRepository(ApplicationDbContext dbContext) /// /// The id of the to retrieve. /// The if one ist matched otherwise . - public async Task GetBankAccount(Guid accountId) + public IQueryable GetBankAccount(Guid accountId) { - return await _dbContext.BankAccounts.SingleOrDefaultAsync(account => account.Id == accountId); + return _dbContext.BankAccounts.Where(account => account.Id == accountId); } /// /// Gets a list of s. /// /// A list of s. - public async Task> GetBankAccounts() + public IQueryable GetBankAccounts() { - return await _dbContext.BankAccounts.ToListAsync(); + return _dbContext.BankAccounts; } ///