package com.nju.edu.gitlab.controller; import com.nju.edu.gitlab.dto.ChangeUserNameDTO; import com.nju.edu.gitlab.service.api.UserService; import com.nju.edu.gitlab.dto.ChangePasswordDTO; import com.nju.edu.gitlab.dto.GitlabUserDTO; 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.*; @RestController @RequestMapping("/api/user") public class GitlabUserController { private final UserService userService; @Autowired public GitlabUserController(UserService userService) { this.userService = userService; } @PostMapping("/") public Response createGitlabUser(@RequestBody GitlabUserDTO gitlabUserDTO) throws GitLabApiException { return new ResourceResponse(userService.createGitlabUser(gitlabUserDTO)); } @PostMapping("/changePassword") public Response changePassword(@RequestBody ChangePasswordDTO changePasswordDTO) throws GitLabApiException { return new ResourceResponse(userService.changePassword(changePasswordDTO)); } @PostMapping("/changeUserName") public Response changeUserName(@RequestBody ChangeUserNameDTO changeUserNameDTO) throws GitLabApiException { return new ResourceResponse(userService.changeUserName(changeUserNameDTO)); } @DeleteMapping("/{userId}") public Response deleteUser(@PathVariable(name = "userId") Integer userId) throws GitLabApiException { return new ResourceResponse(userService.deleteUser(userId)); } @GetMapping("/{userId}/email") public Response getUserEmail(@PathVariable(name = "userId") Integer userId) throws GitLabApiException { return new ResourceResponse(userService.getUserEmail(userId)); } @GetMapping("/getByUserName") public Response getUserByUserName(@RequestParam(name = "userName") String userName) throws GitLabApiException { return new ResourceResponse(userService.findByUsername(userName)); } }