Skip to content

Commit

Permalink
Merge pull request #264 from junseoparkk/fix/lounge-invite
Browse files Browse the repository at this point in the history
최대 개수의 라운지에 소속되어도 초대 수락되는 버그 해결
  • Loading branch information
JiHongKim98 authored Oct 2, 2024
2 parents 86746a0 + a402043 commit 8a25b80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void inviteUser(LoungeInviteDto request, Long inviterId) {
public void updateInvitedUserStatus(Long userId, Long loungeId) {
User invitedUser = userService.getUserById(userId);
Lounge findLounge = loungeService.getLoungeById(loungeId);
loungeSharerService.updateInvitedUserStatus(invitedUser, findLounge);
loungeSharerService.updateInvitedUserStatus(invitedUser.getId(), findLounge.getId());
}

// 라운지 내 유저 검색
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class LoungeSharerService {
private final LoungeSharerRepository loungeSharerRepository;

public void createAndSaveLoungeSharer(User user, Lounge lounge) {
// 라운지 최대 개수를 초과하는지 검증
if (isOverMaximumCountLounge(user.getId())) {
throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION);
}
Expand All @@ -54,12 +53,18 @@ public void inviteUser(User user, Lounge lounge, Long inviterId) {
}

// FIXME:
public void updateInvitedUserStatus(User invitedUser, Lounge lounge) {
LoungeSharer findSharer = loungeSharerRepository.findByUserIdAndLoungeId(invitedUser.getId(), lounge.getId());
if (!findSharer.isActive()) {
findSharer.updateStatusActive();
loungeSharerRepository.save(findSharer);
public void updateInvitedUserStatus(Long invitedUserId, Long loungeId) {
LoungeSharer loungeSharer = loungeSharerRepository.findByUserIdAndLoungeId(invitedUserId, loungeId)
.orElseThrow(() -> new LoungeException(INVALID_LOUNGE_SHARER_EXCEPTION));
if (loungeSharer.isActive()) {
throw new LoungeException(ALREADY_EXISTS_LOUNGE_USER_EXCEPTION);
}

if (isOverMaximumCountLounge(invitedUserId)) {
throw new LoungeException(MAXIMUM_LOUNGE_LIMIT_EXCEEDED_EXCEPTION);
}
loungeSharer.updateStatusActive();
loungeSharerRepository.save(loungeSharer);
}

public List<LoungeSharerInfoResponseDto> searchLoungeSharer(Long userId, String nickname, Lounge lounge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.daobe.lounge.domain.LoungeSharer;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down Expand Up @@ -42,5 +43,5 @@ SELECT COUNT(ls) FROM LoungeSharer ls

void deleteByUserIdAndLoungeId(Long userId, Long loungeId);

LoungeSharer findByUserIdAndLoungeId(Long userId, Long loungeId);
Optional<LoungeSharer> findByUserIdAndLoungeId(Long userId, Long loungeId);
}

0 comments on commit 8a25b80

Please sign in to comment.