From 6c4a40c78424c6f8cd525e416ab1f517d5fff58a Mon Sep 17 00:00:00 2001 From: prtsie Date: Fri, 4 Oct 2024 15:40:30 +0300 Subject: [PATCH 1/2] Added interface IClient fo client, added IClientBase for IClient, removed warnings --- .../Components/Auth/AuthComponent.razor | 2 +- .../Base/VisaClientComponentBase.razor | 2 +- .../UserDataProvider/UserDataProvider.cs | 4 +- .../BlazorWebAssemblyVisaApiClient/Program.cs | 2 +- .../ExcelWriter.cs | 1 - SchengenVisaApi/VisaApiClient/Client.cs | 304 +++++++++++++++++- SchengenVisaApi/VisaApiClient/ClientBase.cs | 29 -- .../VisaApiClient/ClientPartialMethods.cs | 30 ++ SchengenVisaApi/VisaApiClient/IClientBase.cs | 7 + 9 files changed, 345 insertions(+), 36 deletions(-) delete mode 100644 SchengenVisaApi/VisaApiClient/ClientBase.cs create mode 100644 SchengenVisaApi/VisaApiClient/ClientPartialMethods.cs create mode 100644 SchengenVisaApi/VisaApiClient/IClientBase.cs diff --git a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Auth/AuthComponent.razor b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Auth/AuthComponent.razor index d56c24d..5a042ee 100644 --- a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Auth/AuthComponent.razor +++ b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Auth/AuthComponent.razor @@ -10,7 +10,7 @@ [CascadingParameter] private Status? Status { get; set; } - [Inject] private Client Client { get; set; } = null!; + [Inject] private IClient Client { get; set; } = null!; [Inject] private NavigationManager Nav { get; set; } = null!; diff --git a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Base/VisaClientComponentBase.razor b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Base/VisaClientComponentBase.razor index 99d7312..744c340 100644 --- a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Base/VisaClientComponentBase.razor +++ b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Components/Base/VisaClientComponentBase.razor @@ -5,5 +5,5 @@ { [CascadingParameter] protected GlobalErrorHandler ErrorHandler { get; set; } = null!; - [Inject] protected Client Client { get; set; } = null!; + [Inject] protected IClient Client { get; set; } = null!; } diff --git a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Infrastructure/Services/UserDataProvider/UserDataProvider.cs b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Infrastructure/Services/UserDataProvider/UserDataProvider.cs index 7f1bf25..6a64b51 100644 --- a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Infrastructure/Services/UserDataProvider/UserDataProvider.cs +++ b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Infrastructure/Services/UserDataProvider/UserDataProvider.cs @@ -5,7 +5,7 @@ using VisaApiClient; namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.UserDataProvider; -public class UserDataProvider(Client client) : IUserDataProvider +public class UserDataProvider(IClient client) : IUserDataProvider { private readonly static JwtSecurityTokenHandler tokenHandler = new(); @@ -49,4 +49,4 @@ public class UserDataProvider(Client client) : IUserDataProvider OnRoleChanged?.Invoke(); } } -} \ No newline at end of file +} diff --git a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Program.cs b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Program.cs index f43741d..e4ddbde 100644 --- a/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Program.cs +++ b/SchengenVisaApi/BlazorWebAssemblyVisaApiClient/Program.cs @@ -28,7 +28,7 @@ public static class Program const string baseAddress = "https://localhost:44370"; builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new(baseAddress) }); builder.Services.AddBlazorBootstrap(); - builder.Services.AddScoped(sp => new(baseAddress, sp.GetRequiredService())); + builder.Services.AddScoped(sp => new(baseAddress, sp.GetRequiredService())); builder.Services.AddSingleton(); builder.Services.AddScoped(); diff --git a/SchengenVisaApi/Infrastructure/EntityToExcelTemplateWriter/ExcelWriter.cs b/SchengenVisaApi/Infrastructure/EntityToExcelTemplateWriter/ExcelWriter.cs index a935dd2..45a7abc 100644 --- a/SchengenVisaApi/Infrastructure/EntityToExcelTemplateWriter/ExcelWriter.cs +++ b/SchengenVisaApi/Infrastructure/EntityToExcelTemplateWriter/ExcelWriter.cs @@ -3,7 +3,6 @@ using System.Text; using ApplicationLayer.Services.VisaApplications.NeededServices; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; -using Microsoft.Extensions.Primitives; namespace Infrastructure.EntityToExcelTemplateWriter { diff --git a/SchengenVisaApi/VisaApiClient/Client.cs b/SchengenVisaApi/VisaApiClient/Client.cs index 52dd040..a3725de 100644 --- a/SchengenVisaApi/VisaApiClient/Client.cs +++ b/SchengenVisaApi/VisaApiClient/Client.cs @@ -25,7 +25,309 @@ namespace VisaApiClient using System = global::System; [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")] - public partial class Client : ClientBase + public partial interface IClient : IClientBase + { + /// + /// Adds applicant with user account + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAsync(RegisterApplicantRequest? body); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Adds applicant with user account + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAsync(RegisterApplicantRequest? body, System.Threading.CancellationToken cancellationToken); + + /// + /// Adds approving authority with user account + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAuthorityAsync(RegisterRequest? body); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Adds approving authority with user account + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RegisterAuthorityAsync(RegisterRequest? body, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns list of authority accounts + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetAuthorityAccountsAsync(); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns list of authority accounts + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetAuthorityAccountsAsync(System.Threading.CancellationToken cancellationToken); + + /// + /// Changes authority's account authentication data + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task ChangeAuthorityAuthDataAsync(ChangeUserAuthDataRequest? body); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Changes authority's account authentication data + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task ChangeAuthorityAuthDataAsync(ChangeUserAuthDataRequest? body, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns JWT-token for authentication + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task LoginAsync(string? email, string? password); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns JWT-token for authentication + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task LoginAsync(string? email, string? password, System.Threading.CancellationToken cancellationToken); + + /// + /// Removes authority's account + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RemoveAuthorityAccountAsync(System.Guid authorityAccountId); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Removes authority's account + /// + /// + /// Accessible only for admins + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task RemoveAuthorityAccountAsync(System.Guid authorityAccountId, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns applicant info + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicantAsync(); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns applicant info + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicantAsync(System.Threading.CancellationToken cancellationToken); + + /// + /// Returns pending applications + /// + /// + /// Accessible only for approving authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetPendingAsync(); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns pending applications + /// + /// + /// Accessible only for approving authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetPendingAsync(System.Threading.CancellationToken cancellationToken); + + /// + /// Returns application + /// + /// + /// Accessible only for approving authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicationForAuthorityAsync(System.Guid applicationId); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns application + /// + /// + /// Accessible only for approving authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicationForAuthorityAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns application + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicationForApplicantAsync(System.Guid applicationId); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns application + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task GetApplicationForApplicantAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns all applications of one applicant + /// + /// + /// Returns applications of authorized applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetApplicationsForApplicantAsync(); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns all applications of one applicant + /// + /// + /// Returns applications of authorized applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task> GetApplicationsForApplicantAsync(System.Threading.CancellationToken cancellationToken); + + /// + /// Adds new application + /// + /// + /// Adds application for authorized applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task CreateApplicationAsync(VisaApplicationCreateRequest? body); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Adds new application + /// + /// + /// Adds application for authorized applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task CreateApplicationAsync(VisaApplicationCreateRequest? body, System.Threading.CancellationToken cancellationToken); + + /// + /// Sets application status to closed + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task CloseApplicationAsync(System.Guid applicationId); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Sets application status to closed + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task CloseApplicationAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken); + + /// + /// Approve or reject applications + /// + /// + /// Accessible only for authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task SetStatusFromAuthorityAsync(System.Guid applicationId, AuthorityRequestStatuses? status); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Approve or reject applications + /// + /// + /// Accessible only for authorities + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task SetStatusFromAuthorityAsync(System.Guid applicationId, AuthorityRequestStatuses? status, System.Threading.CancellationToken cancellationToken); + + /// + /// Returns application + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task DownloadApplicationForApplicantAsync(System.Guid applicationId); + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// + /// Returns application + /// + /// + /// Accessible only for applicant + /// + /// Success + /// A server side error occurred. + System.Threading.Tasks.Task DownloadApplicationForApplicantAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken); + + } + + [System.CodeDom.Compiler.GeneratedCode("NSwag", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")] + public partial class Client : IClient { #pragma warning disable 8618 private string _baseUrl; diff --git a/SchengenVisaApi/VisaApiClient/ClientBase.cs b/SchengenVisaApi/VisaApiClient/ClientBase.cs deleted file mode 100644 index 94e19a4..0000000 --- a/SchengenVisaApi/VisaApiClient/ClientBase.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Text; - -namespace VisaApiClient; - -public class ClientBase -{ - public AuthToken? AuthToken { get; set; } - - protected Task CreateHttpRequestMessageAsync(CancellationToken cancellationToken) - { - var msg = new HttpRequestMessage(); - - msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AuthToken?.Token); - - return Task.FromResult(msg); - } - - - protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken) - => await Task.CompletedTask; - - protected async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken) - { - await Task.CompletedTask; - } - - protected async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken) - => await Task.CompletedTask; -} \ No newline at end of file diff --git a/SchengenVisaApi/VisaApiClient/ClientPartialMethods.cs b/SchengenVisaApi/VisaApiClient/ClientPartialMethods.cs new file mode 100644 index 0000000..6854e10 --- /dev/null +++ b/SchengenVisaApi/VisaApiClient/ClientPartialMethods.cs @@ -0,0 +1,30 @@ +using System.Text; +// ReSharper disable UnusedParameter.Local + +namespace VisaApiClient; + +public partial class Client +{ + public AuthToken? AuthToken { get; set; } + + private Task CreateHttpRequestMessageAsync(CancellationToken cancellationToken) + { + var msg = new HttpRequestMessage(); + + msg.Headers.Authorization = new("Bearer", AuthToken?.Token); + + return Task.FromResult(msg); + } + + + private async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, string url, CancellationToken cancellationToken) + => await Task.CompletedTask; + + private async Task PrepareRequestAsync(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder, CancellationToken cancellationToken) + { + await Task.CompletedTask; + } + + private async Task ProcessResponseAsync(HttpClient client, HttpResponseMessage response, CancellationToken cancellationToken) + => await Task.CompletedTask; +} diff --git a/SchengenVisaApi/VisaApiClient/IClientBase.cs b/SchengenVisaApi/VisaApiClient/IClientBase.cs new file mode 100644 index 0000000..a4a5deb --- /dev/null +++ b/SchengenVisaApi/VisaApiClient/IClientBase.cs @@ -0,0 +1,7 @@ +namespace VisaApiClient +{ + public interface IClientBase + { + AuthToken? AuthToken { get; set; } + } +} From a97db1ce4b959cf276dac9e8c1639795798fcadd Mon Sep 17 00:00:00 2001 From: prtsie Date: Fri, 4 Oct 2024 15:42:46 +0300 Subject: [PATCH 2/2] Updated nswag configuration --- SchengenVisaApi/VisaApiClient/clientGeneratorConfig.nswag | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SchengenVisaApi/VisaApiClient/clientGeneratorConfig.nswag b/SchengenVisaApi/VisaApiClient/clientGeneratorConfig.nswag index f449f35..e2847f1 100644 --- a/SchengenVisaApi/VisaApiClient/clientGeneratorConfig.nswag +++ b/SchengenVisaApi/VisaApiClient/clientGeneratorConfig.nswag @@ -11,13 +11,13 @@ }, "codeGenerators": { "openApiToCSharpClient": { - "clientBaseClass": "ClientBase", + "clientBaseClass": "", "configurationClass": null, "generateClientClasses": true, "suppressClientClassesOutput": false, - "generateClientInterfaces": false, + "generateClientInterfaces": true, "suppressClientInterfacesOutput": false, - "clientBaseInterface": null, + "clientBaseInterface": "IClientBase", "injectHttpClient": true, "disposeHttpClient": true, "protectedMethods": [],