Skip to content

Commit

Permalink
[fix] 인증방이 해체 안되는 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tpgh02 committed May 23, 2024
1 parent 22c776e commit 9932532
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions backend/src/main/java/com/dodo/room/RoomService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dodo.room;

import com.dodo.certification.CertificationRepository;
import com.dodo.certification.domain.Certification;
import com.dodo.exception.NotFoundException;
import com.dodo.image.ImageRepository;
import com.dodo.image.ImageService;
Expand Down Expand Up @@ -150,6 +151,7 @@ public Room createGroupRoom(String roomName, String roomPwd, Long maxUser, Categ
.goal(goal)
.nowGoal(0)
.isFull(isFull)
.image(imageRepository.findById(1L).get())
.build();

roomRepository.save(room);
Expand Down Expand Up @@ -181,6 +183,14 @@ public void minusUserCnt(Long roomId){
// 인증방 해체
public void deleteRoom(Long roomId){

List<RoomUser> roomUserList = roomUserRepository.findAllByRoomId(roomId).orElseThrow(NotFoundException::new);
for(RoomUser roomUser : roomUserList){
for (Certification certificate : certificationRepository.findAllByRoomUser(roomUser).get()){
certificate.setRoomUser(null);
certificationRepository.save(certificate);
}
}

roomUserRepository.deleteAllInBatch(roomUserRepository.findAllByRoomId(roomId).orElseThrow(NotFoundException::new));
roomTagRepository.deleteAllInBatch(roomTagRepository.findAllByRoom(roomRepository.findById(roomId).orElseThrow(NotFoundException::new)).orElseThrow(NotFoundException::new));

Expand Down
4 changes: 4 additions & 0 deletions backend/src/main/java/com/dodo/roomuser/RoomUserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public void deleteChatRoomUser(Long roomId, Long userId){
}
}

for (Certification certificate : certificationRepository.findAllByRoomUser(roomUser).get()){
certificate.setRoomUser(null);
certificationRepository.save(certificate);
}
roomUserRepository.delete(roomUser);

log.info("삭제한 room : {}, user : {}", roomUser.getRoom().getId(), roomUser.getUser().getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class RoomUser {
@ManyToOne
private Room room;

@OneToMany(mappedBy = "roomUser", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "roomUser", fetch = FetchType.LAZY)
private List<Certification> certification;

public RoomUser(User user, Room room) {
Expand Down

0 comments on commit 9932532

Please sign in to comment.