EnvironmentController.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package cn.seecoder.paas.web.controller.api;
  2. import cn.seecoder.paas.service.EnvironmentService;
  3. import cn.seecoder.paas.service.model.vo.EnvironmentVO;
  4. import cn.seecoder.paas.util.ServiceException;
  5. import cn.seecoder.paas.web.model.Response;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.*;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.validation.Valid;
  10. @RestController
  11. @RequestMapping("/api/environment")
  12. public class EnvironmentController {
  13. private final EnvironmentService environmentService;
  14. @Autowired
  15. public EnvironmentController(EnvironmentService environmentService) {
  16. this.environmentService = environmentService;
  17. }
  18. @PostMapping("")
  19. public Response create(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException {
  20. return Response.buildSuccess(environmentService.createOrUpdate(environmentVO));
  21. }
  22. @PutMapping("")
  23. public Response update(@Valid @RequestBody EnvironmentVO environmentVO) throws ServiceException {
  24. return Response.buildSuccess(environmentService.createOrUpdate(environmentVO));
  25. }
  26. @GetMapping("")
  27. public Response getAll(@RequestParam Integer appId) {
  28. return Response.buildSuccess(environmentService.getListByAppId(appId));
  29. }
  30. @GetMapping("/{id}")
  31. public Response get(@PathVariable("id") Integer id, HttpServletRequest request) throws ServiceException {
  32. Boolean fetchAll = Boolean.valueOf(request.getParameter("fetchAll"));
  33. return Response.buildSuccess(environmentService.get(id, fetchAll == null ? false : fetchAll));
  34. }
  35. @DeleteMapping("/{id}")
  36. public Response delete(@PathVariable("id") Integer id) {
  37. environmentService.delete(id);
  38. return Response.buildSuccess(null);
  39. }
  40. @GetMapping("/log")
  41. public Response getLog(@RequestParam Integer id, @RequestParam String podName) throws ServiceException {
  42. return Response.buildSuccess(
  43. environmentService.getLog(id, podName));
  44. }
  45. @PostMapping("/deploy")
  46. public Response deploy(@RequestParam Integer id) throws ServiceException {
  47. return Response.buildSuccess(
  48. environmentService.deploy(id));
  49. }
  50. @PostMapping("/restart")
  51. public Response deploy(@RequestParam Integer id, @RequestParam String podName) throws ServiceException {
  52. return Response.buildSuccess(
  53. environmentService.restart(id, podName));
  54. }
  55. }