package cn.seecoder.paas.web.controller.api; import cn.seecoder.paas.service.EnvironmentService; import cn.seecoder.paas.service.model.vo.EnvironmentVO; import cn.seecoder.paas.util.ServiceException; import cn.seecoder.paas.web.model.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; @RestController @RequestMapping("/api/environment") public class EnvironmentController { private final EnvironmentService environmentService; @Autowired public EnvironmentController(EnvironmentService environmentService) { this.environmentService = environmentService; } @PostMapping("") public Response create(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException { return Response.buildSuccess(environmentService.createOrUpdate(environmentVO)); } @PutMapping("") public Response update(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException { return Response.buildSuccess(environmentService.createOrUpdate(environmentVO)); } @GetMapping("") public Response getAll(@RequestParam Integer appId) { return Response.buildSuccess(environmentService.getListByAppId(appId)); } @GetMapping("/{id}") public Response get(@PathVariable("id") Integer id, HttpServletRequest request) throws ServiceException { Boolean fetchAll = Boolean.valueOf(request.getParameter("fetchAll")); return Response.buildSuccess(environmentService.get(id, fetchAll == null ? false : fetchAll)); } @DeleteMapping("/{id}") public Response delete(@PathVariable("id") Integer id) throws ServiceException { environmentService.delete(id); return Response.buildSuccess(null); } @GetMapping("/log") public Response getLog(@RequestParam Integer id, @RequestParam String podName) throws ServiceException { return Response.buildSuccess( environmentService.getLog(id, podName)); } @PostMapping("/deploy") public Response deploy(@RequestParam Integer id, @RequestParam(required = false, defaultValue = "false") Boolean useCache) throws ServiceException { return Response.buildSuccess( environmentService.deploy(id,useCache)); } @PostMapping("/restart") public Response deploy(@RequestParam Integer id, @RequestParam String podName) throws ServiceException { return Response.buildSuccess( environmentService.restart(id, podName)); } }