package com.zhiqiyun.open.mvc.manager.controller;

import com.zhiqiyun.open.annotation.Permission;
import com.zhiqiyun.open.mvc.Result;
import com.zhiqiyun.open.core.models.user.AuthorityInfo;
import com.zhiqiyun.open.core.service.AuthorityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jtoms
 */
@RestController
@RequestMapping("/user/authority")
public class AuthorityInfoController {

    @Autowired
    private AuthorityInfoService authorityInfoService;

    @Permission(value = {"oauth.role.add", "oauth.role.edit"}, tags = "查询系统权限")
    @PostMapping("/findAllAuthorities")
    public Result findAllAuthorities() {
        List<AuthorityInfo> listData = this.authorityInfoService.findChildren(0L);
        for (AuthorityInfo authority : listData) {
            List<AuthorityInfo> children = this.authorityInfoService.findChildren(authority.getId());
            authority.setChildren(children);
        }
        return Result.instance(Result.Code.SUCCESS).setData(listData);
    }
}
