@@ -7,6 +7,8 @@ import com.backgu.amaker.api.event.dto.ReactionEventDto
7
7
import com.backgu.amaker.api.event.dto.ReplyEventCreateDto
8
8
import com.backgu.amaker.api.event.dto.ReplyEventDetailDto
9
9
import com.backgu.amaker.api.event.dto.ReplyEventDto
10
+ import com.backgu.amaker.api.event.dto.TaskEventCreateDto
11
+ import com.backgu.amaker.api.event.dto.TaskEventDto
10
12
import com.backgu.amaker.api.user.dto.UserDto
11
13
import com.backgu.amaker.application.chat.event.EventChatSaveEvent
12
14
import com.backgu.amaker.application.chat.service.ChatRoomService
@@ -17,6 +19,7 @@ import com.backgu.amaker.application.event.service.EventService
17
19
import com.backgu.amaker.application.event.service.ReactionEventService
18
20
import com.backgu.amaker.application.event.service.ReactionOptionService
19
21
import com.backgu.amaker.application.event.service.ReplyEventService
22
+ import com.backgu.amaker.application.event.service.TaskEventService
20
23
import com.backgu.amaker.application.user.service.UserService
21
24
import com.backgu.amaker.application.workspace.WorkspaceUserService
22
25
import com.backgu.amaker.common.exception.BusinessException
@@ -39,6 +42,7 @@ class EventFacadeService(
39
42
private val chatRoomUserService : ChatRoomUserService ,
40
43
private val chatService : ChatService ,
41
44
private val replyEventService : ReplyEventService ,
45
+ private val taskEventService : TaskEventService ,
42
46
private val reactionEventService : ReactionEventService ,
43
47
private val reactionOptionService : ReactionOptionService ,
44
48
private val eventAssignedUserService : EventAssignedUserService ,
@@ -164,6 +168,45 @@ class EventFacadeService(
164
168
return ReplyEventDto .of(replyEvent)
165
169
}
166
170
171
+ @Transactional
172
+ fun createTaskEvent (
173
+ userId : String ,
174
+ chatRoomId : Long ,
175
+ taskEventCreateDto : TaskEventCreateDto ,
176
+ ): TaskEventDto {
177
+ val user = userService.getById(userId)
178
+ val chatRoom = chatRoomService.getById(chatRoomId)
179
+ chatRoomUserService.validateUserInChatRoom(user, chatRoom)
180
+
181
+ val chat: Chat = chatService.save(chatRoom.createChat(user, taskEventCreateDto.eventTitle, ChatType .TASK ))
182
+ chatRoomService.save(chatRoom.updateLastChatId(chat))
183
+
184
+ val taskEvent =
185
+ taskEventService.save(
186
+ chat.createTaskEvent(
187
+ taskEventCreateDto.deadLine,
188
+ taskEventCreateDto.notificationStartHour,
189
+ taskEventCreateDto.notificationStartMinute,
190
+ taskEventCreateDto.interval,
191
+ taskEventCreateDto.eventDetails,
192
+ ),
193
+ )
194
+
195
+ val users = userService.getAllByUserEmails(taskEventCreateDto.assignees)
196
+ chatRoomUserService.validateUsersInChatRoom(users, chatRoom)
197
+
198
+ eventAssignedUserService.saveAll(taskEvent.createAssignedUsers(users))
199
+
200
+ eventPublisher.publishEvent(
201
+ EventChatSaveEvent .of(
202
+ chatRoomId,
203
+ chat.createEventChatWithUser(taskEvent, user, users),
204
+ ),
205
+ )
206
+
207
+ return TaskEventDto .of(taskEvent)
208
+ }
209
+
167
210
@Transactional
168
211
fun createReactionEvent (
169
212
userId : String ,
0 commit comments