Skip to content

Commit

Permalink
[fix] 그룹 최초 가입 시 기본으로 선택되도록 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
boo105 committed Mar 12, 2024
1 parent ba3fb54 commit ade5094
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ public void joinGroup(long groupId, UserInfo user) {
throw new ApiException(GroupMessage.GROUP_NOT_FOUND);
}

Optional<GroupUsersEntity> groupUserResult = groupUserRepository.findByGroupIdAndUserId(groupId, userResult.get().getId());
if(groupUserResult.isPresent()) {
List<GroupUsersEntity> groupUsers = groupUserRepository.findByUserId(userResult.get().getId());
boolean isAlreadyExistsGroup = groupUsers
.stream()
.anyMatch(groupUser -> groupUser.getGroupId().equals(groupId));
if(isAlreadyExistsGroup) {
throw new ApiException(GroupMessage.USER_ALREADY_EXISTS_IN_GROUP);
}

Expand All @@ -159,6 +162,14 @@ public void joinGroup(long groupId, UserInfo user) {
.role(GroupUserRole.MEMBER)
.build();

if(groupUsers.isEmpty()) {
GroupUserSelectEntity groupUserSelectEntity = GroupUserSelectEntity.builder()
.groupId(groupId)
.userId(userResult.get().getId())
.build();
groupUserSelectRepository.save(groupUserSelectEntity);
}

groupUserRepository.save(joinGroupUsersEntity);
}

Expand Down

0 comments on commit ade5094

Please sign in to comment.