* Managed API to handle User maintenance

* Managed Users view in application
This commit is contained in:
2025-02-20 06:39:06 +01:00
parent cd5990039d
commit 9b8d621f42
19 changed files with 530 additions and 195 deletions

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class FunctionService(OrdersManagementDbContext context, IMapper mapper) : IFunctionService
{
public async Task<IEnumerable<FunctionDto>> GetFunctions()
public async Task<IEnumerable<FunctionDto>> GetAll()
{
IList<FunctionDto> functions = await context.Functions.Select(x => mapper.Map<FunctionDto>(x)).ToListAsync();
return functions;
}
public async Task<FunctionDto?> GetFunctionById(Guid id)
public async Task<FunctionDto?> GetById(Guid id)
{
FunctionDto? function = await context.Functions.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return function;
}
public async Task<FunctionDto?> GetFunctionByName(string name)
public async Task<FunctionDto?> GetByName(string name)
{
FunctionDto? function = await context.Functions.Where(x => x.Name == name)
.Select(x => mapper.Map<FunctionDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return function;
}
public async Task<int> AddFunction(FunctionDto functionDto)
public async Task<int> Add(FunctionDto functionDto)
{
Function function = new Function
{
@@ -42,7 +42,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync();
}
public async Task<int> DeleteFunction(Guid id)
public async Task<int> Delete(Guid id)
{
Function? function = await context.Functions.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;
@@ -52,7 +52,7 @@ public class FunctionService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync();
}
public async Task<int> UpdateFunction(FunctionDto functionDto)
public async Task<int> Update(FunctionDto functionDto)
{
Function function = mapper.Map<Function>(functionDto);
context.Functions.Update(function);

View File

@@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services;
public interface IFunctionService
{
Task<IEnumerable<FunctionDto>> GetFunctions();
Task<FunctionDto?> GetFunctionById(Guid id);
Task<FunctionDto?> GetFunctionByName(string name);
Task<int> AddFunction(FunctionDto functionDto);
Task<int> DeleteFunction(Guid id);
Task<int> UpdateFunction(FunctionDto functionDto);
Task<IEnumerable<FunctionDto>> GetAll();
Task<FunctionDto?> GetById(Guid id);
Task<FunctionDto?> GetByName(string name);
Task<int> Add(FunctionDto functionDto);
Task<int> Delete(Guid id);
Task<int> Update(FunctionDto functionDto);
Task<IEnumerable<FunctionDto>> GetFunctionsByRoleId(Guid roleId);
Task<int> AddFunctionToRole(Guid roleId, Guid functionId);
Task<int> RemoveFunctionFromRole(Guid roleId, Guid functionId);

View File

@@ -4,9 +4,9 @@ namespace OrdersManagementDataModel.Services;
public interface IRoleService
{
Task<IEnumerable<RoleDto>> GetRoles();
Task<RoleDto?> GetRoleById(Guid id);
Task<RoleDto?> GetRoleByName(string name);
Task<int> AddRole(RoleDto roleDto);
Task<int> DeleteRole(Guid id);
Task<IEnumerable<RoleDto>> GetAll();
Task<RoleDto?> GetById(Guid id);
Task<RoleDto?> GetByName(string name);
Task<int> Add(RoleDto roleDto);
Task<int> Delete(Guid id);
}

View File

@@ -4,11 +4,11 @@ namespace OrdersManagementDataModel.Services;
public interface IUserRoleService
{
Task<IEnumerable<UserRoleDto>> GetUserRoles();
Task<UserRoleDto?> GetUserRoleById(Guid id);
Task<int> AddUserRole(UserRoleDto userRoleDto);
Task<int> DeleteUserRole(Guid id);
Task<int> UpdateUserRole(UserRoleDto userRoleDto);
Task<IEnumerable<UserRoleDto>> GetAll();
Task<UserRoleDto?> GetById(Guid id);
Task<int> Add(UserRoleDto userRoleDto);
Task<int> Delete(Guid id);
Task<int> Update(UserRoleDto userRoleDto);
Task<IEnumerable<UserRoleDto>> GetUserRolesByUserId(Guid userId);
Task<IEnumerable<UserRoleDto>> GetUserRolesByRoleId(Guid roleId);
Task<int> AddRoleToUser(Guid userId, Guid roleId);

View File

@@ -4,12 +4,12 @@ namespace OrdersManagementDataModel.Services;
public interface IUserService
{
Task<IEnumerable<UserDto>> GetUsers();
Task<UserDto?> GetUserById(Guid id);
Task<UserDto?> GetUserByUsername(string username);
Task<int> AddUser(UserDto userDto);
Task<int> UpdateUser(UserDto userDto);
Task<int> DeleteUser(Guid id);
Task<IEnumerable<UserDto>> GetAll();
Task<UserDto?> GetById(Guid id);
Task<UserDto?> GetByUsername(string username);
Task<int> Add(UserDto userDto);
Task<int> Update(UserDto userDto);
Task<int> Delete(Guid id);
Task<IList<UserRoleDto>> GetUserRoles(Guid userId);
Task<UserDto?> GetUserByLoginAndPassword(string login, string password);
}

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IRoleService
{
public async Task<IEnumerable<RoleDto>> GetRoles()
public async Task<IEnumerable<RoleDto>> GetAll()
{
IList<RoleDto> roles = await context.Roles.Select(x => mapper.Map<RoleDto>(x)).ToListAsync();
return roles;
}
public async Task<RoleDto?> GetRoleById(Guid id)
public async Task<RoleDto?> GetById(Guid id)
{
RoleDto? role = await context.Roles.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return role;
}
public async Task<RoleDto?> GetRoleByName(string name)
public async Task<RoleDto?> GetByName(string name)
{
RoleDto? role = await context.Roles.Where(x => x.Name == name)
.Select(x => mapper.Map<RoleDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return role;
}
public async Task<int> AddRole(RoleDto roleDto)
public async Task<int> Add(RoleDto roleDto)
{
Role role = new Role
{
@@ -42,7 +42,7 @@ public class RoleService(OrdersManagementDbContext context, IMapper mapper) : IR
return await context.SaveChangesAsync();
}
public async Task<int> DeleteRole(Guid id)
public async Task<int> Delete(Guid id)
{
Role? role = await context.Roles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class UserRoleService(OrdersManagementDbContext context, IMapper mapper) : IUserRoleService
{
public async Task<IEnumerable<UserRoleDto>> GetUserRoles()
public async Task<IEnumerable<UserRoleDto>> GetAll()
{
IList<UserRoleDto> userRoles = await context.UserRoles.Select(x => mapper.Map<UserRoleDto>(x)).ToListAsync();
return userRoles;
}
public async Task<UserRoleDto?> GetUserRoleById(Guid id)
public async Task<UserRoleDto?> GetById(Guid id)
{
UserRoleDto? userRole = await context.UserRoles.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<UserRoleDto>(x)).FirstOrDefaultAsync();
@@ -22,14 +22,14 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper)
return userRole;
}
public Task<int> AddUserRole(UserRoleDto userRoleDto)
public Task<int> Add(UserRoleDto userRoleDto)
{
UserRole userRole = mapper.Map<UserRole>(userRoleDto);
context.UserRoles.Add(userRole);
return context.SaveChangesAsync();
}
public async Task<int> DeleteUserRole(Guid id)
public async Task<int> Delete(Guid id)
{
UserRole? userRole = await context.UserRoles.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;
@@ -39,7 +39,7 @@ public class UserRoleService(OrdersManagementDbContext context, IMapper mapper)
return await context.SaveChangesAsync();
}
public async Task<int> UpdateUserRole(UserRoleDto userRoleDto)
public async Task<int> Update(UserRoleDto userRoleDto)
{
UserRole userRole = mapper.Map<UserRole>(userRoleDto);
context.UserRoles.Update(userRole);

View File

@@ -7,14 +7,14 @@ namespace OrdersManagementDataModel.Services;
public class UserService(OrdersManagementDbContext context, IMapper mapper) : IUserService
{
public async Task<IEnumerable<UserDto>> GetUsers()
public async Task<IEnumerable<UserDto>> GetAll()
{
IList<UserDto> users = await context.Users.Select(x => mapper.Map<UserDto>(x)).ToListAsync();
return users;
}
public async Task<UserDto?> GetUserById(Guid id)
public async Task<UserDto?> GetById(Guid id)
{
UserDto? user = await context.Users.Where(x => x.RowPointer == id)
.Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync();
@@ -22,7 +22,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return user;
}
public async Task<UserDto?> GetUserByUsername(string username)
public async Task<UserDto?> GetByUsername(string username)
{
UserDto? user = await context.Users.Where(x => x.Login == username)
.Select(x => mapper.Map<UserDto>(x)).FirstOrDefaultAsync();
@@ -30,7 +30,7 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return user;
}
public async Task<int> AddUser(UserDto userDto)
public async Task<int> Add(UserDto userDto)
{
User user = new User
{
@@ -50,14 +50,14 @@ public class UserService(OrdersManagementDbContext context, IMapper mapper) : IU
return await context.SaveChangesAsync();
}
public async Task<int> UpdateUser(UserDto userDto)
public async Task<int> Update(UserDto userDto)
{
User user = mapper.Map<User>(userDto);
context.Users.Update(user);
return await context.SaveChangesAsync();
}
public async Task<int> DeleteUser(Guid id)
public async Task<int> Delete(Guid id)
{
User? user = await context.Users.Where(x => x.RowPointer == id).FirstOrDefaultAsync() ?? null;