package ink.wgink.login.oauth2.server.controller.resources;

import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.exceptions.SearchException;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService;
import ink.wgink.pojo.dtos.menu.MenuDTO;
import ink.wgink.pojo.result.ErrorResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: OauthClientController
 * @Description: Oauth客户端
 * @Author: WangGeng
 * @Date: 2019/3/12 11:15 AM
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_RESOURCE_PREFIX + "Oauth客户端")
@RestController
@RequestMapping(ISystemConstant.RESOURCE_PREFIX + "/oauth2client")
public class OAuth2ClientResourceController extends DefaultBaseController {

    @Autowired
    private IOAuth2ClientMenuService oAuth2ClientMenuService;

    @ApiOperation(value = "Oauth2客户端菜单列表", notes = "Oauth2客户端菜单列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "clientId", value = "客户端ID", paramType = "path"),
            @ApiImplicitParam(name = "roleIds", value = "角色ID列表，下划线分割", paramType = "path")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list-all/{clientId}/{roleIds}")
    public List<MenuDTO> list(@PathVariable("clientId") String clientId, @PathVariable("roleIds") String roleIds) throws SearchException {
        return oAuth2ClientMenuService.listAll(clientId, Arrays.asList(roleIds.split("\\_")));
    }


}
