Added validation and fixed errors

This commit is contained in:
2024-08-25 19:49:28 +03:00
parent c92855e7ce
commit 00aa3ab6af
43 changed files with 621 additions and 147 deletions

View File

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

View File

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

View File

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

View 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);
}
}
}

View File

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

View File

@@ -1,4 +1,5 @@
using Domains.ApplicantDomain;
using Domains;
using Domains.ApplicantDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

View File

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

View File

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

View File

@@ -1,4 +1,5 @@
using Domains.Users;
using Domains;
using Domains.Users;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

View File

@@ -1,4 +1,5 @@
using Domains.ApplicantDomain;
using Domains;
using Domains.ApplicantDomain;
using Domains.VisaApplicationDomain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

View File

@@ -38,6 +38,9 @@ public static class DependencyInjection
services.AddSingleton<IDateTimeProvider, DateTimeProvider>();
services.AddHttpContextAccessor();
services.AddScoped<IUserIdProvider, UserIdProvider>();
services.AddAutoMapper(Assembly.GetExecutingAssembly());
return services;