Added validation and fixed errors
This commit is contained in:
		| @@ -1,4 +1,5 @@ | ||||
| using ApplicationLayer.Services.Applicants.Models; | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
|  | ||||
| @@ -9,6 +10,11 @@ namespace Infrastructure.Automapper.Profiles | ||||
|         public ApplicantProfile() | ||||
|         { | ||||
|             CreateMap<Applicant, ApplicantModel>(MemberList.Destination); | ||||
|  | ||||
|             CreateMap<RegisterApplicantRequest, Applicant>(MemberList.Destination) | ||||
|                 .ForMember(a => a.UserId, opts => opts.Ignore()) | ||||
|                 .ForMember(a => a.Name, | ||||
|                     opts => opts.MapFrom(r => r.ApplicantName)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,16 @@ | ||||
| using ApplicationLayer.Services.Applicants.Models; | ||||
| using AutoMapper; | ||||
| using Domains.ApplicantDomain; | ||||
|  | ||||
| namespace Infrastructure.Automapper.Profiles | ||||
| { | ||||
|     public class PlaceOfWorkProfile : Profile | ||||
|     { | ||||
|         public PlaceOfWorkProfile() | ||||
|         { | ||||
|             CreateMap<PlaceOfWorkModel, PlaceOfWork>(MemberList.Destination) | ||||
|                 .ForMember(p => p.Id, | ||||
|                     opts => opts.UseDestinationValue()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
| using AutoMapper; | ||||
| using Domains.Users; | ||||
|  | ||||
| @@ -8,11 +8,7 @@ namespace Infrastructure.Automapper.Profiles | ||||
|     { | ||||
|         public UserProfile() | ||||
|         { | ||||
|             CreateMap<RegisterApplicantRequest, User>(MemberList.Destination) | ||||
|                 .ForMember(u => u.Role, | ||||
|                     opts => opts.Ignore()); | ||||
|  | ||||
|             CreateMap<RegisterRequest, User>() | ||||
|             CreateMap<AuthData, User>(MemberList.Destination) | ||||
|                 .ForMember(u => u.Role, | ||||
|                     opts => opts.Ignore()); | ||||
|         } | ||||
|   | ||||
							
								
								
									
										19
									
								
								SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								SchengenVisaApi/Infrastructure/Common/UserIdProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| using System.Security.Claims; | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using Microsoft.AspNetCore.Http; | ||||
|  | ||||
| namespace Infrastructure.Common | ||||
| { | ||||
|     public class UserIdProvider(IHttpContextAccessor contextAccessor) : IUserIdProvider | ||||
|     { | ||||
|         Guid IUserIdProvider.GetUserId() | ||||
|         { | ||||
|             var claim = contextAccessor.HttpContext!.User.Claims.SingleOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier); | ||||
|             if (claim is null) | ||||
|             { | ||||
|                 throw new InvalidOperationException("UserIdProvider call for request with no authorization"); | ||||
|             } | ||||
|             return Guid.Parse(claim.Value); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains.Users; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
| @@ -31,5 +32,9 @@ public class ApplicantConfiguration : IEntityTypeConfiguration<Applicant> | ||||
|         entity.Property(a => a.CityOfBirth) | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(ConfigurationConstraints.CityNameLength); | ||||
|  | ||||
|         entity.Property(a => a.JobTitle) | ||||
|             .IsUnicode(false) | ||||
|             .HasMaxLength(ConfigurationConstraints.JobTitleLength); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
|   | ||||
| @@ -18,7 +18,8 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w | ||||
|             .Include(a => a.PlaceOfWork); | ||||
|     } | ||||
|  | ||||
|     async Task<Applicant> IApplicantsRepository.FindByUserIdAsync(Guid userId, CancellationToken cancellationToken) | ||||
|     /// <inheritdoc cref="IApplicantsRepository.FindByUserIdAsync"/> | ||||
|     public async Task<Applicant> FindByUserIdAsync(Guid userId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var result = await LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); | ||||
|         return result ?? throw new ApplicantNotFoundByUserIdException(); | ||||
| @@ -29,4 +30,10 @@ public sealed class ApplicantsRepository(IGenericReader reader, IGenericWriter w | ||||
|         var result = await base.LoadDomain().SingleOrDefaultAsync(a => a.UserId == userId, cancellationToken); | ||||
|         return result?.Id ?? throw new ApplicantNotFoundByUserIdException(); | ||||
|     } | ||||
|  | ||||
|     async Task<bool> IApplicantsRepository.IsApplicantNonResidentByUserId(Guid userId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var applicant = await FindByUserIdAsync(userId, cancellationToken); | ||||
|         return applicant.IsNonResident; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,20 +0,0 @@ | ||||
| namespace Infrastructure.Database | ||||
| { | ||||
|     public static class ConfigurationConstraints | ||||
|     { | ||||
|         public const int CityNameLength = 70; | ||||
|         public const int CountryNameLength = 70; | ||||
|         public const int CitizenshipLength = 30; | ||||
|         public const int ReentryPermitNumberLength = 25; | ||||
|         public const int IssuerNameLength = 200; | ||||
|         public const int VisaNameLength = 70; | ||||
|         public const int StreetNameLength = 100; | ||||
|         public const int PlaceOfWorkNameLength = 200; | ||||
|         public const int NameLength = 50; | ||||
|         public const int BuildingNumberLength = 10; | ||||
|         public const int PassportNumberLength = 20; | ||||
|         public const int PhoneNumberLength = 15; | ||||
|         public const int EmailLength = 254; | ||||
|         public const int PasswordLength = 50; | ||||
|     } | ||||
| } | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Domains.Users; | ||||
| using Domains; | ||||
| using Domains.Users; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|  | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains; | ||||
| using Domains.ApplicantDomain; | ||||
| using Domains.VisaApplicationDomain; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||||
|   | ||||
| @@ -38,6 +38,9 @@ public static class DependencyInjection | ||||
|  | ||||
|         services.AddSingleton<IDateTimeProvider, DateTimeProvider>(); | ||||
|  | ||||
|         services.AddHttpContextAccessor(); | ||||
|         services.AddScoped<IUserIdProvider, UserIdProvider>(); | ||||
|  | ||||
|         services.AddAutoMapper(Assembly.GetExecutingAssembly()); | ||||
|  | ||||
|         return services; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user