refactor(role): refactor role management API and service

- Remove unused imports and simplify controller annotations
- Change request mapping path from /api/role to /api/roles
- Update assignRolesToUser endpoint to use POST /users
- Update revokeRolesFromUser endpoint to use DELETE /users
- Modify getAllRoles method to return OptionResponse instead of RoleResponse
- Simplify database query in RoleServiceImpl using lambda query wrapper
- Add proper authorization checks for all role management endpoints
- Remove redundant getUserRole method with duplicate logic
This commit is contained in:
Chaos
2025-11-28 17:01:02 +08:00
parent f0d6279949
commit 647d5733ac
4 changed files with 28 additions and 19 deletions

View File

@@ -27,7 +27,6 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DriveTypeMapper, DeviceTy
@Override
public List<OptionResponse> getDeviceTypeOptions() {
LambdaQueryWrapper<DeviceType> wrapper = new LambdaQueryWrapper<>();
return this.lambdaQuery()
.select(DeviceType::getId, DeviceType::getName)
.list()

View File

@@ -1,6 +1,7 @@
package cn.nopj.chaos_api.service.impl;
import cn.nopj.chaos_api.domain.entity.Role;
import cn.nopj.chaos_api.dto.response.OptionResponse;
import cn.nopj.chaos_api.dto.response.RoleResponse;
import cn.nopj.chaos_api.mapper.RoleMapper;
import cn.nopj.chaos_api.service.RoleService;
@@ -12,7 +13,13 @@ import java.util.List;
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
@Override
public List<RoleResponse> getAllRoles() {
return this.baseMapper.selectList(null).stream().map(RoleResponse::new).toList();
public List<OptionResponse> getAllRoles() {
return this.lambdaQuery()
.select(Role::getId, Role::getName)
.list()
.stream()
.map(role -> new OptionResponse(role.getName(), role.getId().toString()))
.toList();
}
}