StorageConfigController.java
2.58 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
69
70
71
72
73
74
75
76
77
78
79
package com.viontech.storage.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.viontech.storage.entity.Context;
import com.viontech.storage.entity.Generator;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.StorageConfig;
import com.viontech.storage.service.StorageConfigService;
import com.viontech.storage.vo.StorageConfigVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* .
*
* @author 谢明辉
* @date 2021/11/9
*/
@RestController
@RequestMapping("/storageConfigs")
public class StorageConfigController {
@Resource
private StorageConfigService storageConfigService;
@GetMapping("/{id}")
public Message<StorageConfig> getById(@PathVariable("id") Long id) {
StorageConfig byId = storageConfigService.getById(id);
StorageConfigVo copy = StorageConfigVo.copy(byId);
return Message.success(copy);
}
@GetMapping
public Message<List<StorageConfig>> listAll() {
List<StorageConfig> list = storageConfigService.list();
List<StorageConfig> collect = list.stream().map(StorageConfigVo::copy).collect(Collectors.toList());
return Message.success(collect);
}
@PostMapping
public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
}
boolean save = storageConfigService.save(storageConfigVo);
return Message.success(storageConfigVo);
}
@PutMapping("/{id}")
public Message<StorageConfig> updateById(@PathVariable Long id, @RequestBody StorageConfigVo storageConfigVo) {
List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) {
storageConfigVo.setContext(JSONUtil.toJsonStr(contexts));
}
storageConfigVo.setId(id);
boolean b = storageConfigService.updateById(storageConfigVo);
return Message.success(storageConfigVo);
}
@DeleteMapping("/{id}")
public Message<StorageConfig> deleteById(@PathVariable Long id) {
boolean b = storageConfigService.removeById(id);
return Message.success();
}
@GetMapping("/build/{id}")
public Message<String> buildConfig(@PathVariable Long id) {
String build = new Generator().create(id).build();
return Message.success(build);
}
}