package com.cool.store.controller;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.dto.role.RoleUpdateDTO;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.RoleService;
import com.cool.store.vo.role.RoleAuthInfoVO;
import com.cool.store.vo.role.RolePageVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhangchenbiao
 * @FileName: RoleController
 * @Description:
 * @date 2023-07-25 14:58
 */
@RestController
@Slf4j
@Api(tags = "角色")
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation("角色列表")
    @GetMapping("/role/page")
    public ResponseResult<PageInfo<RolePageVO>> getRolePage(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize){
        return ResponseResult.success(roleService.getRolePage(pageNum, pageSize));
    }

    @ApiOperation("角色权限详情")
    @GetMapping("/role/auth/detail")
    public ResponseResult<RoleAuthInfoVO> getRoleAuthDetail(@RequestParam("roleId")String roleId){
        return ResponseResult.success(roleService.getRoleAuthDetail(roleId));
    }

    @ApiOperation("角色更新")
    @PostMapping("/role/auth/update")
    public ResponseResult updateRoleAuth(@RequestBody RoleUpdateDTO param){
        return ResponseResult.success(roleService.updateRoleAuth(CurrentUserHolder.getUserId(), param));
    }

}
