Skip to content

Commit

Permalink
#52 [CHORE] : 리뷰 반영. 알람,룸 삭제 메소드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
hye-on committed Oct 6, 2023
1 parent 5696975 commit e149373
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,8 @@ public void leaveRoom(Integer roomId,Integer userId){
public void findNextCreatedUser(Integer roomId,Integer userId){
List<RoomUser> orderedRoomUser = roomUserRepository.findAllByRoom_IdOrderByCreatedAt(roomId);
//방의 마지막 멤버가 나가면 방,알람 삭제
if(orderedRoomUser.size()<Constant.MINIMUM_NUMBER_TO_CHANGE_HOST){
roomRepository.deleteById(roomId);
Alarm alarm = alarmRepository.findFirstByRoom_Id(roomId);
if(Objects.isNull(alarm))
throw new BaseException(Status.ALARM_NOT_FOUND);
alarmRepository.delete(alarm);
return;
}
if(orderedRoomUser.size()<Constant.MINIMUM_NUMBER_TO_CHANGE_HOST)
deleteUnnecessaryRoomAndAlarm(roomId);

//방장이 제일 먼저 들어온 사람인 경우 그 다음 사람이 방장이 된다.
Integer nextHostId=orderedRoomUser.get(0).getId();
Expand All @@ -232,6 +226,16 @@ public void findNextCreatedUser(Integer roomId,Integer userId){
this.changeRoomHost(roomId,userId,nextHostId);
}

@Transactional
public void deleteUnnecessaryRoomAndAlarm(Integer roomId){
roomRepository.deleteById(roomId);
Alarm alarm = alarmRepository.findFirstByRoom_Id(roomId);
if(Objects.isNull(alarm))
throw new BaseException(Status.ALARM_NOT_FOUND);
alarmRepository.delete(alarm);
}


public RoomDetailRes getRoomDetail(Integer roomId){
//알람 조회
Alarm alarm = alarmRepository.findFirstByRoom_Id(roomId);
Expand Down

0 comments on commit e149373

Please sign in to comment.