From b459bf2d52e4ff6c744b300417c02fe13f22c59c Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Tue, 24 Oct 2023 03:19:09 +0200 Subject: [PATCH 1/8] Simplify HotChocolate code generation --- .../Program.cs | 7 ++----- .../Properties/ModuleInfo.cs | 1 + .../{Models => Types}/AppConfiguration.cs | 2 +- .../AuthenticationMutationResolvers.cs | 4 ++-- .../Mutations/TransactionMutationResolvers.cs | 4 ++-- .../Queries/AccountQueryResolvers.cs | 10 +++++----- .../AuthenticationRequestQueryResolvers.cs | 4 ++-- .../BankingInstitutionQueryResolvers.cs | 4 ++-- .../Queries/TransactionQueryResolvers.cs | 4 ++-- .../application.db | Bin 40960 -> 40960 bytes 10 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 src/server/RobinTTY.PersonalFinanceDashboard.API/Properties/ModuleInfo.cs rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/AppConfiguration.cs (96%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Mutations/AuthenticationMutationResolvers.cs (92%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Mutations/TransactionMutationResolvers.cs (88%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Queries/AccountQueryResolvers.cs (87%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Queries/AuthenticationRequestQueryResolvers.cs (91%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Queries/BankingInstitutionQueryResolvers.cs (92%) rename src/server/RobinTTY.PersonalFinanceDashboard.API/{Models => Types}/Queries/TransactionQueryResolvers.cs (88%) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs index b6560ae..72bbccc 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs @@ -1,7 +1,7 @@ global using System; global using Serilog; +global using HotChocolate; -using HotChocolate; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -43,15 +43,13 @@ // HotChocolate GraphQL Setup builder.Services .AddGraphQLServer() - .AddQueryType() - .AddMutationType() + .AddTypes() // TODO // https://relay.dev/docs/v1.5.0/graphql-server-specification/ // 1. By convention, mutations are named as verbs (done) // 2. their inputs are the name with "Input" appended at the end // 3. they return an object that is the name with "Payload" appended // .AddMutationConventions() - .AddApiTypes() .RegisterService(ServiceKind.Resolver); var app = builder.Build(); @@ -65,6 +63,5 @@ //} app.UseCors(); -app.UseWebSockets(); app.MapGraphQL(); app.Run(); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Properties/ModuleInfo.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Properties/ModuleInfo.cs new file mode 100644 index 0000000..4cfb15d --- /dev/null +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Properties/ModuleInfo.cs @@ -0,0 +1 @@ +[assembly: Module("Types")] \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/AppConfiguration.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/AppConfiguration.cs similarity index 96% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/AppConfiguration.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/AppConfiguration.cs index 3be1f9e..526cfc3 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/AppConfiguration.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/AppConfiguration.cs @@ -1,4 +1,4 @@ -namespace RobinTTY.PersonalFinanceDashboard.API.Models; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types; /// /// The configuration of the application server. diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/AuthenticationMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs similarity index 92% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/AuthenticationMutationResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs index 021c887..38d580e 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/AuthenticationMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs @@ -4,9 +4,9 @@ using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Mutations; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Mutations; -[ExtendObjectType(OperationTypeNames.Mutation)] +[MutationType] public class AuthenticationMutationResolvers { private readonly GoCardlessDataProvider _dataProvider; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/TransactionMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs similarity index 88% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/TransactionMutationResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs index cd6d14a..020a072 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Mutations/TransactionMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs @@ -3,9 +3,9 @@ using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Mutations; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Mutations; -[ExtendObjectType(OperationTypeNames.Mutation)] +[MutationType] public class TransactionMutationResolvers { /// diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AccountQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs similarity index 87% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AccountQueryResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs index a1c27ea..565b259 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AccountQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs @@ -1,13 +1,13 @@ -using HotChocolate.Types; -using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.Core.Models; +using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Queries; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; -[ExtendObjectType(OperationTypeNames.Query)] +[QueryType] public sealed class AccountQueryResolvers { private readonly GoCardlessDataProvider _dataProvider; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AuthenticationRequestQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs similarity index 91% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AuthenticationRequestQueryResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs index 5f42d09..619ab76 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/AuthenticationRequestQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs @@ -4,9 +4,9 @@ using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Queries; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; -[ExtendObjectType(OperationTypeNames.Query)] +[QueryType] public class AuthenticationRequestQueryResolvers { private readonly GoCardlessDataProvider _dataProvider; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/BankingInstitutionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs similarity index 92% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/BankingInstitutionQueryResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs index e7da18d..83d62aa 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/BankingInstitutionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs @@ -4,9 +4,9 @@ using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Queries; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; -[ExtendObjectType(OperationTypeNames.Query)] +[QueryType] public class BankingInstitutionQueryResolvers { private readonly GoCardlessDataProvider _dataProvider; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/TransactionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs similarity index 88% rename from src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/TransactionQueryResolvers.cs rename to src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs index 7be642c..47c16dc 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Models/Queries/TransactionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs @@ -5,9 +5,9 @@ using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; -namespace RobinTTY.PersonalFinanceDashboard.API.Models.Queries; +namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; -[ExtendObjectType(OperationTypeNames.Query)] +[QueryType] public class TransactionQueryResolvers { /// diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/application.db b/src/server/RobinTTY.PersonalFinanceDashboard.API/application.db index fb841d9d88e40aada5ccffe3a1dffd49635dafc3..f2f39b80f6a125e0c6621a9a150f97ecf17bf5c4 100644 GIT binary patch delta 408 zcmZoTz|?SnX#+<92j2z=+$<=th_9Y8z*=2UTv$`p#K^$VQrEyz*U((Sz{JYf$ja0} z&%o3qC_gDPPrOfRL{sbG}y%@F*B!9!L_0wHLp0eIHV{MsHh|}IXkt4 zfq~%<)J$W7X4VsL=nANzMg$Ed-pr5$sG)|`GL#GGeFgyr2L6{2xLMHP4!?-F2@6nI V(3lxWavL!LNmj!}1`3ND1OPlBaCQIy delta 21 dcmZoTz|?SnX#+>VVh#g^%^U_l Date: Tue, 24 Oct 2023 03:19:55 +0200 Subject: [PATCH 2/8] fix import --- .../Utility/AppConfigurationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/AppConfigurationManager.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/AppConfigurationManager.cs index 08ae47d..efce00a 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/AppConfigurationManager.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/AppConfigurationManager.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -using RobinTTY.PersonalFinanceDashboard.API.Models; +using RobinTTY.PersonalFinanceDashboard.Api.Types; namespace RobinTTY.PersonalFinanceDashboard.API.Utility; From edd45b82b3da00a1d5c7240b093c3b85e0e76204 Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Thu, 26 Oct 2023 01:16:54 +0200 Subject: [PATCH 3/8] Use graphql mutation conventions --- .../RobinTTY.PersonalFinanceDashboard.API/Program.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs index 72bbccc..38787f9 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs @@ -44,12 +44,7 @@ builder.Services .AddGraphQLServer() .AddTypes() - // TODO - // https://relay.dev/docs/v1.5.0/graphql-server-specification/ - // 1. By convention, mutations are named as verbs (done) - // 2. their inputs are the name with "Input" appended at the end - // 3. they return an object that is the name with "Payload" appended - // .AddMutationConventions() + .AddMutationConventions() .RegisterService(ServiceKind.Resolver); var app = builder.Build(); From 123b1193ff4b4d5c2ea2baa65abaf6118bb5f72d Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Thu, 26 Oct 2023 22:59:45 +0200 Subject: [PATCH 4/8] Add TransactionRepository --- .../Program.cs | 8 ++- .../AuthenticationRequestRepository.cs | 50 +++++++++++++++++++ .../Repositories/TransactionRepository.cs | 4 +- .../AuthenticationMutationResolvers.cs | 29 +++++------ .../AuthenticationRequestQueryResolvers.cs | 24 +++------ 5 files changed, 76 insertions(+), 39 deletions(-) create mode 100644 src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs index 38787f9..9798393 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs @@ -1,6 +1,8 @@ global using System; +global using System.Collections.Generic; +global using System.Threading.Tasks; global using Serilog; -global using HotChocolate; +global using HotChocolate; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; @@ -30,6 +32,7 @@ // General Services builder.Services .AddScoped() + .AddScoped() .AddSingleton(new NordigenClientCredentials(appConfig.NordigenApi!.SecretId, appConfig.NordigenApi.SecretKey)) .AddSingleton(); @@ -45,7 +48,8 @@ .AddGraphQLServer() .AddTypes() .AddMutationConventions() - .RegisterService(ServiceKind.Resolver); + .RegisterService(ServiceKind.Resolver) + .RegisterService(ServiceKind.Resolver); var app = builder.Build(); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs new file mode 100644 index 0000000..1744690 --- /dev/null +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs @@ -0,0 +1,50 @@ +using RobinTTY.NordigenApiClient.Models.Responses; +using RobinTTY.PersonalFinanceDashboard.Core.Models; +using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; + +namespace RobinTTY.PersonalFinanceDashboard.API.Repositories; + +/// +/// Manages data retrieval. +/// +public class AuthenticationRequestRepository +{ + private readonly GoCardlessDataProvider _dataProvider; + private readonly ApplicationDbContext _dbContext; + + /// + /// Creates a new instance of . + /// + /// The data provider to use for data retrieval. + /// The to use for data retrieval. + public AuthenticationRequestRepository(GoCardlessDataProvider dataProvider, ApplicationDbContext dbContext) + { + _dataProvider = dataProvider; + _dbContext = dbContext; + } + + public async Task Get(string authenticationId) + { + var requests = await _dataProvider.GetAuthenticationRequest(authenticationId); + return requests.Result!; + } + + public async Task> GetAll() + { + // TODO: limit + var requests = await _dataProvider.GetAuthenticationRequests(100); + return requests.Result!; + } + + public async Task Add(string institutionId, string redirectUri) + { + var request = await _dataProvider.CreateAuthenticationRequest(institutionId, new Uri(redirectUri)); + return request.Result!; + } + + public async Task Delete(string authenticationId) + { + var request = await _dataProvider.DeleteAuthenticationRequest(authenticationId); + return request.Result!; + } +} \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs index 2666a5f..fc15a64 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Linq; using Microsoft.EntityFrameworkCore; using RobinTTY.PersonalFinanceDashboard.API.EfModels; using RobinTTY.PersonalFinanceDashboard.Core.Models; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs index 38d580e..c2f9648 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/AuthenticationMutationResolvers.cs @@ -1,39 +1,36 @@ -using System.Threading.Tasks; -using HotChocolate.Types; +using HotChocolate.Types; using RobinTTY.NordigenApiClient.Models.Responses; +using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; -using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Mutations; +/// +/// related mutation resolvers. +/// [MutationType] public class AuthenticationMutationResolvers { - private readonly GoCardlessDataProvider _dataProvider; - - public AuthenticationMutationResolvers(GoCardlessDataProvider dataProvider) - { - _dataProvider = dataProvider; - } - /// /// Create a new authentication request for an institution. /// /// The id of the institution which the authentication request should be created for. /// The URI to redirect to after the authentication is completed. - public async Task CreateAuthenticationRequest(string institutionId, string redirectUri) + /// The repository to use for data retrieval. + // TODO: Exceptions + // [Error] + public async Task CreateAuthenticationRequest(string institutionId, string redirectUri, AuthenticationRequestRepository repository) { - var request = await _dataProvider.CreateAuthenticationRequest(institutionId, new Uri(redirectUri)); - return request.Result!; + return await repository.Add(institutionId, redirectUri); } /// /// Delete an existing authentication request. /// /// The id of the authentication request to delete. - public async Task DeleteAuthenticationRequest(string authenticationId) + /// The repository to use for data retrieval. + public async Task DeleteAuthenticationRequest(string authenticationId, AuthenticationRequestRepository repository) { - var request = await _dataProvider.DeleteAuthenticationRequest(authenticationId); - return request.Result!; + return await repository.Delete(authenticationId); } } \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs index 619ab76..434fa2a 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs @@ -1,38 +1,26 @@ -using System.Linq; -using System.Threading.Tasks; -using HotChocolate.Types; +using HotChocolate.Types; +using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; -using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; [QueryType] public class AuthenticationRequestQueryResolvers { - private readonly GoCardlessDataProvider _dataProvider; - - public AuthenticationRequestQueryResolvers(GoCardlessDataProvider dataProvider) - { - _dataProvider = dataProvider; - } - /// /// Look up authentication requests by their id. /// /// The id of the authentication request to retrieve. - public async Task GetAuthenticationRequest(string authenticationId) + public async Task GetAuthenticationRequest(string authenticationId, AuthenticationRequestRepository repository) { - var requests = await _dataProvider.GetAuthenticationRequest(authenticationId); - return requests.Result!; + return await repository.Get(authenticationId); } /// /// Look up authentication requests. /// - public async Task> GetAuthenticationRequests() + public async Task> GetAuthenticationRequests(AuthenticationRequestRepository repository) { - // TODO: Limit? - var requests = await _dataProvider.GetAuthenticationRequests(100); - return requests.Result!.AsQueryable(); + return await repository.GetAll(); } } \ No newline at end of file From 9118d73030fc1d26d7cc063808db36d7d17da1bb Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Fri, 27 Oct 2023 02:10:06 +0200 Subject: [PATCH 5/8] Update global imports --- .../EfModels/EfTag.cs | 4 +--- .../EfModels/EfTransaction.cs | 4 +--- .../Program.cs | 2 ++ .../Repositories/AuthenticationRequestRepository.cs | 13 +++++++++---- .../Repositories/TransactionRepository.cs | 3 +-- .../Types/Mutations/TransactionMutationResolvers.cs | 3 +-- .../Queries/BankingInstitutionQueryResolvers.cs | 4 +--- .../Types/Queries/TransactionQueryResolvers.cs | 13 ++----------- .../Utility/MockDataAccessService.cs | 4 +--- 9 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTag.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTag.cs index 3a4558f..7e65946 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTag.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTag.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RobinTTY.PersonalFinanceDashboard.API.EfModels; +namespace RobinTTY.PersonalFinanceDashboard.API.EfModels; /// /// A tag can be used to add additional information to transactions. diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTransaction.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTransaction.cs index 62cf5e7..0b85076 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTransaction.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/EfModels/EfTransaction.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; - -namespace RobinTTY.PersonalFinanceDashboard.API.EfModels; +namespace RobinTTY.PersonalFinanceDashboard.API.EfModels; /// /// A transaction represents a monetary exchange between 2 parties. diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs index 9798393..5636a5c 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs @@ -1,4 +1,6 @@ global using System; +global using System.Linq; +global using System.Threading; global using System.Collections.Generic; global using System.Threading.Tasks; global using Serilog; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs index 1744690..2ecff66 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs @@ -9,20 +9,25 @@ namespace RobinTTY.PersonalFinanceDashboard.API.Repositories; /// public class AuthenticationRequestRepository { - private readonly GoCardlessDataProvider _dataProvider; private readonly ApplicationDbContext _dbContext; + private readonly GoCardlessDataProvider _dataProvider; /// /// Creates a new instance of . /// - /// The data provider to use for data retrieval. /// The to use for data retrieval. - public AuthenticationRequestRepository(GoCardlessDataProvider dataProvider, ApplicationDbContext dbContext) + /// The data provider to use for data retrieval. + public AuthenticationRequestRepository(ApplicationDbContext dbContext, GoCardlessDataProvider dataProvider) { - _dataProvider = dataProvider; _dbContext = dbContext; + _dataProvider = dataProvider; } + /// + /// Gets the matching the specified authentication id. + /// + /// The id of the to return. + /// The if one ist matched otherwise . public async Task Get(string authenticationId) { var requests = await _dataProvider.GetAuthenticationRequest(authenticationId); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs index fc15a64..c713e21 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using RobinTTY.PersonalFinanceDashboard.API.EfModels; using RobinTTY.PersonalFinanceDashboard.Core.Models; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs index 020a072..e2cf462 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using HotChocolate.Types; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs index 83d62aa..f94eaaf 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs @@ -1,6 +1,4 @@ -using System.Linq; -using System.Threading.Tasks; -using HotChocolate.Types; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs index 47c16dc..420bd56 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using HotChocolate.Types; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; @@ -10,17 +7,11 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; [QueryType] public class TransactionQueryResolvers { - /// - /// Creates a new instance of . - /// - public TransactionQueryResolvers() - { - } - /// /// Look up transactions of an account. /// /// The id of the account to retrieve. + /// The repository to use for data retrieval. [UsePaging] public async Task> GetTransactions(string accountId, TransactionRepository repository, CancellationToken cancellationToken) { diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/MockDataAccessService.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/MockDataAccessService.cs index f633445..fb6fd3e 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/MockDataAccessService.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Utility/MockDataAccessService.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using Bogus; +using Bogus; using RobinTTY.PersonalFinanceDashboard.Core.Models; namespace RobinTTY.PersonalFinanceDashboard.API.Utility; From 505277f9cc845b84e5b598aa0fa00dcdc006ad50 Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Fri, 27 Oct 2023 02:10:20 +0200 Subject: [PATCH 6/8] Add AccountRepository --- .../Repositories/AccountRepository.cs | 31 +++++++++++++++++++ .../Types/Queries/AccountQueryResolvers.cs | 24 +++++--------- 2 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs new file mode 100644 index 0000000..c20571b --- /dev/null +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs @@ -0,0 +1,31 @@ +using RobinTTY.PersonalFinanceDashboard.Core.Models; +using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; + +namespace RobinTTY.PersonalFinanceDashboard.API.Repositories; + +/// +/// Manages data retrieval. +/// +public class AccountRepository +{ + private readonly ApplicationDbContext _dbContext; + private readonly GoCardlessDataProvider _dataProvider; + + public AccountRepository(ApplicationDbContext dbContext, GoCardlessDataProvider dataProvider) + { + _dbContext = dbContext; + _dataProvider = dataProvider; + } + + public async Task Get(string accountId) + { + var account = await _dataProvider.GetBankAccount(accountId); + return account.Result; + } + + public async Task> Get(IEnumerable accountIds) + { + var accounts = await _dataProvider.GetBankAccounts(accountIds); + return accounts.Select(query => query.Result)!; + } +} \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs index 565b259..b38c4df 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs @@ -1,7 +1,6 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using System.Collections; using HotChocolate.Types; +using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; @@ -10,32 +9,25 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; [QueryType] public sealed class AccountQueryResolvers { - private readonly GoCardlessDataProvider _dataProvider; - - public AccountQueryResolvers(GoCardlessDataProvider dataProvider) - { - _dataProvider = dataProvider; - } - // TODO: probably should be GetBankAccount and then separate route for investment accounts /// /// Look up an account by its id. /// /// The id of the account to lookup. - public async Task GetAccount(string accountId) + /// The repository to use for data retrieval. + public async Task GetAccount(string accountId, AccountRepository repository) { - var account = await _dataProvider.GetBankAccount(accountId); - return account.Result; + return await repository.Get(accountId); } /// /// Look up accounts by a list of ids. /// /// The ids of the accounts to retrieve. + /// The repository to use for data retrieval. [UsePaging] - public async Task> GetAccounts(IEnumerable accountIds) + public async Task> GetAccounts(IEnumerable accountIds, AccountRepository repository) { - var accounts = await _dataProvider.GetBankAccounts(accountIds); - return accounts.Select(query => query.Result).AsQueryable()!; + return await repository.Get(accountIds); } } From e0c52c6ccbc757a754c6a3ee1bc861a8945fe751 Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Fri, 27 Oct 2023 02:51:32 +0200 Subject: [PATCH 7/8] Add documentation --- .../Repositories/AccountRepository.cs | 15 ++++++++++++++ .../AuthenticationRequestRepository.cs | 18 ++++++++++++++++- .../Repositories/TransactionRepository.cs | 20 +++++++++++++++++++ .../Mutations/TransactionMutationResolvers.cs | 18 ++++++++++++++++- .../Types/Queries/AccountQueryResolvers.cs | 7 ++++--- .../AuthenticationRequestQueryResolvers.cs | 5 +++++ .../BankingInstitutionQueryResolvers.cs | 7 +++++++ .../Queries/TransactionQueryResolvers.cs | 3 +++ .../Etoro/Models/EtoroDividends.cs | 2 +- 9 files changed, 89 insertions(+), 6 deletions(-) diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs index c20571b..9978d35 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AccountRepository.cs @@ -11,18 +11,33 @@ public class AccountRepository private readonly ApplicationDbContext _dbContext; private readonly GoCardlessDataProvider _dataProvider; + /// + /// Creates a new instance of . + /// + /// The to use for data retrieval. + /// The data provider to use for data retrieval. public AccountRepository(ApplicationDbContext dbContext, GoCardlessDataProvider dataProvider) { _dbContext = dbContext; _dataProvider = dataProvider; } + /// + /// Gets the matching the specified id. + /// + /// The id of the account to retrieve. + /// The if one ist matched otherwise . public async Task Get(string accountId) { var account = await _dataProvider.GetBankAccount(accountId); return account.Result; } + /// + /// Gets the s matching the specified ids. + /// + /// The ids of the accounts to retrieve. + /// A list of the matched s. public async Task> Get(IEnumerable accountIds) { var accounts = await _dataProvider.GetBankAccounts(accountIds); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs index 2ecff66..cd00c81 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs @@ -26,7 +26,7 @@ public AuthenticationRequestRepository(ApplicationDbContext dbContext, GoCardles /// /// Gets the matching the specified authentication id. /// - /// The id of the to return. + /// The id of the to retrieve. /// The if one ist matched otherwise . public async Task Get(string authenticationId) { @@ -34,6 +34,10 @@ public AuthenticationRequestRepository(ApplicationDbContext dbContext, GoCardles return requests.Result!; } + /// + /// Gets all s. + /// + /// A list of all s. public async Task> GetAll() { // TODO: limit @@ -41,12 +45,24 @@ public async Task> GetAll() return requests.Result!; } + /// + /// Adds a new . + /// + /// The id of the institution to create a for. + /// The URI of the page to redirect to after successful authentication. + /// The added . public async Task Add(string institutionId, string redirectUri) { + // TODO: URI validation (here or in resolver?) var request = await _dataProvider.CreateAuthenticationRequest(institutionId, new Uri(redirectUri)); return request.Result!; } + /// + /// Deletes an existing . + /// + /// The id of the to delete. + /// TODO public async Task Delete(string authenticationId) { var request = await _dataProvider.DeleteAuthenticationRequest(authenticationId); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs index c713e21..801f4dc 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/TransactionRepository.cs @@ -20,6 +20,10 @@ public TransactionRepository(ApplicationDbContext dbContext) _dbContext = dbContext; } + /// + /// Gets all s. + /// + /// A list of all s. public async Task> GetAll() { // TODO @@ -34,6 +38,11 @@ public async Task> GetAll() return transformed; } + /// + /// Adds a new . + /// + /// The to add. + /// The added . public async Task Add(Transaction transaction) { // TODO: Automate mapping @@ -45,6 +54,12 @@ public async Task Add(Transaction transaction) return transaction; } + /// + /// Updates an existing . + /// + /// The to update. + /// The updated . + /// TODO: return Transaction not EfTransaction public async Task Update(EfTransaction transaction) { _dbContext.Transactions.Update(transaction); @@ -52,6 +67,11 @@ public async Task Update(EfTransaction transaction) return transaction; } + /// + /// Deletes an existing . + /// + /// The id of the transaction to delete. + /// TODO public async Task Delete(string transactionId) { var result = await _dbContext.Transactions.Where(t => t.Id == transactionId).ExecuteDeleteAsync(); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs index e2cf462..886ac37 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Mutations/TransactionMutationResolvers.cs @@ -4,12 +4,17 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Mutations; +/// +/// related mutation resolvers. +/// [MutationType] public class TransactionMutationResolvers { /// /// Create a new transaction. /// + /// The transaction to create. + /// The repository to use for data mutation. /// TODO: Change param to CreateTransactionInput type public async Task CreateTransaction(Transaction transaction, TransactionRepository repository) { @@ -17,6 +22,11 @@ public async Task CreateTransaction(Transaction transaction, Transa return transaction; } + /// + /// Delete an existing transaction. + /// + /// The id of the transaction to delete. + /// The repository to use for data mutation. public async Task DeleteTransaction(string transactionId, TransactionRepository repository) { var result = await repository.Delete(transactionId); @@ -25,7 +35,13 @@ public async Task DeleteTransaction(string transactionId, TransactionR } } +/// +/// TODO +/// public class Response { - public string Id { get; set; } + /// + /// TODO + /// + public required string Id { get; set; } } \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs index b38c4df..3fe1a32 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs @@ -1,11 +1,12 @@ -using System.Collections; -using HotChocolate.Types; +using HotChocolate.Types; using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; -using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; +/// +/// related query resolvers. +/// [QueryType] public sealed class AccountQueryResolvers { diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs index 434fa2a..b6ca82d 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs @@ -4,6 +4,9 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; +/// +/// related query resolvers. +/// [QueryType] public class AuthenticationRequestQueryResolvers { @@ -11,6 +14,7 @@ public class AuthenticationRequestQueryResolvers /// Look up authentication requests by their id. /// /// The id of the authentication request to retrieve. + /// The repository to use for data retrieval. public async Task GetAuthenticationRequest(string authenticationId, AuthenticationRequestRepository repository) { return await repository.Get(authenticationId); @@ -19,6 +23,7 @@ public class AuthenticationRequestQueryResolvers /// /// Look up authentication requests. /// + /// The repository to use for data retrieval. public async Task> GetAuthenticationRequests(AuthenticationRequestRepository repository) { return await repository.GetAll(); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs index f94eaaf..9d2bbc0 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs @@ -4,11 +4,18 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; +/// +/// related query resolvers. +/// [QueryType] public class BankingInstitutionQueryResolvers { private readonly GoCardlessDataProvider _dataProvider; + /// + /// TODO: Create repository + /// + /// public BankingInstitutionQueryResolvers(GoCardlessDataProvider dataProvider) { _dataProvider = dataProvider; diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs index 420bd56..ef312e1 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/TransactionQueryResolvers.cs @@ -4,6 +4,9 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; +/// +/// related query resolvers. +/// [QueryType] public class TransactionQueryResolvers { diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.DataImport/Etoro/Models/EtoroDividends.cs b/src/server/RobinTTY.PersonalFinanceDashboard.DataImport/Etoro/Models/EtoroDividends.cs index a4a5746..e2fbf2e 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.DataImport/Etoro/Models/EtoroDividends.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.DataImport/Etoro/Models/EtoroDividends.cs @@ -44,7 +44,7 @@ public class EtoroDividends public EtoroInstrumentType Type { get; set; } /// /// The International Securities Identification Number of the instrument for which this dividend payment was made. - /// [Column("ISIN")] public string Isin { get; set; } From f1e1ce4425c1e221717a51e6041506e7b808c61e Mon Sep 17 00:00:00 2001 From: RobinTTY Date: Fri, 27 Oct 2023 03:12:58 +0200 Subject: [PATCH 8/8] Add BankingInstitutionRepository --- .../Program.cs | 11 +++-- .../AuthenticationRequestRepository.cs | 2 +- .../BankingInstitutionRepository.cs | 45 +++++++++++++++++++ .../Types/Queries/AccountQueryResolvers.cs | 2 +- .../AuthenticationRequestQueryResolvers.cs | 2 +- .../BankingInstitutionQueryResolvers.cs | 18 ++++---- 6 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/BankingInstitutionRepository.cs diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs index 5636a5c..0ce102c 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Program.cs @@ -31,10 +31,13 @@ builder.Services.AddDbContextPool(options => options.UseSqlite("Data Source=application.db")); +// TODO: automatic registration of repositories via codegen? // General Services builder.Services - .AddScoped() + .AddScoped() .AddScoped() + .AddScoped() + .AddScoped() .AddSingleton(new NordigenClientCredentials(appConfig.NordigenApi!.SecretId, appConfig.NordigenApi.SecretKey)) .AddSingleton(); @@ -50,8 +53,10 @@ .AddGraphQLServer() .AddTypes() .AddMutationConventions() - .RegisterService(ServiceKind.Resolver) - .RegisterService(ServiceKind.Resolver); + .RegisterService(ServiceKind.Resolver) + .RegisterService(ServiceKind.Resolver) + .RegisterService(ServiceKind.Resolver) + .RegisterService(ServiceKind.Resolver); var app = builder.Build(); diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs index cd00c81..d59da66 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/AuthenticationRequestRepository.cs @@ -24,7 +24,7 @@ public AuthenticationRequestRepository(ApplicationDbContext dbContext, GoCardles } /// - /// Gets the matching the specified authentication id. + /// Gets the matching the specified id. /// /// The id of the to retrieve. /// The if one ist matched otherwise . diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/BankingInstitutionRepository.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/BankingInstitutionRepository.cs new file mode 100644 index 0000000..7e20b24 --- /dev/null +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Repositories/BankingInstitutionRepository.cs @@ -0,0 +1,45 @@ +using RobinTTY.PersonalFinanceDashboard.Core.Models; +using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; + +namespace RobinTTY.PersonalFinanceDashboard.API.Repositories; + +/// +/// Manages data retrieval. +/// +public class BankingInstitutionRepository +{ + private readonly ApplicationDbContext _dbContext; + private readonly GoCardlessDataProvider _dataProvider; + + /// + /// Creates a new instance of . + /// + /// The to use for data retrieval. + /// The data provider to use for data retrieval. + public BankingInstitutionRepository(ApplicationDbContext dbContext, GoCardlessDataProvider dataProvider) + { + _dbContext = dbContext; + _dataProvider = dataProvider; + } + + /// + /// Gets the matching the specified id. + /// + /// The id of the to retrieve. + /// The if one ist matched otherwise . + public async Task Get(string institutionId) + { + var request = await _dataProvider.GetBankingInstitution(institutionId); + return request.Result!; + } + + /// + /// Gets all s. + /// + /// A list of all s. + public async Task> GetAll(string? countryCode) + { + var request = await _dataProvider.GetBankingInstitutions(countryCode); + return request.Result!; + } +} \ No newline at end of file diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs index 3fe1a32..84708f4 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AccountQueryResolvers.cs @@ -16,7 +16,7 @@ public sealed class AccountQueryResolvers /// /// The id of the account to lookup. /// The repository to use for data retrieval. - public async Task GetAccount(string accountId, AccountRepository repository) + public async Task GetAccount(string accountId, AccountRepository repository) { return await repository.Get(accountId); } diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs index b6ca82d..9ec5b94 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/AuthenticationRequestQueryResolvers.cs @@ -15,7 +15,7 @@ public class AuthenticationRequestQueryResolvers /// /// The id of the authentication request to retrieve. /// The repository to use for data retrieval. - public async Task GetAuthenticationRequest(string authenticationId, AuthenticationRequestRepository repository) + public async Task GetAuthenticationRequest(string authenticationId, AuthenticationRequestRepository repository) { return await repository.Get(authenticationId); } diff --git a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs index 9d2bbc0..1630731 100644 --- a/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs +++ b/src/server/RobinTTY.PersonalFinanceDashboard.API/Types/Queries/BankingInstitutionQueryResolvers.cs @@ -1,4 +1,5 @@ using HotChocolate.Types; +using RobinTTY.PersonalFinanceDashboard.API.Repositories; using RobinTTY.PersonalFinanceDashboard.Core.Models; using RobinTTY.PersonalFinanceDashboard.ThirdPartyDataProviders; @@ -11,7 +12,7 @@ namespace RobinTTY.PersonalFinanceDashboard.Api.Types.Queries; public class BankingInstitutionQueryResolvers { private readonly GoCardlessDataProvider _dataProvider; - + /// /// TODO: Create repository /// @@ -20,15 +21,15 @@ public BankingInstitutionQueryResolvers(GoCardlessDataProvider dataProvider) { _dataProvider = dataProvider; } - + /// /// Look up banking institutions by their id. /// /// The id of the banking institution to retrieve. - public async Task GetBankingInstitution(string institutionId) + public async Task GetBankingInstitution(string institutionId, + BankingInstitutionRepository repository) { - var request = await _dataProvider.GetBankingInstitution(institutionId); - return request.Result!; + return await repository.Get(institutionId); } /// @@ -36,8 +37,9 @@ public async Task GetBankingInstitution(string institutionId /// /// Optional filter by country the institution operates in. [UsePaging(MaxPageSize = 3000)] - public async Task> GetBankingInstitutions(string? countryCode = null) { - var request = await _dataProvider.GetBankingInstitutions(countryCode); - return request.Result!; + public async Task> GetBankingInstitutions(BankingInstitutionRepository repository, + string? countryCode = null) + { + return await repository.GetAll(countryCode); } } \ No newline at end of file