package com.rongyichuang.role.api;
|
|
import com.rongyichuang.role.dto.response.RoleResponse;
|
import com.rongyichuang.role.service.RoleService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.graphql.data.method.annotation.Argument;
|
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
import org.springframework.stereotype.Controller;
|
|
import java.util.List;
|
|
/**
|
* 角色GraphQL API控制器
|
*/
|
@Controller
|
public class RoleGraphqlApi {
|
|
@Autowired
|
private RoleService roleService;
|
|
/**
|
* 获取所有角色列表
|
*/
|
@QueryMapping
|
public List<RoleResponse> roles() {
|
return roleService.getAllRoles();
|
}
|
|
/**
|
* 获取所有启用状态的角色
|
*/
|
@QueryMapping
|
public List<RoleResponse> activeRoles() {
|
return roleService.getAllActiveRoles();
|
}
|
|
/**
|
* 根据ID获取角色详情
|
*/
|
@QueryMapping
|
public RoleResponse role(@Argument Long id) {
|
return roleService.getRoleById(id).orElse(null);
|
}
|
|
/**
|
* 根据角色代码获取角色
|
*/
|
@QueryMapping
|
public RoleResponse roleByCode(@Argument String code) {
|
return roleService.getRoleByCode(code).orElse(null);
|
}
|
|
/**
|
* 根据状态获取角色
|
*/
|
@QueryMapping
|
public List<RoleResponse> rolesByState(@Argument Integer state) {
|
return roleService.getRolesByState(state);
|
}
|
|
/**
|
* 根据名称模糊查询角色
|
*/
|
@QueryMapping
|
public List<RoleResponse> rolesByName(@Argument String name) {
|
return roleService.searchRolesByName(name);
|
}
|
}
|