package com.njcn.user.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.user.pojo.po.Function;
import com.njcn.user.pojo.vo.FunctionVO;
import com.njcn.user.service.IRoleFunctionService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/roleFunction")
@Api(tags = "角色资源管理")
@AllArgsConstructor
public class RoleFunctionController extends BaseController {
    private final IRoleFunctionService roleFunctionService;

    @OperateInfo
    @PostMapping("/getFunctionsByRoleIndex")
    @ApiOperation("根据角色id查询相关联的资源")
    @ApiImplicitParam(name = "id", value = "角色id", required = true)
    public HttpResult<List<FunctionVO>> getFunctionsByRoleIndex(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getFunctionsByRoleIndex");
        LogUtil.njcnDebug(log,  "{},传入的角色id：{}", methodDescribe,id);
        List<FunctionVO> list = roleFunctionService.getFunctionsByRoleIndex(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}

