package ink.wgink.service.role.controller.api;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.dtos.role.RolePermissionDTO;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.service.role.pojo.vos.RolePermissionVO;
import ink.wgink.service.role.service.IRolePermissionService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: RolePermissionController
 * @Description: 角色权限
 * @Author: WangGeng
 * @Date: 2021/2/20 17:54
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "角色权限")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/role/permission")
public class RolePermissionController extends DefaultBaseController {

    @Autowired
    private IRolePermissionService rolePermissionService;

    @ApiOperation(value = "修改角色权限", notes = "修改角色权限接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update/{roleId}")
    @CheckRequestBodyAnnotation
    public SuccessResult update(@PathVariable("roleId") String roleId, @RequestBody RolePermissionVO rolePermissionVO) {
        rolePermissionService.update(roleId, rolePermissionVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "角色权限详情", notes = "角色权限详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "path"),
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list/{roleId}")
    public List<RolePermissionDTO> list(@PathVariable("roleId") String roleId) {
        return rolePermissionService.list(roleId);
    }

}
