1
0

GitlabUserController.java 2.1 KB

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