|
|
@@ -0,0 +1,139 @@
|
|
|
+package cn.reghao.autodop.dmaster.app.controller.crud;
|
|
|
+
|
|
|
+import cn.reghao.autodop.common.deploy.PackerType;
|
|
|
+import cn.reghao.autodop.common.result.WebResult;
|
|
|
+import cn.reghao.autodop.common.utils.data.db.PageList;
|
|
|
+import cn.reghao.autodop.dmaster.app.constant.*;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.ConfigService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2019-08-30 18:49:15
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Api(tags = "配置 CRUD 接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/config1")
|
|
|
+public class BuildCrudController {
|
|
|
+ private ConfigService configService;
|
|
|
+
|
|
|
+ public BuildCrudController(ConfigService configService) {
|
|
|
+ this.configService = configService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "添加配置")
|
|
|
+ @PostMapping(value = "/{configType}", consumes = "application/json")
|
|
|
+ public ResponseEntity<String> addConfig(@PathVariable("configType") String configType,
|
|
|
+ @RequestBody String json) throws Exception {
|
|
|
+ configService.addOrModify(configType, json);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页获取配置(更新时间倒序)")
|
|
|
+ @GetMapping("/{configType}")
|
|
|
+ public ResponseEntity<String> getConfigByPage(@PathVariable("configType") String configType,
|
|
|
+ @RequestParam("page") int page,
|
|
|
+ @RequestParam("size") int size) throws Exception {
|
|
|
+ PageRequest pageRequest =
|
|
|
+ PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
+ PageList pageList = configService.getByPage(configType, pageRequest);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success(pageList));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改配置")
|
|
|
+ @PutMapping("/{configType}")
|
|
|
+ public ResponseEntity<String> modifyConfig(@PathVariable("configType") String configType,
|
|
|
+ @RequestBody String json) throws Exception {
|
|
|
+ configService.addOrModify(configType, json);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除配置")
|
|
|
+ @DeleteMapping("/{configType}/{uniqueKey}")
|
|
|
+ public ResponseEntity<String> deleteConfig(@PathVariable("configType") String configType,
|
|
|
+ @PathVariable("uniqueKey") String uniqueKey) throws Exception {
|
|
|
+ configService.delete(configType, uniqueKey);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 各种配置类型
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2020-09-16 下午2:12
|
|
|
+ */
|
|
|
+ @GetMapping("/types/{configType}")
|
|
|
+ public ResponseEntity<String> getConfigType(@PathVariable("configType") String configType) {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ // TODO 配置类型可以动态修改
|
|
|
+ switch (ConfigType.valueOf(configType)) {
|
|
|
+ case localDir:
|
|
|
+ for (EnvType config : EnvType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case notifier:
|
|
|
+ for (NotifierType config : NotifierType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case repo:
|
|
|
+ for (RepoType config : RepoType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case compiler:
|
|
|
+ for (CompilerType config : CompilerType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case packer:
|
|
|
+ for (PackerType config : PackerType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case repoAuth:
|
|
|
+ for (RepoAuthType config : RepoAuthType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case app:
|
|
|
+ for (AppType config : AppType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case env:
|
|
|
+ for (EnvType config : EnvType.values()) {
|
|
|
+ map.put(config.name(), config.getValue());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case proj:
|
|
|
+ case update:
|
|
|
+ case compile:
|
|
|
+ case pack:
|
|
|
+ case notify:
|
|
|
+ map.putAll(configService.buildConfigs(configType));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseEntity.ok().body(WebResult.success(map));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/{configType}/list")
|
|
|
+ public ResponseEntity<String> getConfigList(@PathVariable("configType") String configType) throws Exception {
|
|
|
+ configService.buildConfigs("");
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("pageList"));
|
|
|
+ }
|
|
|
+}
|