1
1
package com.backgu.amaker.api.event.service
2
2
3
+ import com.backgu.amaker.api.event.dto.EventWithUserAndChatRoomDto
3
4
import com.backgu.amaker.api.event.dto.ReactionEventCreateDto
4
5
import com.backgu.amaker.api.event.dto.ReactionEventDetailDto
5
6
import com.backgu.amaker.api.event.dto.ReactionEventDto
@@ -12,14 +13,20 @@ import com.backgu.amaker.application.chat.service.ChatRoomService
12
13
import com.backgu.amaker.application.chat.service.ChatRoomUserService
13
14
import com.backgu.amaker.application.chat.service.ChatService
14
15
import com.backgu.amaker.application.event.service.EventAssignedUserService
16
+ import com.backgu.amaker.application.event.service.EventService
15
17
import com.backgu.amaker.application.event.service.ReactionEventService
16
18
import com.backgu.amaker.application.event.service.ReactionOptionService
17
19
import com.backgu.amaker.application.event.service.ReplyEventService
18
20
import com.backgu.amaker.application.user.service.UserService
21
+ import com.backgu.amaker.application.workspace.WorkspaceUserService
19
22
import com.backgu.amaker.common.exception.BusinessException
20
23
import com.backgu.amaker.common.status.StatusCode
21
24
import com.backgu.amaker.domain.chat.Chat
22
25
import com.backgu.amaker.domain.chat.ChatType
26
+ import com.backgu.amaker.domain.event.Event
27
+ import com.backgu.amaker.domain.event.EventAssignedUser
28
+ import com.backgu.amaker.domain.event.EventStatus
29
+ import com.backgu.amaker.domain.user.User
23
30
import org.springframework.context.ApplicationEventPublisher
24
31
import org.springframework.stereotype.Service
25
32
import org.springframework.transaction.annotation.Transactional
@@ -36,6 +43,8 @@ class EventFacadeService(
36
43
private val reactionOptionService : ReactionOptionService ,
37
44
private val eventAssignedUserService : EventAssignedUserService ,
38
45
private val eventPublisher : ApplicationEventPublisher ,
46
+ private val eventService : EventService ,
47
+ private val workspaceUserService : WorkspaceUserService ,
39
48
) {
40
49
@Transactional
41
50
fun getReplyEvent (
@@ -196,4 +205,29 @@ class EventFacadeService(
196
205
197
206
return ReactionEventDto .of(reactionEvent, reactionOptions)
198
207
}
208
+
209
+ fun getEvents (
210
+ userId : String ,
211
+ workspaceId : Long ,
212
+ eventStatus : EventStatus ,
213
+ ): List <EventWithUserAndChatRoomDto > {
214
+ workspaceUserService.validateUserInWorkspace(userId, workspaceId)
215
+ val events: List <Event > = eventService.findEventByWorkspaceId(workspaceId)
216
+ val eventUserMap: Map <Long , List <EventAssignedUser >> =
217
+ eventAssignedUserService.findByEventIdsToEventIdMapped(events.map { it.id })
218
+ val filteredEvents =
219
+ events.filter { eventStatus.filter(it, eventUserMap[it.id] ? : emptyList()) }
220
+ val chatToMap = chatService.findAllByIdsToMap(filteredEvents.map { it.id })
221
+
222
+ val userMap = userService.findAllByUserIdsToMap(eventUserMap.values.flatten().map { it.userId })
223
+
224
+ return filteredEvents.map { event: Event ->
225
+ val eventAssignedUsers: List <User > =
226
+ eventUserMap[event.id]?.mapNotNull { userMap[it.userId] } ? : emptyList()
227
+ val finishedNumber = eventUserMap[event.id]?.count { it.isFinished } ? : 0
228
+ val chat = chatToMap[event.id] ? : throw BusinessException (StatusCode .CHAT_NOT_FOUND )
229
+
230
+ EventWithUserAndChatRoomDto .of(event, chat, eventAssignedUsers, finishedNumber)
231
+ }
232
+ }
199
233
}
0 commit comments