1+ package xyz .lingview .dimstack .controller ;
2+
3+ import lombok .extern .slf4j .Slf4j ;
4+ import org .springframework .beans .factory .annotation .Autowired ;
5+ import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .PostMapping ;
7+ import org .springframework .web .bind .annotation .RequestBody ;
8+ import org .springframework .web .bind .annotation .RequestMapping ;
9+ import org .springframework .web .bind .annotation .RestController ;
10+ import xyz .lingview .dimstack .annotation .RequiresPermission ;
11+ import xyz .lingview .dimstack .common .ApiResponse ;
12+ import xyz .lingview .dimstack .domain .StorageMethod ;
13+ import xyz .lingview .dimstack .service .CurrentUserService ;
14+ import xyz .lingview .dimstack .service .StorageMethodService ;
15+
16+ import java .util .List ;
17+ import java .util .Map ;
18+
19+ /**
20+ * @Author: lingview
21+ * @Date: 2026/07/17 17:23:48
22+ * @Description: 存储方式管理控制器
23+ * @Version: 1.0
24+ */
25+ @ Slf4j
26+ @ RestController
27+ @ RequestMapping ("/api/storage" )
28+ public class StorageMethodController {
29+
30+ @ Autowired
31+ private StorageMethodService storageMethodService ;
32+
33+ @ Autowired
34+ private CurrentUserService currentUserService ;
35+
36+ @ GetMapping ("/list" )
37+ @ RequiresPermission ("system:config:management" )
38+ public ApiResponse <List <StorageMethod >> list () {
39+ return ApiResponse .success (storageMethodService .list ());
40+ }
41+
42+ @ PostMapping ("/add" )
43+ @ RequiresPermission ("system:config:management" )
44+ public ApiResponse <Map <String , String >> add (@ RequestBody StorageMethod storageMethod ) {
45+ String userUuid = currentUserService .getCurrentUserUuid ();
46+ Map <String , String > result = storageMethodService .add (storageMethod , userUuid );
47+ if (result .containsKey ("error" )) {
48+ return ApiResponse .error (400 , result .get ("error" ));
49+ }
50+ return ApiResponse .success (result );
51+ }
52+
53+ @ PostMapping ("/edit" )
54+ @ RequiresPermission ("system:config:management" )
55+ public ApiResponse <Map <String , String >> edit (@ RequestBody StorageMethod storageMethod ) {
56+ Map <String , String > result = storageMethodService .edit (storageMethod );
57+ if (result .containsKey ("error" )) {
58+ return ApiResponse .error (400 , result .get ("error" ));
59+ }
60+ return ApiResponse .success (result );
61+ }
62+
63+ @ PostMapping ("/disable" )
64+ @ RequiresPermission ("system:config:management" )
65+ public ApiResponse <Map <String , String >> disable (@ RequestBody Map <String , String > payload ) {
66+ String uuid = payload .get ("uuid" );
67+ Map <String , String > result = storageMethodService .disable (uuid );
68+ if (result .containsKey ("error" )) {
69+ return ApiResponse .error (400 , result .get ("error" ));
70+ }
71+ return ApiResponse .success (result );
72+ }
73+
74+ @ PostMapping ("/enable" )
75+ @ RequiresPermission ("system:config:management" )
76+ public ApiResponse <Map <String , String >> enable (@ RequestBody Map <String , String > payload ) {
77+ String uuid = payload .get ("uuid" );
78+ Map <String , String > result = storageMethodService .enable (uuid );
79+ if (result .containsKey ("error" )) {
80+ return ApiResponse .error (400 , result .get ("error" ));
81+ }
82+ return ApiResponse .success (result );
83+ }
84+
85+ @ PostMapping ("/delete" )
86+ @ RequiresPermission ("system:config:management" )
87+ public ApiResponse <Map <String , String >> delete (@ RequestBody Map <String , String > payload ) {
88+ String uuid = payload .get ("uuid" );
89+ Map <String , String > result = storageMethodService .deletePhysical (uuid );
90+ if (result .containsKey ("error" )) {
91+ return ApiResponse .error (400 , result .get ("error" ));
92+ }
93+ return ApiResponse .success (result );
94+ }
95+
96+ @ PostMapping ("/set-default" )
97+ @ RequiresPermission ("system:config:management" )
98+ public ApiResponse <Map <String , String >> setDefault (@ RequestBody Map <String , String > payload ) {
99+ String uuid = payload .get ("uuid" );
100+ Map <String , String > result = storageMethodService .setDefault (uuid );
101+ if (result .containsKey ("error" )) {
102+ return ApiResponse .error (400 , result .get ("error" ));
103+ }
104+ return ApiResponse .success (result );
105+ }
106+ }
0 commit comments