GitlabProjectController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.nju.edu.gitlab.controller;
  2. import com.nju.edu.gitlab.dto.commit.CommitDTO;
  3. import com.nju.edu.gitlab.dto.project.ProjectDTO;
  4. import com.nju.edu.gitlab.service.api.ProjectService;
  5. import com.nju.edu.gitlab.dto.*;
  6. import com.nju.edu.gitlab.web.response.EmptyResponse;
  7. import com.nju.edu.gitlab.web.response.ResourceResponse;
  8. import com.nju.edu.gitlab.web.response.Response;
  9. import org.gitlab4j.api.GitLabApiException;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import java.io.IOException;
  13. import java.io.UnsupportedEncodingException;
  14. @RestController
  15. @RequestMapping("/api/project")
  16. public class GitlabProjectController {
  17. private final ProjectService projectService;
  18. @Autowired
  19. public GitlabProjectController(ProjectService projectService) {
  20. this.projectService = projectService;
  21. }
  22. @PostMapping("/")
  23. public Response createProject(@RequestBody ProjectDTO projectDTO) throws GitLabApiException {
  24. return new ResourceResponse(projectService.createProject(projectDTO));
  25. }
  26. @PostMapping("/private")
  27. public Response createPrivateProject(@RequestBody ProjectDTO projectDTO) throws GitLabApiException {
  28. return new ResourceResponse(projectService.createPrivateProject(projectDTO));
  29. }
  30. @PostMapping("/userFork")
  31. public Response forkProject(@RequestBody UserForkDTO userForkDTO) throws GitLabApiException {
  32. return new ResourceResponse(projectService.forkProject(userForkDTO));
  33. }
  34. @PostMapping("/groupFork")
  35. public Response groupForkProject(@RequestBody GroupForkDTO groupForkDTO) throws GitLabApiException {
  36. return new ResourceResponse(projectService.forkGroupProject(groupForkDTO));
  37. }
  38. @GetMapping("/compare")
  39. public Response compareProject(@RequestParam Integer projectId,
  40. @RequestParam String fromBash,
  41. @RequestParam String toBash) throws GitLabApiException {
  42. return new ResourceResponse(projectService.compare(projectId, fromBash, toBash));
  43. }
  44. @PostMapping("/webhook")
  45. public Response addWebHook(@RequestBody WebHookDTO webHookDTO) throws GitLabApiException {
  46. return new ResourceResponse(projectService.addWebHook(webHookDTO));
  47. }
  48. @PostMapping("/archive")
  49. public Response archiveProject(@RequestBody Integer projectId) throws GitLabApiException {
  50. return new ResourceResponse(projectService.archiveProject(projectId));
  51. }
  52. @DeleteMapping("/{projectId}")
  53. public Response deleteProject(@PathVariable(name = "projectId") Integer projectId) throws GitLabApiException {
  54. return new ResourceResponse(projectService.deleteProject(projectId));
  55. }
  56. @PostMapping("/{projectId}/getFile")
  57. public Response getProjectFile(@PathVariable(name = "projectId") Integer projectId,
  58. @RequestBody ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException {
  59. return new ResourceResponse(projectService.getProjectFile(projectId, projectFileDTO));
  60. }
  61. @PostMapping("/{projectId}/getRawFile")
  62. public Response getProjectRawFile(@PathVariable(name = "projectId") Integer projectId,
  63. @RequestBody ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException {
  64. return new ResourceResponse(projectService.getProjectRawFile(projectId, projectRawFileDTO));
  65. }
  66. @PostMapping("/{projectId}/commit")
  67. public Response createCommit(@PathVariable(name = "projectId") Integer projectId,
  68. @RequestBody CommitDTO commitDTO) throws GitLabApiException {
  69. return new ResourceResponse(projectService.createCommit(projectId, commitDTO));
  70. }
  71. @GetMapping("{projectId}/commit/{commitHash}")
  72. public Response getAllCommitMessage(@PathVariable(name = "projectId") Integer projectId,
  73. @PathVariable(name = "commitHash") String commitHash) throws GitLabApiException {
  74. return new ResourceResponse(projectService.getAllCommitMessage(projectId, commitHash));
  75. }
  76. @GetMapping("/{projectId}/branches")
  77. public Response getAllBranches(@PathVariable(name = "projectId") Integer projectId) throws GitLabApiException {
  78. return new ResourceResponse(projectService.getProjectBranches(projectId));
  79. }
  80. @PostMapping("/updateMember")
  81. public Response updateMember(@RequestBody UpdateMemberDTO updateMemberDTO) throws GitLabApiException {
  82. return new ResourceResponse(projectService.addAuthorization(updateMemberDTO));
  83. }
  84. @GetMapping("/allProjects/{userId}")
  85. public Response getAllProjectsByUserId(@PathVariable(name = "userId") int userId) throws GitLabApiException {
  86. return new ResourceResponse(projectService.getAllProjectByUserId(userId));
  87. }
  88. @GetMapping("/projectMembers/{projectId}")
  89. public Response getMembers(@PathVariable(name = "projectId") int projectId) throws GitLabApiException {
  90. return new ResourceResponse(projectService.getProjectJoinedUserId(projectId));
  91. }
  92. @GetMapping("/filePaths")
  93. public Response getFilePaths(
  94. @RequestParam(value = "projectId") Integer projectId,
  95. @RequestParam(value = "basePath") String basePath,
  96. @RequestParam(value = "branch") String branch) throws GitLabApiException {
  97. return new ResourceResponse(projectService.getFilePaths(projectId, basePath, branch));
  98. }
  99. }