#48 added basic role features and some cleanUp
This commit is contained in:
@@ -1,21 +1,17 @@
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Domain.Models;
|
||||
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
public interface IIdentityService
|
||||
{
|
||||
Task<string?> GetUserNameAsync(string userId);
|
||||
|
||||
Task CreateUserAsync(string email, string userName, string firstName, string lastName, string password);
|
||||
|
||||
Task<Result> CreateUserAsync(string email, string userName, string firstName, string lastName, string password);
|
||||
Task<UserModel?> FindUserByIdAsync(string id);
|
||||
Task<UserModel?> GetCurrentUserAsync();
|
||||
Task<UserModel?> FindUserByEmailAsync(string id);
|
||||
|
||||
Task<bool> IsInRoleAsync(string userId, string role);
|
||||
|
||||
Task<bool> AuthorizeAsync(string userId, string policyName);
|
||||
|
||||
Task<Result> AddRoleAsync(string userId, string role);
|
||||
Task<IList<string>> GetCurrentUserRolesAsync();
|
||||
Task<Result> DeleteUserAsync(string userId);
|
||||
}
|
||||
|
||||
10
src/Application/Common/Interfaces/IRoleService.cs
Normal file
10
src/Application/Common/Interfaces/IRoleService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Hutopy.Application.Common.Models;
|
||||
|
||||
namespace Hutopy.Application.Common.Interfaces;
|
||||
|
||||
public interface IRoleService
|
||||
{
|
||||
public Task<Result> CreateRoleAsync(string roleName);
|
||||
public Task<Result> DeleteRoleAsync(string roleName);
|
||||
public Task<RoleModel?> FindRoleByIdAsync(string roleId);
|
||||
}
|
||||
7
src/Application/Common/Models/RoleModel.cs
Normal file
7
src/Application/Common/Models/RoleModel.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Hutopy.Application.Common.Models;
|
||||
|
||||
public class RoleModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
10
src/Application/Common/Models/UserModel.cs
Normal file
10
src/Application/Common/Models/UserModel.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Hutopy.Application.Common.Models;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? UserName { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Hutopy.Application.Common.Behaviours;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hutopy.Application;
|
||||
@@ -15,7 +16,7 @@ public static class DependencyInjection
|
||||
{
|
||||
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
||||
//cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
|
||||
//cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
|
||||
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
|
||||
//cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
|
||||
//cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Common.Mappings;
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Application.Common.Security;
|
||||
|
||||
namespace Hutopy.Application.FutureCreators.Queries;
|
||||
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public record GetFutureCreatorListQuery : IRequest<PaginatedList<FutureCreatorListDto>>
|
||||
{
|
||||
public int PageNumber { get; init; } = 1;
|
||||
|
||||
@@ -23,6 +23,8 @@ public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
|
||||
|
||||
public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _identityService.CreateUserAsync(request.EmailAddress, request.UserName, request.FirstName, request.LastName, request.Password);
|
||||
|
||||
var user = await _identityService.FindUserByEmailAsync(request.EmailAddress);
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
@@ -23,14 +23,17 @@ public class GetCurrentUserQueryHandler(
|
||||
.Where(x => x.IsConfirmed == true)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var user = new UserDto()
|
||||
var roles = await identityService.GetCurrentUserRolesAsync();
|
||||
|
||||
var user = new UserDto
|
||||
{
|
||||
Id = currentUserId,
|
||||
FirstName = identityUser?.FirstName ?? "",
|
||||
LastName = identityUser?.LastName ?? "",
|
||||
UserName =identityUser?.UserName ?? "",
|
||||
UserTransactions = transactions,
|
||||
TotalBalance = transactions.Sum(x => x.Amount)
|
||||
TotalBalance = transactions.Sum(x => x.Amount),
|
||||
UserRoles = roles
|
||||
};
|
||||
|
||||
return user;
|
||||
|
||||
@@ -7,6 +7,7 @@ public class UserDto
|
||||
public required string LastName { get; init; }
|
||||
public string UserName { get; init; } = String.Empty;
|
||||
public List<UserTransactionDto> UserTransactions { get; init; } = [];
|
||||
public IList<string> UserRoles { get; init; } = [];
|
||||
|
||||
public required decimal TotalBalance { get; init; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user