라이브 방 - 라이브 나가기 로직 수정
This commit is contained in:
		| @@ -223,10 +223,9 @@ class LiveRoomController(private val service: LiveRoomService) { | |||||||
|  |  | ||||||
|     @PostMapping("/quit") |     @PostMapping("/quit") | ||||||
|     fun quitRoom( |     fun quitRoom( | ||||||
|         @RequestParam("id") roomId: Long, |  | ||||||
|         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? |         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? | ||||||
|     ) = run { |     ) = run { | ||||||
|         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") |         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") | ||||||
|         ApiResponse.ok(service.quitRoom(roomId, member)) |         ApiResponse.ok(service.quitRoom(member)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -843,11 +843,15 @@ class LiveRoomService( | |||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fun quitRoom(roomId: Long, member: Member) { |     fun quitRoom(member: Member) { | ||||||
|         val room = repository.getLiveRoom(roomId) |         val roomVisit = roomVisitService.getLatestRoomVisit(member.id!!) | ||||||
|  |  | ||||||
|  |         val roomId = roomVisit?.room?.id | ||||||
|  |         if (roomId != null) { | ||||||
|             val roomInfo = roomInfoRepository.findByIdOrNull(roomId) |             val roomInfo = roomInfoRepository.findByIdOrNull(roomId) | ||||||
|             if (roomInfo != null) { |             if (roomInfo != null) { | ||||||
|             if (room?.member != null && room.member!! == member) { |                 val room = repository.getLiveRoom(roomId) ?: return | ||||||
|  |                 if (room.member != null && room.member!! == member) { | ||||||
|                     room.isActive = false |                     room.isActive = false | ||||||
|                     kickOutService.deleteKickOutData(roomId = room.id!!) |                     kickOutService.deleteKickOutData(roomId = room.id!!) | ||||||
|                     roomInfoRepository.deleteById(roomInfo.roomId) |                     roomInfoRepository.deleteById(roomInfo.roomId) | ||||||
| @@ -859,4 +863,5 @@ class LiveRoomService( | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ interface LiveRoomVisitRepository : JpaRepository<LiveRoomVisit, Long>, LiveRoom | |||||||
| interface LiveRoomVisitQueryRepository { | interface LiveRoomVisitQueryRepository { | ||||||
|     fun findByRoomIdAndMemberId(roomId: Long, memberId: Long): LiveRoomVisit? |     fun findByRoomIdAndMemberId(roomId: Long, memberId: Long): LiveRoomVisit? | ||||||
|     fun findFirstByMemberIdOrderByUpdatedAtDesc(memberId: Long): LiveRoomVisit? |     fun findFirstByMemberIdOrderByUpdatedAtDesc(memberId: Long): LiveRoomVisit? | ||||||
|  |     fun getLatestRoomVisit(memberId: Long): LiveRoomVisit? | ||||||
| } | } | ||||||
|  |  | ||||||
| @Repository | @Repository | ||||||
| @@ -38,4 +39,13 @@ class LiveRoomVisitQueryRepositoryImpl(private val queryFactory: JPAQueryFactory | |||||||
|             .orderBy(liveRoomVisit.updatedAt.desc()) |             .orderBy(liveRoomVisit.updatedAt.desc()) | ||||||
|             .fetchFirst() |             .fetchFirst() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     override fun getLatestRoomVisit(memberId: Long): LiveRoomVisit? { | ||||||
|  |         return queryFactory | ||||||
|  |             .selectFrom(liveRoomVisit) | ||||||
|  |             .innerJoin(liveRoomVisit.member, member) | ||||||
|  |             .where(member.id.eq(memberId)) | ||||||
|  |             .orderBy(liveRoomVisit.updatedAt.desc()) | ||||||
|  |             .fetchFirst() | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -22,4 +22,8 @@ class LiveRoomVisitService(private val repository: LiveRoomVisitRepository) { | |||||||
|  |  | ||||||
|         repository.save(roomVisit) |         repository.save(roomVisit) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     fun getLatestRoomVisit(memberId: Long): LiveRoomVisit? { | ||||||
|  |         return repository.getLatestRoomVisit(memberId) | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user