package com.nju.edu.gitlab.controller; import com.nju.edu.gitlab.dto.commit.CommitDTO; import com.nju.edu.gitlab.dto.project.ProjectDTO; import com.nju.edu.gitlab.service.api.ProjectService; import com.nju.edu.gitlab.dto.*; import com.nju.edu.gitlab.web.response.EmptyResponse; import com.nju.edu.gitlab.web.response.ResourceResponse; import com.nju.edu.gitlab.web.response.Response; import org.gitlab4j.api.GitLabApiException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.io.UnsupportedEncodingException; @RestController @RequestMapping("/api/project") public class GitlabProjectController { private final ProjectService projectService; @Autowired public GitlabProjectController(ProjectService projectService) { this.projectService = projectService; } @PostMapping("/") public Response createProject(@RequestBody ProjectDTO projectDTO) throws GitLabApiException { return new ResourceResponse(projectService.createProject(projectDTO)); } @PostMapping("/private") public Response createPrivateProject(@RequestBody ProjectDTO projectDTO) throws GitLabApiException { return new ResourceResponse(projectService.createPrivateProject(projectDTO)); } @PostMapping("/userFork") public Response forkProject(@RequestBody UserForkDTO userForkDTO) throws GitLabApiException { return new ResourceResponse(projectService.forkProject(userForkDTO)); } @PostMapping("/groupFork") public Response groupForkProject(@RequestBody GroupForkDTO groupForkDTO) throws GitLabApiException { return new ResourceResponse(projectService.forkGroupProject(groupForkDTO)); } @GetMapping("/compare") public Response compareProject(@RequestParam Integer projectId, @RequestParam String fromBash, @RequestParam String toBash) throws GitLabApiException { return new ResourceResponse(projectService.compare(projectId, fromBash, toBash)); } @PostMapping("/webhook") public Response addWebHook(@RequestBody WebHookDTO webHookDTO) throws GitLabApiException { return new ResourceResponse(projectService.addWebHook(webHookDTO)); } @PostMapping("/archive") public Response archiveProject(@RequestBody Integer projectId) throws GitLabApiException { return new ResourceResponse(projectService.archiveProject(projectId)); } @DeleteMapping("/{projectId}") public Response deleteProject(@PathVariable(name = "projectId") Integer projectId) throws GitLabApiException { return new ResourceResponse(projectService.deleteProject(projectId)); } @PostMapping("/{projectId}/getFile") public Response getProjectFile(@PathVariable(name = "projectId") Integer projectId, @RequestBody ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException { return new ResourceResponse(projectService.getProjectFile(projectId, projectFileDTO)); } @PostMapping("/{projectId}/getRawFile") public Response getProjectRawFile(@PathVariable(name = "projectId") Integer projectId, @RequestBody ProjectRawFileDTO projectRawFileDTO) throws GitLabApiException, IOException { return new ResourceResponse(projectService.getProjectRawFile(projectId, projectRawFileDTO)); } @PostMapping("/{projectId}/commit") public Response createCommit(@PathVariable(name = "projectId") Integer projectId, @RequestBody CommitDTO commitDTO) throws GitLabApiException { return new ResourceResponse(projectService.createCommit(projectId, commitDTO)); } @GetMapping("{projectId}/commit/{commitHash}") public Response getAllCommitMessage(@PathVariable(name = "projectId") Integer projectId, @PathVariable(name = "commitHash") String commitHash) throws GitLabApiException { return new ResourceResponse(projectService.getAllCommitMessage(projectId, commitHash)); } @GetMapping("/{projectId}/branches") public Response getAllBranches(@PathVariable(name = "projectId") Integer projectId) throws GitLabApiException { return new ResourceResponse(projectService.getProjectBranches(projectId)); } @PostMapping("/updateMember") public Response updateMember(@RequestBody UpdateMemberDTO updateMemberDTO) throws GitLabApiException { return new ResourceResponse(projectService.addAuthorization(updateMemberDTO)); } @GetMapping("/allProjects/{userId}") public Response getAllProjectsByUserId(@PathVariable(name = "userId") int userId) throws GitLabApiException { return new ResourceResponse(projectService.getAllProjectByUserId(userId)); } @GetMapping("/projectMembers/{projectId}") public Response getMembers(@PathVariable(name = "projectId") int projectId) throws GitLabApiException { return new ResourceResponse(projectService.getProjectJoinedUserId(projectId)); } @GetMapping("/filePaths") public Response getFilePaths( @RequestParam(value = "projectId") Integer projectId, @RequestParam(value = "basePath") String basePath, @RequestParam(value = "branch") String branch) throws GitLabApiException { return new ResourceResponse(projectService.getFilePaths(projectId, basePath, branch)); } }