package cn.ey.biz.module.system.controller.admin.appuser;

import cn.ey.biz.common.pojo.PageResult;
import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserPageReqVO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserPageRespVO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserReqVO;
import cn.ey.biz.module.system.controller.admin.appuser.vo.AppUserRespVO;
import cn.ey.biz.module.system.service.appuser.AppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static cn.ey.biz.common.pojo.R.success;

@Api(tags = "管理后台 - 应用用户信息")
@RestController
@RequestMapping("/system/app-user")
@Validated
public class AppUserController {

    @Resource
    private AppUserService appUserService;

    @PostMapping("/create")
    @ApiOperation("应用用户信息")
    public R<Long> createAppUser(
            @Validated(value = AppUserReqVO.Save.class)
            @RequestBody AppUserReqVO reqVO) {
        Long appId = appUserService.createAppUser(reqVO);
        return success(appId);
    }

    @PostMapping("/get")
    @ApiOperation("查询应用用户信息")
    public R<AppUserRespVO> getAppUser(
            @Validated(value = AppUserReqVO.QueryById.class)
            @RequestBody AppUserReqVO reqVO) {
        AppUserRespVO respVO = appUserService.getAppUser(reqVO.getId());
        return success(respVO);
    }

    @PostMapping("/page")
    @ApiOperation("应用用户信息分页查询")
    public R<PageResult<AppUserPageRespVO>> listPage(@RequestBody AppUserPageReqVO appUserReqVO) {
        return success(appUserService.getAppUserPage(appUserReqVO));
    }

}
