-
Notifications
You must be signed in to change notification settings - Fork 1
[IDLE-577] 채팅 시스템 및 크롤링 공고 조회 최적화 #275
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
Changes from all commits
1d8fca3
5bd2770
c33ef7d
4de2d89
245ad0c
5b88723
bd3d191
74c8246
65242a3
ae76dfe
8d7e010
eefd1d7
b8328cf
5ce7eb5
69cae91
7ee886f
02b35a0
a454579
f27f5b7
07522cc
1f3e712
455fcfe
8e870c1
7910243
dea7a18
159fb6c
ed035dd
d4d5f41
fac8784
c60c1c1
f77453d
9a90d32
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,13 @@ import com.swm.idle.application.notification.domain.DeviceTokenService | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.application.user.carer.domain.CarerService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.application.user.center.service.domain.CenterManagerService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.application.user.center.service.domain.CenterService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.event.ChatRedisTemplate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.entity.jpa.ChatMessage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.event.ChatRedisPublisher | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.repository.ChatRedisRepository | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.vo.ChatRoomSummaryInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.chat.vo.ReadMessage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.user.carer.entity.jpa.Carer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.user.center.entity.jpa.Center | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.user.center.entity.jpa.CenterManager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.user.center.exception.CenterException | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.swm.idle.domain.user.center.vo.BusinessRegistrationNumber | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,28 +25,48 @@ import org.springframework.transaction.annotation.Transactional | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional(readOnly = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ChatFacadeService( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val centerManagerService: CenterManagerService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val chatRedisTemplate: ChatRedisTemplate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val chatRedisPublisher: ChatRedisPublisher, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val messageService: ChatMessageService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val notificationService: ChatNotificationService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val deviceTokenService: DeviceTokenService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val chatMessageService: ChatMessageService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val chatroomService: ChatRoomService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val centerService: CenterService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val carerService: CarerService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val chatRedisRepository: ChatRedisRepository, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun carerSend(request: SendChatMessageRequest, carerId: UUID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val message = messageService.save(request, carerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisTemplate.publish(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun send(request: SendChatMessageRequest, inputId: UUID, isCarer: Boolean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val userId = if(isCarer) inputId else getCenterId(inputId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val sequence = chatRedisRepository.getChatRoomSequence(request.chatroomId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val message = messageService.save(request, userId, sequence) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for(manager in getManagersByCenterId(UUID.fromString(request.receiverId))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (chatRedisTemplate.isChatting(manager.id)) continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisRepository.addUnreadChatRoom(request.receiverId, request.chatroomId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisRepository.updateReadSequence(request.chatroomId, message.sequence.toString(), userId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val token = deviceTokenService.findByUserId(manager.id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisPublisher.publish(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sendNotification(message, request, isCarer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun sendNotification( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: ChatMessage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request: SendChatMessageRequest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isCarer: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if(isCarer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (manager in getManagersByCenterId(UUID.fromString(request.receiverId))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (chatRedisRepository.isChatting(manager.id)) continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val token = deviceTokenService.findByUserId(manager.id) ?: continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notificationService.send(message, request.senderName, token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (chatRedisRepository.isChatting(message.receiverId)) return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val token = deviceTokenService.findByUserId(message.receiverId) ?: return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notificationService.send(message, request.senderName, token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -54,40 +78,25 @@ class ChatFacadeService( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun centerSend(request: SendChatMessageRequest, managerId: UUID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val centerId = getCenterId(managerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val message = messageService.save(request, centerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisTemplate.publish(message) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (chatRedisTemplate.isChatting(message.receiverId)) return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val token = deviceTokenService.findByUserId(message.receiverId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notificationService.send(message, request.senderName, token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun carerRead(request: ReadChatMessagesReqeust, carerId: UUID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messageService.read(request, carerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun read(request: ReadChatMessageRequest, inputId: UUID, isCarer: Boolean) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val userId = if(isCarer) inputId else getCenterId(inputId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisRepository.removeUnreadChatRoom(userId ,request.chatroomId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisRepository.updateReadSequence(request.chatroomId, request.sequence, userId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val readMessage = ReadMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRoomId = UUID.fromString(request.chatroomId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| receiverId = UUID.fromString(request.opponentId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readUserId = carerId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readUserId = userId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sequence = request.sequence.toLong() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisTemplate.publish(readMessage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisPublisher.publish(readMessage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun centerRead(request: ReadChatMessagesReqeust, managerId: UUID) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val centerId = getCenterId(managerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messageService.read(request, centerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val readMessage = ReadMessage( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRoomId = UUID.fromString(request.chatroomId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| receiverId = UUID.fromString(request.opponentId), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readUserId = centerId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRedisTemplate.publish(readMessage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun getCenterId(managerId:UUID): UUID { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val manager = centerManagerService.getById(managerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val businessNumber = BusinessRegistrationNumber(manager.centerBusinessRegistrationNumber) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val center = centerService.findByBusinessRegistrationNumber(businessNumber)?: throw CenterException.NotFoundException() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return center.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -112,36 +121,54 @@ class ChatFacadeService( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return center.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun getRecentMessages(chatRoomId: UUID, messageId: UUID?): List<ChatMessageResponse> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val effectiveMessageId = messageId ?: UuidCreator.create() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return chatMessageService.getRecentMessages(chatRoomId, effectiveMessageId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map { ChatMessageResponse(it) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional(readOnly = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun getRecentMessages( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRoomId: UUID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| messageId: UUID?, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isCarer: Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): ChatMessageResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val lastMessageId = messageId ?: UuidCreator.create() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val messages = chatMessageService.getRecentMessages(chatRoomId, lastMessageId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val messageInfo = messages.map { ChatMessageInfo(it) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val chatRoom = chatroomService.getById(chatRoomId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val opponentId = if (isCarer) chatRoom.centerId else chatRoom.carerId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val opponentReadSequence = chatRedisRepository.getReadSequence(opponentId, chatRoomId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ChatMessageResponse(messageInfo, opponentReadSequence) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Transactional(readOnly = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun getChatroomSummary(isCarer: Boolean): List<ChatRoomSummaryInfo> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val userId: UUID = if (isCarer) getUserAuthentication().userId | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else getCenterIdByAuthentication() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val summary = chatroomService.findChatroomSummaries(userId, isCarer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return if (isCarer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary.map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val center = centerService.getById(it.opponentId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy(opponentName = center.centerName, opponentProfileImageUrl = center.profileImageUrl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val userId = if (isCarer) getUserAuthentication().userId else getCenterIdByAuthentication() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val unreadChatRoomIds = chatRedisRepository.getUnreadChatRooms(userId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val readSequences = chatRedisRepository.getReadSequences(userId, unreadChatRoomIds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val summaries = chatroomService.findChatRoomsWithLastMessages(unreadChatRoomIds, isCarer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val opponentIds = summaries.map { it.opponentId }.toSet() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val opponentInfoMap = if (isCarer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| centerService.getByIds(opponentIds).associateBy { it.id } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary.map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val carer = carerService.getById(it.opponentId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it.copy(opponentName = carer.name, opponentProfileImageUrl = carer.profileImageUrl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| carerService.getByIds(opponentIds).associateBy { it.id } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun getCenterId(managerId:UUID): UUID { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val manager = centerManagerService.getById(managerId) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val businessNumber = BusinessRegistrationNumber(manager.centerBusinessRegistrationNumber) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val center = centerService.findByBusinessRegistrationNumber(businessNumber)?: throw CenterException.NotFoundException() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return center.id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return summaries.map { summary -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val readSeq = readSequences[summary.chatRoomId.toString()] ?: 0L | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary.count = (summary.count - readSeq).coerceAtLeast(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| val opponent = opponentInfoMap[summary.opponentId] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| summary.apply { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when (opponent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is Center -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opponentName = opponent.centerName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opponentProfileImageUrl = opponent.profileImageUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| is Carer -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opponentName = opponent.name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| opponentProfileImageUrl = opponent.profileImageUrl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+155
to
+172
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. 🛠️ Refactor suggestion 불변성을 유지하고 로직을 개선하세요. 현재 코드는 여러 문제점이 있습니다:
return summaries.map { summary ->
val readSeq = readSequences[summary.chatRoomId.toString()] ?: 0L
- summary.count = (summary.count - readSeq).coerceAtLeast(1)
+ val unreadCount = maxOf(0, summary.count - readSeq)
val opponent = opponentInfoMap[summary.opponentId]
- summary.apply {
- when (opponent) {
- is Center -> {
- opponentName = opponent.centerName
- opponentProfileImageUrl = opponent.profileImageUrl
- }
- is Carer -> {
- opponentName = opponent.name
- opponentProfileImageUrl = opponent.profileImageUrl
- }
- }
+ val (opponentName, opponentProfileImageUrl) = when (opponent) {
+ is Center -> opponent.centerName to opponent.profileImageUrl
+ is Carer -> opponent.name to opponent.profileImageUrl
+ else -> "Unknown" to null
}
+
+ summary.copy(
+ count = unreadCount,
+ opponentName = opponentName,
+ opponentProfileImageUrl = opponentProfileImageUrl
+ )
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.