package com.tuoheng.controller.op;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.dto.RoleMenuDto;
import com.tuoheng.model.entity.Roles;
import com.tuoheng.model.query.RoleClientQuery;
import com.tuoheng.model.query.RoleQuery;
import com.tuoheng.service.CurrentUser;
import com.tuoheng.service.op.RolesService;
import com.tuoheng.until.JsonResult;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author xiaoying
 * @Date 2023/3/20 17:09
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RolesService rolesService;

    /**
     * 获取角色列表
     *
     * @param roleQuery 查询条件
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(RoleQuery roleQuery) {
        return rolesService.getList(roleQuery);
    }

    /**
     * 添加角色
     *
     * @param entity 实体对象
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody Roles entity,@CurrentUser LoginUser loginUser) {
        return rolesService.edit(entity,loginUser);
    }

    /**
     * 编辑角色
     *
     * @param entity 实体对象
     * @return
     */
    @PostMapping("/edit")
    public JsonResult edit(@RequestBody Roles entity,@CurrentUser LoginUser loginUser) {
        return rolesService.edit(entity,loginUser);
    }

    /**
     * 删除角色
     *
     * @param roleIds 角色ID
     * @return
     */
    @DeleteMapping("/delete/{roleIds}")
    public JsonResult delete(@PathVariable("roleIds") Integer[] roleIds) {
        return rolesService.deleteByList(roleIds);
    }

    /**
     * 获取角色菜单列表
     *
     * @param query
     * @return
     */
    @GetMapping("/getMenuList")
    public JsonResult getMenuList(RoleClientQuery query) {
        return rolesService.getMenuList(query);
    }


    /**
     * 保存角色权限数据
     *
     * @param roleMenuDto 角色菜单Dto
     * @return
     */
    @PostMapping("/savePermission")
    public JsonResult savePermission(@RequestBody RoleMenuDto roleMenuDto) {
        return rolesService.savePermission(roleMenuDto);
    }
}
