package com.wteam.controller.permission;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.framework.common.enums.ResultUtil;
import com.wteam.framework.common.mybatis.util.PageUtil;
import com.wteam.framework.common.vo.PageVO;
import com.wteam.framework.common.vo.ResultMessage;
import com.wteam.framework.modules.permission.entity.dos.Role;
import com.wteam.framework.modules.permission.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 管理端,角色管理接口
 *
 * @author Chopper
 * @since 2020/11/20 18:50
 */
@RestController
@Tag(name = "管理端,角色管理接口")
@RequestMapping("/manager/permission/role")
public class RoleManagerController {
    @Autowired
    private RoleService roleService;

    @PostMapping
    @Operation(summary = "添加")
    public ResultMessage<Role> add(Role role) {
        roleService.save(role);
        return ResultUtil.data(role);
    }

    @GetMapping
    @Operation(summary = "查询")
    public ResultMessage<Page> add(PageVO pageVo, Role role) {
        Page page = roleService.page(PageUtil.initPage(pageVo), PageUtil.initWrapper(role));
        return ResultUtil.data(page);
    }

    @PutMapping("/{roleId}")
    @Operation(summary = "编辑")
    public ResultMessage<Role> edit(@PathVariable String roleId, Role role) {
        role.setId(roleId);
        roleService.updateById(role);
        return ResultUtil.data(role);
    }

    @DeleteMapping(value = "/{ids}")
    @Operation(summary = "批量删除")
    public ResultMessage<Role> delByIds(@PathVariable List<String> ids) {
        roleService.deleteRoles(ids);
        return ResultUtil.success();
    }


}
