list of authorities, changing authority auth data
This commit is contained in:
		| @@ -1,9 +0,0 @@ | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.GeneralExceptions; | ||||
|  | ||||
| /// Exception to throw when entity not found | ||||
| /// <param name="id">Identifier of entity</param> | ||||
| /// <typeparam name="T">Type of entity</typeparam> | ||||
| public class EntityNotFoundByIdException<T>(Guid id) : EntityNotFoundException($"{typeof(T).Name} with id {id} not found.") | ||||
|     where T : class, IEntity; | ||||
| @@ -1,6 +0,0 @@ | ||||
| using ApplicationLayer.GeneralExceptions; | ||||
|  | ||||
| namespace ApplicationLayer.Services.GeneralExceptions; | ||||
|  | ||||
| /// Exception to throw when entity not found | ||||
| public class EntityNotFoundException(string message) : ApiException(message); | ||||
| @@ -1,4 +1,4 @@ | ||||
| using ApplicationLayer.Services.GeneralExceptions; | ||||
| using ApplicationLayer.GeneralExceptions; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Users.Exceptions; | ||||
|   | ||||
| @@ -0,0 +1,16 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using Domains; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Users.Models | ||||
| { | ||||
|     /// Auth data with nullable password for making change auth data requests | ||||
|     public class ChangeAuthData | ||||
|     { | ||||
|         [Required] | ||||
|         [MaxLength(ConfigurationConstraints.EmailLength)] | ||||
|         public string Email { get; set; } = null!; | ||||
|  | ||||
|         [MaxLength(ConfigurationConstraints.PasswordLength)] | ||||
|         public string? Password { get; set; } | ||||
|     } | ||||
| } | ||||
| @@ -1,11 +1,11 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
| using ApplicationLayer.Services.Users.Models; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Users.Requests; | ||||
|  | ||||
| public class ChangeUserAuthDataRequest(Guid userId, AuthData newAuthData) | ||||
| public class ChangeUserAuthDataRequest(Guid userId, ChangeAuthData newAuthData) | ||||
| { | ||||
|     [Required] public Guid UserId { get; set; } = userId; | ||||
|  | ||||
|     [Required] public AuthData NewAuthData { get; set; } = newAuthData; | ||||
|     [Required] public ChangeAuthData NewAuthData { get; set; } = newAuthData; | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,21 @@ | ||||
| using Domains; | ||||
| using FluentValidation; | ||||
|  | ||||
| namespace ApplicationLayer.Services.Users.Requests.Validation | ||||
| { | ||||
|     public class ChangeUserAuthDataRequestValidator : AbstractValidator<ChangeUserAuthDataRequest> | ||||
|     { | ||||
|         public ChangeUserAuthDataRequestValidator() | ||||
|         { | ||||
|             RuleFor(r => r.NewAuthData) | ||||
|                 .NotEmpty(); | ||||
|  | ||||
|             RuleFor(r => r.NewAuthData.Email) | ||||
|                 .NotEmpty() | ||||
|                 .EmailAddress() | ||||
|                 .WithMessage("Email should be valid") | ||||
|                 .MaximumLength(ConfigurationConstraints.EmailLength) | ||||
|                 .WithMessage($"Email address length must be less than {ConfigurationConstraints.EmailLength}"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,7 +1,6 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.Applicants.Models; | ||||
| using ApplicationLayer.Services.Applicants.NeededServices; | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using ApplicationLayer.Services.Users.Exceptions; | ||||
| using ApplicationLayer.Services.Users.Models; | ||||
| @@ -53,10 +52,10 @@ public class UsersService( | ||||
|     /// <param name="user">User to remove</param> | ||||
|     /// <param name="authData">New auth data</param> | ||||
|     /// <param name="cancellationToken">Cancellation token</param> | ||||
|     private async Task ChangeAccountAuthDataAsync(User user, AuthData authData, CancellationToken cancellationToken) | ||||
|     private async Task ChangeAccountAuthDataAsync(User user, ChangeAuthData authData, CancellationToken cancellationToken) | ||||
|     { | ||||
|         user.Email = authData.Email; | ||||
|         user.Password = authData.Password; | ||||
|         user.Password = authData.Password ?? user.Password; | ||||
|         await users.UpdateAsync(user, cancellationToken); | ||||
|  | ||||
|         await unitOfWork.SaveAsync(cancellationToken); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user