Add UserRole controller + bits and pieces
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Imprink.Domain.Repositories;
|
||||
using Imprink.Domain.Repositories.Products;
|
||||
|
||||
namespace Imprink.Application;
|
||||
|
||||
@@ -8,6 +9,8 @@ public interface IUnitOfWork
|
||||
public ICategoryRepository CategoryRepository { get; }
|
||||
public IProductVariantRepository ProductVariantRepository { get; }
|
||||
public IUserRepository UserRepository { get; }
|
||||
public IUserRoleRepository UserRoleRepository { get; }
|
||||
public IRoleRepository RoleRepository { get; }
|
||||
|
||||
Task SaveAsync(CancellationToken cancellationToken = default);
|
||||
Task BeginTransactionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
15
src/Imprink.Application/Users/GetUserRolesHandler.cs
Normal file
15
src/Imprink.Application/Users/GetUserRolesHandler.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Imprink.Domain.Entities.Users;
|
||||
using MediatR;
|
||||
|
||||
namespace Imprink.Application.Users;
|
||||
|
||||
public record GetUserRolesCommand(string Sub) : IRequest<IEnumerable<Role>>;
|
||||
|
||||
public class GetUserRolesHandler(IUnitOfWork uw): IRequestHandler<GetUserRolesCommand, IEnumerable<Role>>
|
||||
{
|
||||
public async Task<IEnumerable<Role>> Handle(GetUserRolesCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await uw.UserRepository.UserExistsAsync(request.Sub, cancellationToken)) return [];
|
||||
return await uw.UserRoleRepository.GetUserRolesAsync(request.Sub, cancellationToken);;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user