-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[COZY-432] feat: 사용자가 방에 들어가면 다른 요청들 날리기 #209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,25 +135,21 @@ public void joinRoom(Long roomId, Long memberId) { | |
throw new GeneralException(ErrorStatus._ROOM_ALREADY_EXISTS); | ||
} | ||
|
||
if (mateRepository.countActiveMatesByRoomId(roomId) >= room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); | ||
if (room.getNumOfArrival() >= room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); // 방이 가득 찼을 경우 예외 처리 | ||
} | ||
|
||
if (existingMate.isPresent()) { | ||
// 재입장 처리 | ||
Mate exitingMate = existingMate.get(); | ||
exitingMate.setEntryStatus(EntryStatus.JOINED); | ||
mateRepository.save(exitingMate); | ||
room.arrive(); | ||
room.isRoomFull(); | ||
roomRepository.save(room); | ||
processJoinRequest(existingMate.get(), room); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 재입장하는 경우(status가 EXITED)에 대해 processJoinRequest를 호출합니다 |
||
clearOtherRoomRequests(memberId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JOINED됐으면 기존 요청들을 날립니다 |
||
} else { | ||
Mate mate = MateConverter.toEntity(room, member, false); | ||
mateRepository.save(mate); | ||
room.arrive(); | ||
room.isRoomFull(); | ||
roomRepository.save(room); | ||
} | ||
roomRepository.save(room); | ||
|
||
// 푸시 알림 코드 | ||
List<Mate> findRoomMates = mateRepository.findFetchMemberByRoom(room, EntryStatus.JOINED); | ||
|
@@ -326,8 +322,8 @@ public void sendInvitation(Long inviteeId, Long inviterId) { | |
} | ||
|
||
// 방 정원 검사 | ||
if (mateRepository.countActiveMatesByRoomId(room.getId()) >= room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); | ||
if (room.getNumOfArrival() >= room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); // 방이 가득 찼을 경우 예외 처리 | ||
} | ||
|
||
if (invitee.isPresent()) { | ||
|
@@ -369,10 +365,8 @@ public void respondToInvitation(Long roomId, Long inviteeId, boolean accept) { | |
|
||
if (accept) { | ||
// 초대 요청을 수락하여 JOINED 상태로 변경 | ||
invitee.setEntryStatus(EntryStatus.JOINED); | ||
mateRepository.save(invitee); | ||
room.arrive(); | ||
room.isRoomFull(); | ||
processJoinRequest(invitee, room); | ||
clearOtherRoomRequests(inviteeId); | ||
Comment on lines
+368
to
+369
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위랑 동일 |
||
} else { | ||
// 초대 요청을 거절하여 PENDING 상태를 삭제 | ||
mateRepository.delete(invitee); | ||
|
@@ -546,15 +540,13 @@ public void respondToJoinRequest(Long requesterId, boolean accept, Long managerI | |
requesterId, EntryStatus.PENDING) | ||
.orElseThrow(() -> new GeneralException(ErrorStatus._REQUEST_NOT_FOUND)); | ||
|
||
if (room.getNumOfArrival() + 1 > room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); | ||
if (room.getNumOfArrival() >= room.getMaxMateNum()) { | ||
throw new GeneralException(ErrorStatus._ROOM_FULL); // 방이 가득 찼을 경우 예외 처리 | ||
} | ||
|
||
if (accept) { | ||
requester.setEntryStatus(EntryStatus.JOINED); | ||
mateRepository.save(requester); | ||
room.arrive(); | ||
room.isRoomFull(); | ||
processJoinRequest(requester, room); | ||
clearOtherRoomRequests(requesterId); | ||
} else { | ||
mateRepository.delete(requester); // 거절 시 요청자 삭제 | ||
} | ||
|
@@ -628,6 +620,19 @@ public void changeToPrivateRoom(Long roomId, Long memberId) { | |
room.changeToPrivateRoom(); | ||
} | ||
|
||
private void processJoinRequest(Mate mate, Room room) { | ||
mate.setEntryStatus(EntryStatus.JOINED); | ||
mateRepository.save(mate); | ||
room.arrive(); | ||
room.isRoomFull(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 방 참여시 JOINED STATE로 업데이트 |
||
private void clearOtherRoomRequests(Long memberId) { | ||
mateRepository.deleteAllByMemberIdAndEntryStatusIn( | ||
memberId, List.of(EntryStatus.PENDING, EntryStatus.INVITED) | ||
); | ||
} | ||
|
||
Comment on lines
+630
to
+635
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PENDING, INVITED 상태인 mate를 모두 삭제합니다 |
||
// 초대코드 생성 부분 | ||
private String generateUniqueUppercaseKey() { | ||
String randomKey; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방 정원 검사를 중구난방으로 하고 있어서 통일했습니다 (무시해도 됨)