|
|
@@ -1,46 +1,57 @@
|
|
|
package com.nju.edu.gitlab.controller;
|
|
|
|
|
|
+import com.nju.edu.gitlab.service.api.ProjectService;
|
|
|
import com.nju.edu.gitlab.web.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 javax.ws.rs.Path;
|
|
|
+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){
|
|
|
- return new EmptyResponse();
|
|
|
+ public Response createProject(@RequestBody ProjectDTO projectDTO) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.createProject(projectDTO));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/userFork")
|
|
|
- public Response forkProject(@RequestBody UserForkDTO userForkDTO){
|
|
|
- return new EmptyResponse();
|
|
|
+ public Response forkProject(@RequestBody UserForkDTO userForkDTO) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.forkProject(userForkDTO));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/groupFork")
|
|
|
- public Response groupForkProject(@RequestBody GroupForkDTO groupForkDTO){
|
|
|
- return new EmptyResponse();
|
|
|
+ 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){
|
|
|
- return new EmptyResponse();
|
|
|
+ @RequestParam String toBash) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.compare(projectId,fromBash,toBash));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/webhook")
|
|
|
- public Response addWebHook(@RequestBody WebHookDTO webHookDTO){
|
|
|
- return new EmptyResponse();
|
|
|
+ public Response addWebHook(@RequestBody WebHookDTO webHookDTO) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.addWebHook(webHookDTO));
|
|
|
}
|
|
|
|
|
|
@PostMapping("/archive")
|
|
|
- public Response archiveProject(@RequestParam Integer projectId){
|
|
|
- return new EmptyResponse();
|
|
|
+ public Response archiveProject(@RequestParam Integer projectId) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.archiveProject(projectId));
|
|
|
}
|
|
|
|
|
|
@DeleteMapping("/{projectId}")
|
|
|
@@ -50,30 +61,30 @@ public class GitlabProjectController {
|
|
|
|
|
|
@GetMapping("/{projectId}/getFile")
|
|
|
public Response getProjectFile(@PathVariable(name = "projectId") Integer projectId,
|
|
|
- @RequestBody ProjectFileDTO projectFileDTO){
|
|
|
- return new EmptyResponse();
|
|
|
+ @RequestBody ProjectFileDTO projectFileDTO) throws UnsupportedEncodingException, GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.getProjectFile(projectId,projectFileDTO));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/{projectId}/getRawFile")
|
|
|
public Response getProjectRawFile(@PathVariable(name = "projectId") Integer projectId,
|
|
|
- @RequestBody ProjectRawFileDTO projectRawFileDTO){
|
|
|
- return new EmptyResponse();
|
|
|
+ @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){
|
|
|
- return new EmptyResponse();
|
|
|
+ @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){
|
|
|
- return new EmptyResponse();
|
|
|
+ @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){
|
|
|
- return new EmptyResponse();
|
|
|
+ public Response getAllBranches(@PathVariable(name = "projectId") Integer projectId) throws GitLabApiException {
|
|
|
+ return new ResourceResponse(projectService.getProjectBranches(projectId));
|
|
|
}
|
|
|
}
|