list of authorities, changing authority auth data

This commit is contained in:
2024-09-12 21:14:30 +03:00
parent 18e02792ec
commit 9015348aa6
25 changed files with 442 additions and 175 deletions

View File

@@ -1,6 +1,6 @@
using Domains;
namespace ApplicationLayer.Services.GeneralExceptions;
namespace ApplicationLayer.GeneralExceptions;
/// Exception to throw when entity not found
/// <param name="id">Identifier of entity</param>

View File

@@ -1,6 +1,4 @@
using ApplicationLayer.GeneralExceptions;
namespace ApplicationLayer.Services.GeneralExceptions;
namespace ApplicationLayer.GeneralExceptions;
/// Exception to throw when entity not found
public class EntityNotFoundException(string message) : ApiException(message);

View File

@@ -1,4 +1,4 @@
using ApplicationLayer.Services.GeneralExceptions;
using ApplicationLayer.GeneralExceptions;
using Domains.Users;
namespace ApplicationLayer.Services.Users.Exceptions;

View File

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

View File

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

View File

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

View File

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