package com.jy.system.controller;

import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.validation.DeleteGroup;
import com.jy.system.model.dto.SysPermissionSelectDto;
import com.jy.system.model.entity.SysPermission;
import com.jy.system.service.SysPermissionService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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
 * @since 2024-09-06
 */
@RestController
@RequestMapping("/sysPermission")
public class SysPermissionController {

    @Resource
    private SysPermissionService sysPermissionService;

    /**
     * 获取权限标识列表
     */
    @GetMapping("/getCodeList")
    public List<String> getCodeList() {
        return sysPermissionService.getCodeList();
    }

    /**
     * 鉴权接口列表
     */
    @GetMapping("/getList")
    public List<SysPermission> getList(SysPermissionSelectDto dto) {
        return sysPermissionService.getList(dto);
    }

    /**
     * 鉴权接口编辑
     */
    @PostMapping("/edit")
    public void edit(@Validated @RequestBody SysPermission dto) {
        sysPermissionService.edit(dto);
    }

    /**
     * 鉴权接口删除
     */
    @PostMapping("/delete")
    public void delete(@Validated(DeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysPermissionService.delete(dto.getId());
    }

    /**
     * 刷新鉴权接口缓存
     */
    @PostMapping("/refreshCache")
    public void refreshCache() {
        sysPermissionService.refreshCache();
    }

}
