1
0
فهرست منبع

Merge branch 'lxs' of WuLinYang/SEEC-Gitlab into master

LiXueSong 5 سال پیش
والد
کامیت
bc9da1d059

+ 2 - 0
seecoder-gitlab-client/src/main/java/com.nju.edu.gitlab/SeecoderGitlabApi.java

@@ -19,6 +19,8 @@ public interface SeecoderGitlabApi{
 
     public boolean deleteUser(int userId) throws SeecoderGitlabException;
 
+    public String getUserEmail(int userId) throws SeecoderGitlabException;
+
     public GitlabGroup createGroup(String groupName) throws SeecoderGitlabException;
 
     public boolean addMember(int groupId, int userId, AccessLevelForm accessLevel) throws SeecoderGitlabException;

+ 22 - 0
seecoder-gitlab-client/src/main/java/com.nju.edu.gitlab/SeecoderGitlabClient.java

@@ -165,6 +165,28 @@ public class SeecoderGitlabClient implements SeecoderGitlabApi{
         }
     }
 
+    @Override
+    public String getUserEmail(int userId) throws SeecoderGitlabException {
+        try {
+            ObjectMapper objectMapper = new ObjectMapper();
+            Request.Builder builder = new Request.Builder()
+                    .addHeader("Authorization", token);
+            builder = builder
+                    .url(host + "/api/user/"+userId+"/email")
+                    .get();
+            Request request = builder.build();
+            final Call call = client.newCall(request);
+            Response response = call.execute();
+            return processResponse(objectMapper, response, new TypeReference<String>() {});
+        } catch (JsonProcessingException e) {
+            logger.error("JSON writeValueAsString error", e);
+            throw SeecoderGitlabException.JSON_ERROR;
+        } catch (IOException e) {
+            logger.error("IOException", e);
+            throw SeecoderGitlabException.IO_ERROR;
+        }
+    }
+
     @Override
     public GitlabGroup createGroup(String groupName) throws SeecoderGitlabException {
         try {

+ 5 - 0
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/controller/GitlabUserController.java

@@ -34,4 +34,9 @@ public class GitlabUserController {
     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));
+    }
 }

+ 2 - 0
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/api/UserService.java

@@ -15,4 +15,6 @@ public interface UserService {
     public boolean deleteUser(int userId) throws GitLabApiException;
 
     public User findByUsername(String username) throws GitLabApiException;
+
+    public String getUserEmail(int userId) throws GitLabApiException;
 }

+ 6 - 0
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/UserServiceImpl.java

@@ -91,6 +91,12 @@ public class UserServiceImpl implements UserService {
         return gitlabApi.getUserApi().getUser(username);
     }
 
+    @Override
+    public String getUserEmail(int userId) throws GitLabApiException {
+        userId = gitlabUserRepository.findByUserId(userId).getGitlabUserId();
+        return gitlabApi.getUserApi().getUser(userId).getEmail();
+    }
+
     private String createToken(int userId) throws GitLabApiException {
         Scope[] scopes = new Scope[]{Scope.API};
         ImpersonationToken token;