From 9cfa526e41f7c5ec5a27c4fb11a2b5bba632f94d Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Fri, 18 Oct 2024 23:22:12 +0200 Subject: [PATCH] Implement remaining GraphQL operations for transactions. Resolves #68 --- .../Mutations/TransactionMutationResolvers.cs | 11 +++++++++++ .../Repositories/TransactionRepository.cs | 11 ++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Mutations/TransactionMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Mutations/TransactionMutationResolvers.cs index a993ba1..fc3ec69 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Mutations/TransactionMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Resolvers/Mutations/TransactionMutationResolvers.cs @@ -22,6 +22,17 @@ public async Task CreateTransaction(TransactionRepository repositor return transaction; } + /// + /// Update an existing transaction. + /// + /// The injected repository to use for data retrieval. + /// The transaction to update. + public async Task UpdateTransaction(TransactionRepository repository, + Transaction transaction) + { + return await repository.UpdateTransaction(transaction); + } + /// /// Delete an existing transaction. /// diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/TransactionRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/TransactionRepository.cs index 465b0db..76337a4 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/TransactionRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.Infrastructure/Repositories/TransactionRepository.cs @@ -77,14 +77,15 @@ public async Task AddTransaction(Transaction transaction) /// /// Updates an existing . /// - /// The to update. + /// The to update. /// The updated . - /// TODO: return Transaction not TransactionEntity - public async Task UpdateTransaction(TransactionEntity transactionDto) + public async Task UpdateTransaction(Transaction transaction) { - var updateEntry = _dbContext.Transactions.Update(transactionDto); + var transactionEntity = _transactionMapper.ModelToEntity(transaction); + var updateEntry = _dbContext.Transactions.Update(transactionEntity); await _dbContext.SaveChangesAsync(); - return updateEntry.Entity; + + return _transactionMapper.EntityToModel(updateEntry.Entity); } ///