Decouple UserType, add Role entity and management

Removed all UserType logic and references, replacing them with a new Role model and management system. Introduced RoleManager service, repository, and API endpoint for role CRUD operations. Updated user flows and JWT claims to use RoleCode. Removed admin-only user CRUD endpoints. Updated DI, documentation, and error handling for consistency. Appsettings and DTOs now reflect the new role-based approach.
This commit is contained in:
Dhananjaya99
2026-10-19 12:57:07 +05:30
parent fbd079d337
commit 15832d1ae3
19 changed files with 393 additions and 297 deletions
+43
View File
@@ -0,0 +1,43 @@
using AuthHex.Interfaces;
using AuthHex.Models;
using Microsoft.EntityFrameworkCore;
namespace AuthHex.Repos
{
public class RoleManageRepository : IRoleManageRepository
{
private readonly AppDBContext _dbContext;
public RoleManageRepository(AppDBContext dbContext)
{
_dbContext = dbContext;
}
public Task<Role> AddRoleAsync(Role role, CancellationToken ct = default)
{
_dbContext.Roles.Add(role);
return Task.FromResult(role);
}
public async Task<Role?> GetRoleByIdAsync(Guid roleId, CancellationToken ct = default)
{
return await _dbContext.Roles.FirstOrDefaultAsync(r => r.RoleId == roleId, ct);
}
public async Task<List<Role>> ListRolesAsync(CancellationToken ct = default)
{
return await _dbContext.Roles.OrderBy(r => r.Code).ToListAsync(ct);
}
//public async Task<bool> RoleInUseAsync(Guid roleId, CancellationToken ct = default)
//{
// return await _dbContext.Users.AnyAsync(u => u.RoleId == roleId, ct);
//}
public Task DeleteRoleAsync(Role role, CancellationToken ct = default)
{
_dbContext.Roles.Remove(role);
return Task.CompletedTask;
}
}
}
+1 -3
View File
@@ -43,9 +43,8 @@ namespace AuthHex.Repos
}
public async Task<User?> GetUserByIdentifierAndType(string identifier, Guid? userTypeId)
public async Task<User?> GetUserByIdentifierAndType(string identifier)
{
User? user = await _dbContext.Users
.FirstOrDefaultAsync(u =>
u.Email == identifier ||
@@ -70,7 +69,6 @@ namespace AuthHex.Repos
public async Task<User?> GetUserByIdAsync(Guid userId, CancellationToken ct = default)
{
return await _dbContext.Users
.Include(u => u.UserType)
.FirstOrDefaultAsync(u => u.Id == userId, ct);
}