package com.zhiqiyun.open.manager.controller;

import com.zhiqiyun.open.annotation.Permission;
import com.zhiqiyun.open.manager.Result;
import com.zhiqiyun.open.models.AuthorityInfo;
import com.zhiqiyun.open.service.AuthorityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
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.authority.find", "oauth.role.authority"}, tags = "查询系统权限")
	@GetMapping("/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);
	}
}
