ResourceController.java
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.tree.MapTree;
import org.springframework.web.bind.annotation.*;
import vion.dto.ResourceDTO;
import vion.dto.RoleDTO;
import vion.model.Resource;
import vion.service.IResourceService;
import vion.vo.ResourceVO;
import java.util.List;
/**
* 资源管理
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ResourceController {
private final IResourceService resourceService;
private final Converter converter;
@GetMapping("/resource")
@SaCheckPermission(value = "resource:list", orRole = "admin")
public Page<ResourceVO> list(ResourceDTO dto) {
return resourceService.list(dto);
}
@GetMapping("/resource/tree")
@SaCheckPermission(value = "resource:tree", orRole = "admin")
public List<MapTree<Long>> listTree(Long id) {
return resourceService.listTree(id);
}
@GetMapping("/resource/{id}")
@SaCheckPermission(value = "resource:query", orRole = "admin")
public ResourceVO getRoleById(@PathVariable Long id) {
Resource resource = resourceService.getById(id);
return converter.convert(resource, ResourceVO.class);
}
@PostMapping("/resource")
@SaCheckPermission(value = "resource:save", orRole = "admin")
public String save(@RequestBody ResourceDTO dto) {
Resource resource = converter.convert(dto, Resource.class);
return resourceService.save(resource) ? "创建成功" : "创建失败";
}
@PostMapping("/resource/{id}")
@SaCheckPermission(value = "resource:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody RoleDTO dto) {
Resource resource = converter.convert(dto, Resource.class);
resource.setId(id);
return resourceService.updateById(resource) ? "更新成功" : "更新失败";
}
@DeleteMapping("/resource/{id}")
@SaCheckPermission(value = "resource:remove", orRole = "admin")
public String remove(@PathVariable Long id) {
return resourceService.removeById(id) ? "删除成功" : "删除失败";
}
}