|
|
@@ -9,7 +9,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import seecoder.devcloud.common.exceptions.EntityNotFoundException;
|
|
|
+import seecoder.devcloud.common.exceptions.AccessDeniedException;
|
|
|
+import seecoder.devcloud.common.exceptions.ConflictException;
|
|
|
import seecoder.devcloud.common.exceptions.ServiceException;
|
|
|
import seecoder.devcloud.web.dao.user.GroupMapper;
|
|
|
import seecoder.devcloud.web.dao.user.GroupMemberMapper;
|
|
|
@@ -53,7 +54,7 @@ public class GroupServiceImpl implements GroupService {
|
|
|
@Transactional
|
|
|
public GroupVO createGroup(String name) throws ServiceException {
|
|
|
if (groupMapper.findGroupByName(name) != null){
|
|
|
- throw new ServiceException("您创建的小组名字已被使用!");
|
|
|
+ throw new ConflictException("您创建的小组名字已被使用!");
|
|
|
}
|
|
|
User user = UserService.loginUser();
|
|
|
GitlabGroup gitlabGroup = null;
|
|
|
@@ -61,7 +62,7 @@ public class GroupServiceImpl implements GroupService {
|
|
|
gitlabGroup = seecoderGitlabApi.createGroup(GROUP_NAME_PREFIX + name);
|
|
|
seecoderGitlabApi.addMember(gitlabGroup.getGroupId(), user.getId(), AccessLevelForm.MASTER);
|
|
|
} catch (SeecoderGitlabException e) {
|
|
|
- throw new ServiceException("Error: 创建Group时发生异常[" + e.getMessage() + "]");
|
|
|
+ throw new ServiceException("创建Group时发生异常[" + e.getMessage() + "]",e);
|
|
|
}
|
|
|
Group group = Group.builder()
|
|
|
.id(gitlabGroup.getGroupId())
|
|
|
@@ -75,22 +76,22 @@ public class GroupServiceImpl implements GroupService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void addMember(Integer invitedUserId, Integer groupId) throws EntityNotFoundException {
|
|
|
+ public void addMember(Integer invitedUserId, Integer groupId) throws ServiceException {
|
|
|
//当前登陆的用户id
|
|
|
int userId = UserService.loginUser().getId();
|
|
|
|
|
|
//只有在组内的用户才能邀请
|
|
|
List<Integer> userIds = groupMemberMapper.selectUserIdsByGroupId(groupId);
|
|
|
if (!userIds.contains(userId)) {
|
|
|
- throw new EntityNotFoundException("Error: 小组邀请发生错误,用户没有权限!");
|
|
|
+ throw new AccessDeniedException("小组邀请发生错误,用户没有权限");
|
|
|
}
|
|
|
if (userIds.contains(invitedUserId)) {
|
|
|
- throw new RuntimeException("Error: 邀请的用户已经加入小组!");
|
|
|
+ throw new ConflictException("邀请的用户已经加入小组!");
|
|
|
}
|
|
|
try {
|
|
|
seecoderGitlabApi.addMember(groupId, invitedUserId, AccessLevelForm.MASTER);
|
|
|
} catch (SeecoderGitlabException e) {
|
|
|
- throw new ServiceException("Error: 将成员加入Group时发生异常[" + e.getMessage() + "]");
|
|
|
+ throw new ServiceException("将成员加入Group时发生异常[" + e.getMessage() + "]", e);
|
|
|
}
|
|
|
groupMemberMapper.insert(groupId, invitedUserId);
|
|
|
//Group group = groupMapper.findWithMembersById(groupId);
|