Added interface IClient fo client, added IClientBase for IClient, removed warnings

This commit is contained in:
2024-10-04 15:40:30 +03:00
parent 188a5a14d3
commit 6c4a40c784
9 changed files with 345 additions and 36 deletions

View File

@@ -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!;

View File

@@ -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!;
}

View File

@@ -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();

View File

@@ -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<Client>(sp => new(baseAddress, sp.GetRequiredService<HttpClient>()));
builder.Services.AddScoped<IClient, Client>(sp => new(baseAddress, sp.GetRequiredService<HttpClient>()));
builder.Services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
builder.Services.AddScoped<IUserDataProvider, UserDataProvider>();

View File

@@ -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
{

View File

@@ -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
{
/// <summary>
/// Adds applicant with user account
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RegisterAsync(RegisterApplicantRequest? body);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Adds applicant with user account
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RegisterAsync(RegisterApplicantRequest? body, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Adds approving authority with user account
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RegisterAuthorityAsync(RegisterRequest? body);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Adds approving authority with user account
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RegisterAuthorityAsync(RegisterRequest? body, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns list of authority accounts
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<UserModel>> GetAuthorityAccountsAsync();
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns list of authority accounts
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<UserModel>> GetAuthorityAccountsAsync(System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Changes authority's account authentication data
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task ChangeAuthorityAuthDataAsync(ChangeUserAuthDataRequest? body);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Changes authority's account authentication data
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task ChangeAuthorityAuthDataAsync(ChangeUserAuthDataRequest? body, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns JWT-token for authentication
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<AuthToken> LoginAsync(string? email, string? password);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns JWT-token for authentication
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<AuthToken> LoginAsync(string? email, string? password, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Removes authority's account
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RemoveAuthorityAccountAsync(System.Guid authorityAccountId);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Removes authority's account
/// </summary>
/// <remarks>
/// Accessible only for admins
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task RemoveAuthorityAccountAsync(System.Guid authorityAccountId, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns applicant info
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<ApplicantModel> GetApplicantAsync();
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns applicant info
/// </summary>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<ApplicantModel> GetApplicantAsync(System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns pending applications
/// </summary>
/// <remarks>
/// Accessible only for approving authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<VisaApplicationPreview>> GetPendingAsync();
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns pending applications
/// </summary>
/// <remarks>
/// Accessible only for approving authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<VisaApplicationPreview>> GetPendingAsync(System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for approving authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<VisaApplicationModel> GetApplicationForAuthorityAsync(System.Guid applicationId);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for approving authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<VisaApplicationModel> GetApplicationForAuthorityAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<VisaApplicationModel> GetApplicationForApplicantAsync(System.Guid applicationId);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<VisaApplicationModel> GetApplicationForApplicantAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns all applications of one applicant
/// </summary>
/// <remarks>
/// Returns applications of authorized applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<VisaApplicationPreview>> GetApplicationsForApplicantAsync();
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns all applications of one applicant
/// </summary>
/// <remarks>
/// Returns applications of authorized applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<System.Collections.Generic.ICollection<VisaApplicationPreview>> GetApplicationsForApplicantAsync(System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Adds new application
/// </summary>
/// <remarks>
/// Adds application for authorized applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task CreateApplicationAsync(VisaApplicationCreateRequest? body);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Adds new application
/// </summary>
/// <remarks>
/// Adds application for authorized applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task CreateApplicationAsync(VisaApplicationCreateRequest? body, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Sets application status to closed
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task CloseApplicationAsync(System.Guid applicationId);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Sets application status to closed
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task CloseApplicationAsync(System.Guid applicationId, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Approve or reject applications
/// </summary>
/// <remarks>
/// Accessible only for authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task SetStatusFromAuthorityAsync(System.Guid applicationId, AuthorityRequestStatuses? status);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Approve or reject applications
/// </summary>
/// <remarks>
/// Accessible only for authorities
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task SetStatusFromAuthorityAsync(System.Guid applicationId, AuthorityRequestStatuses? status, System.Threading.CancellationToken cancellationToken);
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<FileResponse> DownloadApplicationForApplicantAsync(System.Guid applicationId);
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <summary>
/// Returns application
/// </summary>
/// <remarks>
/// Accessible only for applicant
/// </remarks>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
System.Threading.Tasks.Task<FileResponse> 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;

View File

@@ -1,29 +0,0 @@
using System.Text;
namespace VisaApiClient;
public class ClientBase
{
public AuthToken? AuthToken { get; set; }
protected Task<HttpRequestMessage> 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;
}

View File

@@ -0,0 +1,30 @@
using System.Text;
// ReSharper disable UnusedParameter.Local
namespace VisaApiClient;
public partial class Client
{
public AuthToken? AuthToken { get; set; }
private Task<HttpRequestMessage> 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;
}

View File

@@ -0,0 +1,7 @@
namespace VisaApiClient
{
public interface IClientBase
{
AuthToken? AuthToken { get; set; }
}
}