Merge remote-tracking branch 'origin/12-client' into 12-client
This commit is contained in:
		| @@ -13,6 +13,7 @@ | |||||||
|         <PackageReference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" Version="3.2.0-rc1.20223.4" /> |         <PackageReference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" Version="3.2.0-rc1.20223.4" /> | ||||||
|         <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1"/> |         <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.1"/> | ||||||
|         <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all"/> |         <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.1" PrivateAssets="all"/> | ||||||
|  |         <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" /> | ||||||
|     </ItemGroup> |     </ItemGroup> | ||||||
|  |  | ||||||
|     <ItemGroup> |     <ItemGroup> | ||||||
|   | |||||||
| @@ -1,11 +1,16 @@ | |||||||
| @using System.Net | @using System.Net | ||||||
|  | @using System.IdentityModel.Tokens.Jwt | ||||||
|  | @using System.Security.Claims | ||||||
| @using BlazorWebAssemblyVisaApiClient.Components.Auth.Exceptions | @using BlazorWebAssemblyVisaApiClient.Components.Auth.Exceptions | ||||||
| @using BlazorWebAssemblyVisaApiClient.ErrorHandling | @using BlazorWebAssemblyVisaApiClient.ErrorHandling | ||||||
| @using VisaApiClient | @using VisaApiClient | ||||||
|  |  | ||||||
| @code { | @code { | ||||||
|     public static bool LoggedIn; |     public static bool LoggedIn; | ||||||
|  |     public static ApplicantModel? CurrentApplicant; //todo api action | ||||||
|  |     public static string? CurrentRole; | ||||||
|     private static AuthData savedData = null!; |     private static AuthData savedData = null!; | ||||||
|  |     private static readonly JwtSecurityTokenHandler TokenHandler = new(); | ||||||
|  |  | ||||||
|     [CascadingParameter] private GlobalErrorHandler ErrorHandler { get; set; } = null!; |     [CascadingParameter] private GlobalErrorHandler ErrorHandler { get; set; } = null!; | ||||||
|  |  | ||||||
| @@ -24,6 +29,10 @@ | |||||||
|         { |         { | ||||||
|             var token = await Client.LoginAsync(authData.Email, authData.Password); |             var token = await Client.LoginAsync(authData.Email, authData.Password); | ||||||
|             Client.SetAuthToken(token); |             Client.SetAuthToken(token); | ||||||
|  |             CurrentRole = TokenHandler.ReadJwtToken(token.Token) | ||||||
|  |                 .Claims | ||||||
|  |                 .FirstOrDefault(claim => claim.Type == ClaimTypes.Role)? | ||||||
|  |                 .Value; | ||||||
|             savedData = authData; |             savedData = authData; | ||||||
|  |  | ||||||
|             Status?.SetSucces("Logged in successfully."); |             Status?.SetSucces("Logged in successfully."); | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| @using System.ComponentModel.DataAnnotations | @using System.Linq.Expressions | ||||||
| @using System.Linq.Expressions |  | ||||||
| @using System.Reflection | @using System.Reflection | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||||
| @typeparam TItem where TItem : class | @typeparam TItem where TItem : class | ||||||
|     @typeparam TMember where TMember : struct, Enum |     @typeparam TMember where TMember : struct, Enum | ||||||
|  |  | ||||||
| @@ -22,18 +22,12 @@ | |||||||
|  |  | ||||||
|     protected override void OnInitialized() |     protected override void OnInitialized() | ||||||
|     { |     { | ||||||
|         var enumMembers = typeof(TMember).GetMembers(); |  | ||||||
|         var modelMemberName = ((MemberExpression)EnumProperty.Body).Member.Name; |         var modelMemberName = ((MemberExpression)EnumProperty.Body).Member.Name; | ||||||
|         modelMemberInfo = typeof(TItem).GetProperty(modelMemberName)!; |         modelMemberInfo = typeof(TItem).GetProperty(modelMemberName)!; | ||||||
|  |  | ||||||
|         foreach (var value in Enum.GetValues<TMember>()) |         foreach (var value in Enum.GetValues<TMember>()) | ||||||
|         { |         { | ||||||
|             var member = enumMembers.First(info => info.Name == value.ToString()); |             enumValues.Add(value, value.GetDisplayName()); | ||||||
|             var displayAttribute = (DisplayAttribute?)member |  | ||||||
|                 .GetCustomAttributes(typeof(DisplayAttribute), false) |  | ||||||
|                 .FirstOrDefault(); |  | ||||||
|             var displayName = displayAttribute?.Name ?? value.ToString(); |  | ||||||
|             enumValues.Add(value, displayName); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services | @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||||
| @using VisaApiClient | @using VisaApiClient | ||||||
|  |  | ||||||
| <div> | <div> | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services; | using BlazorWebAssemblyVisaApiClient.Infrastructure.Services; | ||||||
|  | using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| using VisaApiClient; | using VisaApiClient; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| using BlazorWebAssemblyVisaApiClient.FluentValidation.Applicants.Models; | using BlazorWebAssemblyVisaApiClient.FluentValidation.Applicants.Models; | ||||||
| using BlazorWebAssemblyVisaApiClient.Infrastructure.Services; | using BlazorWebAssemblyVisaApiClient.Infrastructure.Services; | ||||||
|  | using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider; | ||||||
| using FluentValidation; | using FluentValidation; | ||||||
| using VisaApiClient; | using VisaApiClient; | ||||||
| using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.FluentValidation.Applicants.Models.PlaceOfWorkModel; | using PlaceOfWorkModel = BlazorWebAssemblyVisaApiClient.FluentValidation.Applicants.Models.PlaceOfWorkModel; | ||||||
|   | |||||||
| @@ -0,0 +1,18 @@ | |||||||
|  | using System.ComponentModel.DataAnnotations; | ||||||
|  |  | ||||||
|  | namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||||
|  | { | ||||||
|  |     public static class EnumExtensions | ||||||
|  |     { | ||||||
|  |         public static string GetDisplayName(this Enum value) | ||||||
|  |         { | ||||||
|  |             var enumMembers = value.GetType().GetMembers(); | ||||||
|  |             var member = enumMembers.First(info => info.Name == value.ToString()); | ||||||
|  |             var displayAttribute = (DisplayAttribute?)member | ||||||
|  |                 .GetCustomAttributes(typeof(DisplayAttribute), false) | ||||||
|  |                 .FirstOrDefault(); | ||||||
|  |             var displayName = displayAttribute?.Name ?? value.ToString(); | ||||||
|  |             return displayName; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services | namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||||
| { | { | ||||||
|     public class DateTimeProvider : IDateTimeProvider |     public class DateTimeProvider : IDateTimeProvider | ||||||
|     { |     { | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services | namespace BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||||
| { | { | ||||||
|     public interface IDateTimeProvider |     public interface IDateTimeProvider | ||||||
|     { |     { | ||||||
| @@ -0,0 +1,56 @@ | |||||||
|  | @page "/applications" | ||||||
|  | @using System.Net | ||||||
|  | @using System.Text | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Components | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Components.Auth | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Infrastructure.Helpers | ||||||
|  | @using VisaApiClient | ||||||
|  | @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||||
|  |  | ||||||
|  | <PageTitle>@(AuthComponent.CurrentRole ?? "bruh")</PageTitle> | ||||||
|  |  | ||||||
|  | @((MarkupString)htmlMarkup) | ||||||
|  |  | ||||||
|  | @code { | ||||||
|  |     private string htmlMarkup = "bruh"; | ||||||
|  |  | ||||||
|  |     protected override async Task OnInitializedAsync() | ||||||
|  |     { | ||||||
|  |         var stringBuilder = new StringBuilder(); | ||||||
|  |  | ||||||
|  |         try | ||||||
|  |         { | ||||||
|  |             switch (AuthComponent.CurrentRole) | ||||||
|  |         { | ||||||
|  |             case "Applicant": | ||||||
|  |                 var applications = await Client.GetForApplicantAsync(); | ||||||
|  |  | ||||||
|  |                 stringBuilder.AppendLine("<table><tr><th>Destination Country</th><th>Visa Category</th><th>Request date</th><th>Days requested</th><th>Status</th></tr>"); | ||||||
|  |                 foreach (var application in applications) | ||||||
|  |                 { | ||||||
|  |                     stringBuilder.AppendLine($"<tr><th>{application.DestinationCountry}</th><th>{application.VisaCategory.GetDisplayName()}</th><th>{application.RequestDate.ToString("d")}</th><th>{application.ValidDaysRequested}</th><th>{application.Status.GetDisplayName()}</th></tr>"); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 stringBuilder.AppendLine("</table >"); | ||||||
|  |                 htmlMarkup = stringBuilder.ToString(); | ||||||
|  |                 break; | ||||||
|  |                 default: | ||||||
|  |                 htmlMarkup = AuthComponent.CurrentRole; | ||||||
|  |                 break; | ||||||
|  |         } | ||||||
|  |         } | ||||||
|  |         catch (Exception e) | ||||||
|  |         { | ||||||
|  |             if (e is ApiException<ProblemDetails> { Result.Status: (int)HttpStatusCode.Unauthorized } problemDetailsException) | ||||||
|  |             { | ||||||
|  |                 htmlMarkup = problemDetailsException.Result.Detail!; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 //ErrorHandler.Handle(e); | ||||||
|  |                 throw; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -10,6 +10,7 @@ | |||||||
| @using Newtonsoft.Json | @using Newtonsoft.Json | ||||||
| @using Newtonsoft.Json.Linq | @using Newtonsoft.Json.Linq | ||||||
| @using BlazorWebAssemblyVisaApiClient.Components | @using BlazorWebAssemblyVisaApiClient.Components | ||||||
|  | @using BlazorWebAssemblyVisaApiClient.Infrastructure.Services.DateTimeProvider | ||||||
| @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | @inherits BlazorWebAssemblyVisaApiClient.Components.Base.VisaClientComponentBase | ||||||
|  |  | ||||||
| <PageTitle>Registration</PageTitle> | <PageTitle>Registration</PageTitle> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user