|
|
@@ -1,139 +1,131 @@
|
|
|
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 cn.reghao.autodop.common.utils.data.serializer.JsonConverter;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.AppCompile;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.AppPack;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.build.AppUpdate;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.crud.build.AppCompileCrudService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.crud.build.AppPackCrudService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.crud.build.AppUpdateCrudService;
|
|
|
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 接口")
|
|
|
+@Api(tags = "应用构建配置 CRUD 接口")
|
|
|
@RestController
|
|
|
-@RequestMapping("/api/config1")
|
|
|
+@RequestMapping("/api/config/build")
|
|
|
public class BuildCrudController {
|
|
|
- private ConfigService configService;
|
|
|
+ private AppUpdateCrudService updateCrudService;
|
|
|
+ private AppCompileCrudService compileCrudService;
|
|
|
+ private AppPackCrudService packCrudService;
|
|
|
|
|
|
- public BuildCrudController(ConfigService configService) {
|
|
|
- this.configService = configService;
|
|
|
+ public BuildCrudController(AppUpdateCrudService updateCrudService,
|
|
|
+ AppCompileCrudService compileCrudService,
|
|
|
+ AppPackCrudService packCrudService) {
|
|
|
+ this.updateCrudService = updateCrudService;
|
|
|
+ this.compileCrudService = compileCrudService;
|
|
|
+ this.packCrudService = packCrudService;
|
|
|
}
|
|
|
|
|
|
- @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);
|
|
|
+ /* 应用更新配置 */
|
|
|
+ @ApiOperation(value = "添加应用更新配置")
|
|
|
+ @PostMapping(value = "/update", consumes = "application/json")
|
|
|
+ public ResponseEntity<String> addUpdateConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppUpdate appUpdate = (AppUpdate) JsonConverter.jsonToObject(json, AppUpdate.class);
|
|
|
+ updateCrudService.addOrModify(appUpdate);
|
|
|
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);
|
|
|
+ @ApiOperation(value = "分页获取应用更新配置")
|
|
|
+ @GetMapping("/update")
|
|
|
+ public ResponseEntity<String> getUpdateConfigByPage(@RequestParam("page") int page, @RequestParam("size") int size) {
|
|
|
+ PageList<AppUpdate> pageList = updateCrudService.getByPage(page, size);
|
|
|
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);
|
|
|
+ @ApiOperation(value = "修改应用更新配置")
|
|
|
+ @PutMapping("/update")
|
|
|
+ public ResponseEntity<String> modifyUpdateConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppUpdate appUpdate = (AppUpdate) JsonConverter.jsonToObject(json, AppUpdate.class);
|
|
|
+ updateCrudService.addOrModify(appUpdate);
|
|
|
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);
|
|
|
+ @ApiOperation(value = "删除应用更新配置")
|
|
|
+ @DeleteMapping("/update/{uniqueKey}")
|
|
|
+ public ResponseEntity<String> deleteUpdateConfig(@PathVariable("uniqueKey") String uniqueKey) throws Exception {
|
|
|
+ updateCrudService.delete(uniqueKey);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 应用编译配置 */
|
|
|
+ @ApiOperation(value = "添加应用编译配置")
|
|
|
+ @PostMapping(value = "/compile", consumes = "application/json")
|
|
|
+ public ResponseEntity<String> addCompileConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppCompile appCompile = (AppCompile) JsonConverter.jsonToObject(json, AppCompile.class);
|
|
|
+ compileCrudService.addOrModify(appCompile);
|
|
|
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:
|
|
|
- }
|
|
|
+ @ApiOperation(value = "分页获取应用编译配置")
|
|
|
+ @GetMapping("/compile")
|
|
|
+ public ResponseEntity<String> getCompileConfigByPage(@RequestParam("page") int page, @RequestParam("size") int size) {
|
|
|
+ PageList<AppCompile> pageList = compileCrudService.getByPage(page, size);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success(pageList));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改应用编译配置")
|
|
|
+ @PutMapping("/compile")
|
|
|
+ public ResponseEntity<String> modifyCompileConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppCompile appCompile = (AppCompile) JsonConverter.jsonToObject(json, AppCompile.class);
|
|
|
+ compileCrudService.addOrModify(appCompile);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
|
|
|
- return ResponseEntity.ok().body(WebResult.success(map));
|
|
|
+ @ApiOperation(value = "删除应用编译配置")
|
|
|
+ @DeleteMapping("/compile/{uniqueKey}")
|
|
|
+ public ResponseEntity<String> deleteCompileConfig(@PathVariable("uniqueKey") String uniqueKey) throws Exception {
|
|
|
+ compileCrudService.delete(uniqueKey);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/{configType}/list")
|
|
|
- public ResponseEntity<String> getConfigList(@PathVariable("configType") String configType) throws Exception {
|
|
|
- configService.buildConfigs("");
|
|
|
- return ResponseEntity.ok().body(WebResult.success("pageList"));
|
|
|
+ /* 应用打包配置 */
|
|
|
+ @ApiOperation(value = "添加应用打包配置")
|
|
|
+ @PostMapping(value = "/pack", consumes = "application/json")
|
|
|
+ public ResponseEntity<String> addPackConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppPack appPack = (AppPack) JsonConverter.jsonToObject(json, AppPack.class);
|
|
|
+ packCrudService.addOrModify(appPack);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页获取应用打包配置")
|
|
|
+ @GetMapping("/pack")
|
|
|
+ public ResponseEntity<String> getPackConfigByPage(@RequestParam("page") int page, @RequestParam("size") int size) {
|
|
|
+ PageList<AppPack> pageList = packCrudService.getByPage(page, size);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success(pageList));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改应用打包配置")
|
|
|
+ @PutMapping("/pack")
|
|
|
+ public ResponseEntity<String> modifyPackConfig(@RequestBody String json) throws Exception {
|
|
|
+ AppPack appPack = (AppPack) JsonConverter.jsonToObject(json, AppPack.class);
|
|
|
+ packCrudService.addOrModify(appPack);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除应用打包配置")
|
|
|
+ @DeleteMapping("/pack/{uniqueKey}")
|
|
|
+ public ResponseEntity<String> deletePackConfig(@PathVariable("uniqueKey") String uniqueKey) throws Exception {
|
|
|
+ packCrudService.delete(uniqueKey);
|
|
|
+ return ResponseEntity.ok().body(WebResult.success("ok"));
|
|
|
}
|
|
|
}
|