user service with editing, removing and reading accounts methods, controller actions for this service

This commit is contained in:
2024-08-22 00:23:02 +03:00
parent d1d3a1ab73
commit 85bac2b0a4
8 changed files with 140 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
using ApplicationLayer.Services.AuthServices.LoginService;
using ApplicationLayer.Services.ApprovingAuthorities;
using ApplicationLayer.Services.AuthServices.LoginService;
using ApplicationLayer.Services.AuthServices.RegisterService;
using ApplicationLayer.Services.VisaApplications.Handlers;
using Microsoft.Extensions.DependencyInjection;
@@ -14,6 +15,7 @@ public static class DependencyInjection
services.AddScoped<IVisaApplicationRequestsHandler, VisaApplicationRequestsHandler>();
services.AddScoped<IRegisterService, RegisterService>();
services.AddScoped<IUsersService, UsersService>();
if (isDevelopment)
{

View File

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

View File

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

View File

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