user service with editing, removing and reading accounts methods, controller actions for this service
This commit is contained in:
		| @@ -0,0 +1,24 @@ | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.ApprovingAuthorities | ||||
| { | ||||
|     /// user accounts service | ||||
|     public interface IUsersService | ||||
|     { | ||||
|         /// Returns all user accounts with role of approving authority | ||||
|         /// <param name="cancellationToken">Cancellation token</param> | ||||
|         Task<List<User>> GetAuthoritiesAccountsAsync(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// Changes authentication data for an account | ||||
|         /// <param name="userId">identifier of account</param> | ||||
|         /// <param name="data">request data with new email and password</param> | ||||
|         /// <param name="cancellationToken">Cancellation token</param> | ||||
|         Task ChangeAccountAuthDataAsync(Guid userId, RegisterRequest data, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// Removes user account | ||||
|         /// <param name="userId">Identifier of account</param> | ||||
|         /// <param name="cancellationToken">Cancellation token</param> | ||||
|         Task RemoveUserAccount(Guid userId, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,34 @@ | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using ApplicationLayer.Services.AuthServices.Requests; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace ApplicationLayer.Services.ApprovingAuthorities | ||||
| { | ||||
|     public class UsersService(IUsersRepository users, IUnitOfWork unitOfWork) : IUsersService | ||||
|     { | ||||
|         async Task<List<User>> IUsersService.GetAuthoritiesAccountsAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             return await users.GetAllOfRoleAsync(Role.ApprovingAuthority, cancellationToken); | ||||
|         } | ||||
|  | ||||
|         async Task IUsersService.ChangeAccountAuthDataAsync(Guid userId, RegisterRequest data, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = await users.GetByIdAsync(userId, cancellationToken); | ||||
|  | ||||
|             user.Email = data.Email; | ||||
|             user.Password = data.Password; | ||||
|             await users.UpdateAsync(user, cancellationToken); | ||||
|  | ||||
|             await unitOfWork.SaveAsync(cancellationToken); | ||||
|         } | ||||
|  | ||||
|         async Task IUsersService.RemoveUserAccount(Guid userId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = await users.GetByIdAsync(userId, cancellationToken); | ||||
|             users.Remove(user); | ||||
|  | ||||
|             await unitOfWork.SaveAsync(cancellationToken); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -11,5 +11,11 @@ namespace ApplicationLayer.Services.AuthServices.NeededServices | ||||
|         /// <param name="cancellationToken">Cancellation token</param> | ||||
|         /// <returns>User or null if not found</returns> | ||||
|         Task<User?> FindByEmailAsync(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// Returns all accounts with specific role | ||||
|         /// <param name="role">role</param> | ||||
|         /// <param name="cancellationToken">cancellation token</param> | ||||
|         /// <returns>list of accounts</returns> | ||||
|         Task<List<User>> GetAllOfRoleAsync(Role role, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user