This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEAV-000] 미팅매칭시 이벤트 메시지 발송 리펙터링 (#245)
- Loading branch information
1 parent
997e289
commit 8ef193a
Showing
12 changed files
with
185 additions
and
68 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...n/src/main/kotlin/com/studentcenter/weave/application/chat/port/inbound/CreateChatRoom.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package com.studentcenter.weave.application.chat.port.inbound | ||
|
||
import com.studentcenter.weave.domain.meeting.entity.Meeting | ||
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent | ||
|
||
interface CreateChatRoom { | ||
|
||
fun invoke(meeting: Meeting) | ||
fun invoke(meetingCompletedEvent: MeetingCompletedEvent) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ain/kotlin/com/studentcenter/weave/application/meeting/port/inbound/NotifyMeetingEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.studentcenter.weave.application.meeting.port.inbound | ||
|
||
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent | ||
|
||
interface NotifyMeetingEvent { | ||
|
||
fun notifyMeetingCompleted(meetingCompletedEvent: MeetingCompletedEvent) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
.../studentcenter/weave/application/meeting/service/application/NotifyMeetingEventService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.studentcenter.weave.application.meeting.service.application | ||
|
||
import com.studentcenter.weave.application.meeting.port.inbound.NotifyMeetingEvent | ||
import com.studentcenter.weave.application.meeting.port.outbound.MeetingEventMessagePort | ||
import com.studentcenter.weave.application.meeting.service.domain.MeetingDomainService | ||
import com.studentcenter.weave.application.meeting.vo.MeetingMatchingEvent | ||
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTeam | ||
import com.studentcenter.weave.domain.meeting.entity.Meeting | ||
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent | ||
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummary | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class NotifyMeetingEventService( | ||
private val meetingDomainService: MeetingDomainService, | ||
private val meetingEventMessagePort: MeetingEventMessagePort, | ||
private val getMeetingTeam: GetMeetingTeam, | ||
) : NotifyMeetingEvent { | ||
|
||
@Transactional | ||
override fun notifyMeetingCompleted(meetingCompletedEvent: MeetingCompletedEvent) { | ||
val meeting: Meeting = meetingCompletedEvent.entity | ||
val matchedMeetingCount: Int = meetingDomainService.countByStatusIsCompleted() | ||
|
||
val requestingMeetingTeamMemberSummary: MeetingTeamMemberSummary = | ||
getMeetingTeam.getMeetingTeamMemberSummaryByMeetingTeamId(meeting.requestingTeamId) | ||
val receivingMeetingTeamMemberSummary: MeetingTeamMemberSummary = | ||
getMeetingTeam.getMeetingTeamMemberSummaryByMeetingTeamId(meeting.receivingTeamId) | ||
|
||
MeetingMatchingEvent( | ||
meeting = meeting, | ||
memberCount = getMeetingMemberCount(meeting), | ||
matchedMeetingCount = matchedMeetingCount, | ||
requestingMeetingTeamMbti = requestingMeetingTeamMemberSummary.teamMbti, | ||
receivingMeetingTeamMbti = receivingMeetingTeamMemberSummary.teamMbti, | ||
).also { | ||
meetingEventMessagePort.sendMeetingIsMatchedMessage(it) | ||
} | ||
} | ||
|
||
private fun getMeetingMemberCount(meeting: Meeting): Int { | ||
val requestingTeam = getMeetingTeam.getById(meeting.requestingTeamId) | ||
val receivingTeam = getMeetingTeam.getById(meeting.receivingTeamId) | ||
|
||
return requestingTeam.memberCount + receivingTeam.memberCount | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...dentcenter/weave/application/meeting/service/application/NotifyMeetingEventServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.studentcenter.weave.application.meeting.service.application | ||
|
||
import com.studentcenter.weave.application.meeting.outbound.MeetingEventMessagePortSpy | ||
import com.studentcenter.weave.application.meeting.outbound.MeetingRepositorySpy | ||
import com.studentcenter.weave.application.meeting.service.domain.impl.MeetingDomainServiceImpl | ||
import com.studentcenter.weave.application.meetingTeam.port.inbound.GetMeetingTeam | ||
import com.studentcenter.weave.domain.meeting.entity.MeetingFixtureFactory | ||
import com.studentcenter.weave.domain.meeting.enums.MeetingStatus | ||
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent | ||
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamFixtureFactory | ||
import com.studentcenter.weave.domain.meetingTeam.entity.MeetingTeamMemberSummaryFixtureFactory | ||
import io.kotest.core.annotation.DisplayName | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
|
||
@DisplayName("NotifyMeetingEventService") | ||
class NotifyMeetingEventServiceTest : DescribeSpec({ | ||
|
||
val meetingRepository = MeetingRepositorySpy() | ||
val meetingDomainService = MeetingDomainServiceImpl(meetingRepository) | ||
val meetingEventMessagePort = MeetingEventMessagePortSpy() | ||
val getMeetingTeamMock = mockk<GetMeetingTeam>() | ||
|
||
val sut = NotifyMeetingEventService( | ||
meetingDomainService = meetingDomainService, | ||
meetingEventMessagePort = meetingEventMessagePort, | ||
getMeetingTeam = getMeetingTeamMock, | ||
) | ||
|
||
describe("notifyMeetingCompleted") { | ||
it("미팅 완료 이벤트 발생시 알림 메시지를 전송한다") { | ||
// arrange | ||
val requestMeetingTeam = MeetingTeamFixtureFactory.create() | ||
val receivingMeetingTeam = MeetingTeamFixtureFactory.create() | ||
|
||
val requestingMeetingTeamMemberSummary = MeetingTeamMemberSummaryFixtureFactory.create( | ||
meetingTeamId = requestMeetingTeam.id, | ||
) | ||
val receivingMeetingTeamMemberSummary = MeetingTeamMemberSummaryFixtureFactory.create( | ||
meetingTeamId = receivingMeetingTeam.id, | ||
) | ||
|
||
val meeting = MeetingFixtureFactory.create( | ||
requestingTeamId = requestMeetingTeam.id, | ||
receivingTeamId = receivingMeetingTeam.id, | ||
status = MeetingStatus.COMPLETED | ||
) | ||
meetingRepository.save(meeting) | ||
|
||
val event = MeetingCompletedEvent(meeting) | ||
|
||
every { getMeetingTeamMock.getMeetingTeamMemberSummaryByMeetingTeamId(requestMeetingTeam.id) } returns requestingMeetingTeamMemberSummary | ||
every { | ||
getMeetingTeamMock.getMeetingTeamMemberSummaryByMeetingTeamId( | ||
receivingMeetingTeam.id | ||
) | ||
} returns receivingMeetingTeamMemberSummary | ||
every { getMeetingTeamMock.getById(requestMeetingTeam.id) } returns requestMeetingTeam | ||
every { getMeetingTeamMock.getById(receivingMeetingTeam.id) } returns receivingMeetingTeam | ||
|
||
// act | ||
sut.notifyMeetingCompleted(event) | ||
|
||
// assert | ||
meetingEventMessagePort.count() shouldBe 1 | ||
} | ||
} | ||
|
||
}) |
22 changes: 22 additions & 0 deletions
22
...kotlin/com/studentcenter/weave/application/meeting/outbound/MeetingEventMessagePortSpy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.studentcenter.weave.application.meeting.outbound | ||
|
||
import com.studentcenter.weave.application.meeting.port.outbound.MeetingEventMessagePort | ||
import com.studentcenter.weave.application.meeting.vo.MeetingMatchingEvent | ||
|
||
class MeetingEventMessagePortSpy: MeetingEventMessagePort { | ||
|
||
private val meetingMatchingEvents = mutableListOf<MeetingMatchingEvent>() | ||
|
||
override fun sendMeetingIsMatchedMessage(meetingMatchingEvent: MeetingMatchingEvent) { | ||
meetingMatchingEvents.add(meetingMatchingEvent) | ||
} | ||
|
||
fun count(): Int { | ||
return meetingMatchingEvents.size | ||
} | ||
|
||
fun clear() { | ||
meetingMatchingEvents.clear() | ||
} | ||
|
||
} |
12 changes: 9 additions & 3 deletions
12
...c/main/kotlin/com/studentcenter/weave/bootstrap/meeting/controller/MeetingEventHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
package com.studentcenter.weave.bootstrap.meeting.controller | ||
|
||
import com.studentcenter.weave.application.chat.port.inbound.CreateChatRoom | ||
import com.studentcenter.weave.application.meeting.port.inbound.NotifyMeetingEvent | ||
import com.studentcenter.weave.domain.meeting.event.MeetingCompletedEvent | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.stereotype.Controller | ||
|
||
@Controller | ||
class MeetingEventHandler( | ||
private val createChatRoom: CreateChatRoom, | ||
private val notifyMeetingEvent: NotifyMeetingEvent, | ||
) { | ||
|
||
@EventListener | ||
fun handleMeetingEvent(meetingCompletedEvent: MeetingCompletedEvent) { | ||
meetingCompletedEvent | ||
.entity | ||
.also { createChatRoom.invoke(it) } | ||
CoroutineScope(Dispatchers.Default).launch { | ||
launch { createChatRoom.invoke(meetingCompletedEvent) } | ||
launch { notifyMeetingEvent.notifyMeetingCompleted(meetingCompletedEvent) } | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.