GitlabUserController.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.nju.edu.gitlab.controller;
  2. import com.nju.edu.gitlab.service.api.UserService;
  3. import com.nju.edu.gitlab.dto.ChangePasswordDTO;
  4. import com.nju.edu.gitlab.dto.GitlabUserDTO;
  5. import com.nju.edu.gitlab.web.response.ResourceResponse;
  6. import com.nju.edu.gitlab.web.response.Response;
  7. import org.gitlab4j.api.GitLabApiException;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.web.bind.annotation.*;
  10. @RestController
  11. @RequestMapping("/api/user")
  12. public class GitlabUserController {
  13. private final UserService userService;
  14. @Autowired
  15. public GitlabUserController(UserService userService) {
  16. this.userService = userService;
  17. }
  18. @PostMapping("/")
  19. public Response createGitlabUser(@RequestBody GitlabUserDTO gitlabUserDTO) throws GitLabApiException {
  20. return new ResourceResponse(userService.createGitlabUser(gitlabUserDTO));
  21. }
  22. @PostMapping("/changePassword")
  23. public Response changePassword(@RequestBody ChangePasswordDTO changePasswordDTO) throws GitLabApiException {
  24. return new ResourceResponse(userService.changePassword(changePasswordDTO));
  25. }
  26. @DeleteMapping("/{userId}")
  27. public Response deleteUser(@PathVariable(name = "userId") Integer userId) throws GitLabApiException {
  28. return new ResourceResponse(userService.deleteUser(userId));
  29. }
  30. @GetMapping("/{userId}/email")
  31. public Response getUserEmail(@PathVariable(name = "userId") Integer userId) throws GitLabApiException {
  32. return new ResourceResponse(userService.getUserEmail(userId));
  33. }
  34. }