package cn.qinys.platform.upms.api.controller;


import cn.qinys.platform.base.response.Result;
import cn.qinys.platform.upms.api.req.RoleDepartmentAuthReq;
import cn.qinys.platform.upms.api.resp.DataScopeTreeResp;
import cn.qinys.platform.upms.api.service.IDataScopeService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * 数据权限
 *
 * @author tanlie
 * Date: 2024/6/3 9:19
 */

@RestController
@RequestMapping("/upms/data-scope")
public class DataScopeController {

    @Resource
    IDataScopeService dataScopeService;

    /**
     * 获取后台登录菜单
     *
     * @return
     */
    @GetMapping("/tree")
    public Result<List<DataScopeTreeResp>> getMenuTree() {
        List<DataScopeTreeResp> tree = dataScopeService.getTree();
        return new Result<>(tree);
    }

    /**
     * 新增权限
     *
     * @return
     */
    @GetMapping("/tree/selected")
    public Result<List<Integer>> getMenuSelected(String roleId) {
        List<Integer> selected = dataScopeService.getDepartmentSelected(roleId);
        return new Result<>(selected);
    }

    /**
     * 新增权限
     *
     * @return
     */
    @PostMapping("/auth/create")
    public Result<String> createResource(@RequestBody @Valid RoleDepartmentAuthReq req) {
        dataScopeService.createResource(req);
        return new Result<>("操作成功");
    }

}
