package com.kym.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.kym.common.R;
import com.kym.common.controller.IController;
import com.kym.entity.Role;
import com.kym.service.RoleService;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author skyline
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/role")
public class RoleController extends IController {

    private RoleService roleService;

    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }


    @GetMapping("list")
    public R<?>  listRole(String roleName) {
        return resp(()->roleService.listRole(roleName));
    }

    @SaCheckPermission("role.add")
    @PostMapping("add")
    public R<?>  add(@RequestBody Role role) {
        return resp(() -> roleService.add(role));
    }

    @SaCheckPermission("role.modify")
    @PostMapping("modify")
    public R<?> modify(@RequestBody Role role) {
        return resp((t) -> roleService.modify(role));
    }


    @SaCheckPermission("role.delete")
    @PostMapping("delete/{id}")
    public R<?>  delete(@PathVariable (name = "id") int id) {
        return resp((t) -> roleService.remove(id));
    }


    @GetMapping("detail/{id}")
    public R<?>  detail(@PathVariable (name = "id") int id) {
        return resp(() -> roleService.detail(id));
    }



    @SaCheckPermission("role.modify")
    @PostMapping("saveList")
    public R<?>  saveList(@RequestBody List<Role> roleList) {
        return resp((t) -> roleService.saveList(roleList));
    }

}
