From 8884bac7fdcce342d61543816219ae4e7c082acd Mon Sep 17 00:00:00 2001 From: prtsie Date: Thu, 29 Aug 2024 13:18:35 +0300 Subject: [PATCH] Fixed issues --- .../Applicants/Models/ApplicantModel.cs | 13 +++++---- .../Services/Users/IUsersService.cs | 5 ++-- .../Services/Users/Models/UserModel.cs | 16 +++++++++++ .../Services/Users/UsersService.cs | 11 +++++--- .../Automapper/Profiles/ApplicantProfile.cs | 17 +++++++----- .../Automapper/Profiles/PlaceOfWorkProfile.cs | 13 +++++---- .../Automapper/Profiles/UserProfile.cs | 13 +++++---- .../Profiles/VisaApplicationProfile.cs | 27 +++++++++++-------- .../Controllers/UsersController.cs | 7 ++--- 9 files changed, 79 insertions(+), 43 deletions(-) create mode 100644 SchengenVisaApi/ApplicationLayer/Services/Users/Models/UserModel.cs diff --git a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs index b8cb159..eecdd6d 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Applicants/Models/ApplicantModel.cs @@ -2,15 +2,14 @@ namespace ApplicationLayer.Services.Applicants.Models; -/// Model of -/// +/// Model of public class ApplicantModel { /// - public Name Name { get; set; } = null!; + public NameModel Name { get; set; } = null!; /// - public Passport Passport { get; set; } = null!; + public PassportModel Passport { get; set; } = null!; /// public DateTime BirthDate { get; set; } @@ -34,16 +33,16 @@ public class ApplicantModel public MaritalStatus MaritalStatus { get; set; } /// - public Name FatherName { get; set; } = null!; + public NameModel FatherName { get; set; } = null!; /// - public Name MotherName { get; set; } = null!; + public NameModel MotherName { get; set; } = null!; /// public string JobTitle { get; set; } = null!; /// - public PlaceOfWork PlaceOfWork { get; set; } = null!; + public PlaceOfWorkModel PlaceOfWork { get; set; } = null!; /// public bool IsNonResident { get; set; } diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs index 713af1c..3ad0ada 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/IUsersService.cs @@ -1,4 +1,5 @@ -using ApplicationLayer.Services.Users.Requests; +using ApplicationLayer.Services.Users.Models; +using ApplicationLayer.Services.Users.Requests; using Domains.Users; namespace ApplicationLayer.Services.Users; @@ -8,7 +9,7 @@ public interface IUsersService { /// Returns all user accounts with role of approving authority /// Cancellation token - Task> GetAuthoritiesAccountsAsync(CancellationToken cancellationToken); + Task> GetAuthoritiesAccountsAsync(CancellationToken cancellationToken); /// Changes authentication data for an authority account /// Request object with identifier of user and new authentication data diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/Models/UserModel.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/Models/UserModel.cs new file mode 100644 index 0000000..36f87b1 --- /dev/null +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/Models/UserModel.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; +using Domains; + +namespace ApplicationLayer.Services.Users.Models +{ + public class UserModel + { + /// Unique Identifier of user + [Required] + public Guid Id { get; private set; } = Guid.NewGuid(); + + [Required] + [MaxLength(ConfigurationConstraints.EmailLength)] + public string Email { get; set; } = null!; + } +} diff --git a/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs b/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs index eaaeb13..529090a 100644 --- a/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs +++ b/SchengenVisaApi/ApplicationLayer/Services/Users/UsersService.cs @@ -2,15 +2,20 @@ using ApplicationLayer.Services.AuthServices.Common; using ApplicationLayer.Services.AuthServices.NeededServices; using ApplicationLayer.Services.Users.Exceptions; +using ApplicationLayer.Services.Users.Models; using ApplicationLayer.Services.Users.Requests; +using AutoMapper; using Domains.Users; namespace ApplicationLayer.Services.Users; -public class UsersService(IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService +public class UsersService(IMapper mapper, IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService { - async Task> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken) => - await users.GetAllOfRoleAsync(Role.ApprovingAuthority, cancellationToken); + async Task> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken) + { + var userList = await users.GetAllOfRoleAsync(Role.ApprovingAuthority, cancellationToken); + return mapper.Map>(userList); + } async Task IUsersService.ChangeAuthorityAuthDataAsync(ChangeUserAuthDataRequest request, CancellationToken cancellationToken) { diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs index 7075996..e410eec 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/ApplicantProfile.cs @@ -9,11 +9,14 @@ public class ApplicantProfile : Profile { public ApplicantProfile() { - CreateMap(MemberList.Destination); + CreateMap(MemberList.Destination).ReverseMap(); - CreateMap(MemberList.Destination) - .ForMember(a => a.UserId, opts => opts.Ignore()) - .ForMember(a => a.Name, - opts => opts.MapFrom(r => r.ApplicantName)); - } -} \ No newline at end of file + CreateMap(MemberList.Destination) + .ForMember(a => a.UserId, opts => opts.Ignore()) + .ForMember(a => a.Name, + opts => opts.MapFrom(r => r.ApplicantName)); + + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + } +} diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs index ea276dd..4754742 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/PlaceOfWorkProfile.cs @@ -8,8 +8,11 @@ public class PlaceOfWorkProfile : Profile { public PlaceOfWorkProfile() { - CreateMap(MemberList.Destination) - .ForMember(p => p.Id, - opts => opts.UseDestinationValue()); - } -} \ No newline at end of file + CreateMap(MemberList.Destination) + .ForMember(p => p.Id, + opts => opts.UseDestinationValue()) + .ReverseMap(); + + CreateMap().ReverseMap(); + } +} diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs index 0b12a78..f99e4de 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/UserProfile.cs @@ -1,4 +1,5 @@ using ApplicationLayer.Services.AuthServices.Common; +using ApplicationLayer.Services.Users.Models; using AutoMapper; using Domains.Users; @@ -8,8 +9,10 @@ public class UserProfile : Profile { public UserProfile() { - CreateMap(MemberList.Destination) - .ForMember(u => u.Role, - opts => opts.Ignore()); - } -} \ No newline at end of file + CreateMap(MemberList.Destination) + .ForMember(u => u.Role, + opts => opts.Ignore()); + + CreateMap(MemberList.Destination); + } +} diff --git a/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs b/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs index 81f5367..1393394 100644 --- a/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs +++ b/SchengenVisaApi/Infrastructure/Automapper/Profiles/VisaApplicationProfile.cs @@ -9,16 +9,21 @@ public class VisaApplicationProfile : Profile { public VisaApplicationProfile() { - CreateMap(MemberList.Destination); + CreateMap(MemberList.Destination); - CreateMap(MemberList.Destination) - .ForMember(model => model.Applicant, - opts => opts.Ignore()); - - CreateMap(MemberList.Destination) - .ForMember(va => va.RequestDate, - opts => opts.Ignore()) - .ForMember(va => va.ApplicantId, + CreateMap(MemberList.Destination) + .ForMember(model => model.Applicant, opts => opts.Ignore()); - } -} \ No newline at end of file + + CreateMap(MemberList.Destination) + .ForMember(va => va.RequestDate, + opts => opts.Ignore()) + .ForMember(va => va.ApplicantId, + opts => opts.Ignore()); + + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + } +} diff --git a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs index 2a82f07..18ce839 100644 --- a/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs +++ b/SchengenVisaApi/SchengenVisaApi/Controllers/UsersController.cs @@ -20,7 +20,8 @@ public class UsersController( ILoginService loginService, IUsersService usersService, IValidator registerApplicantRequestValidator, - IValidator authDataValidator) : ControllerBase + IValidator authDataValidator, + IValidator registerRequestValidator) : ControllerBase { /// Adds applicant with user account [HttpPost("register")] @@ -46,7 +47,7 @@ public class UsersController( [Authorize(policy: PolicyConstants.AdminPolicy)] public async Task RegisterAuthority(RegisterRequest request, CancellationToken cancellationToken) { - await authDataValidator.ValidateAndThrowAsync(request.AuthData, cancellationToken); + await registerRequestValidator.ValidateAndThrowAsync(request, cancellationToken); await registerService.RegisterAuthority(request, cancellationToken); return Ok(); @@ -56,7 +57,7 @@ public class UsersController( [HttpGet("login")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status403Forbidden)] - public async Task Login(LoginRequest request, CancellationToken cancellationToken) + public async Task Login([FromQuery] LoginRequest request, CancellationToken cancellationToken) { var result = await loginService.LoginAsync(request, cancellationToken); return Ok(result);