Skip to content

Commit

Permalink
[SAMBAD-332] 손 흔들어 인사하기 수락 및 거절 이벤트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 committed Sep 13, 2024
1 parent da5cd82 commit 389b362
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void publishHandWavingEvent(
handWaving.mapEvent(event);
}

private Event publish(Long userId, Long meetingId, EventType type, Map<String, String> contentsMap) {
public Event publish(Long userId, Long meetingId, EventType type, Map<String, String> contentsMap) {
if (meetingMemberValidator.isNotUserOfMeeting(userId, meetingId)) {
log.warn("User is not member of meeting. userId: {}, meetingId: {}", userId, meetingId);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public enum EventType {
QUESTION_REGISTERED,
TARGET_MEMBER,
HAND_WAVING_REQUESTED,
HAND_WAVING_ACCEPTED,
HAND_WAVING_REJECTED,
;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.depromeet.sambad.moring.domain.meeting.handwaving.application;

import static org.depromeet.sambad.moring.domain.event.domain.EventType.*;
import static org.depromeet.sambad.moring.domain.meeting.handwaving.domain.HandWavingStatus.*;

import java.util.List;
Expand Down Expand Up @@ -57,7 +58,9 @@ public void acceptHandWaving(Long userId, Long meetingId, Long handWavingId) {
HandWaving handWaving = getHandWavingById(handWavingId);
handWaving.validateIsReceiver(userId);
handWaving.accept();

inactiveHandWavingEvent(handWaving);
publishAcceptedEvent(handWaving);
}

@Transactional
Expand All @@ -66,7 +69,9 @@ public void ignoreHandWaving(Long userId, Long meetingId, Long handWavingId) {
HandWaving handWaving = getHandWavingById(handWavingId);
handWaving.validateIsReceiver(userId);
handWaving.reject();

inactiveHandWavingEvent(handWaving);
publishRejectedEvent(handWaving);
}

public List<HandWavingSummary> getHandWavingSummariesBy(List<Event> events) {
Expand Down Expand Up @@ -101,7 +106,8 @@ private void publishRequestedEvent(HandWaving handWaving) {
Long userId = receiver.getUser().getId();
Long meetingId = receiver.getMeeting().getId();

eventService.publishHandWavingEvent(userId, meetingId, EventType.HAND_WAVING_REQUESTED, contentsMap, handWaving);
eventService.publishHandWavingEvent(userId, meetingId, EventType.HAND_WAVING_REQUESTED, contentsMap,
handWaving);
}

private void inactiveHandWavingEvent(HandWaving handWaving) {
Expand All @@ -110,4 +116,36 @@ private void inactiveHandWavingEvent(HandWaving handWaving) {
eventService.inactivate(eventId);
}
}

private void publishAcceptedEvent(HandWaving handWaving) {
publishAcceptedEventToSender(handWaving);
publishAcceptedEventToReceiver(handWaving);
}

private void publishRejectedEvent(HandWaving handWaving) {
// 내가 거절했으므로, 거절한 상대방의 이름이 메시지에 포함되어야 함
Map<String, String> contentsMap = Map.of("member", handWaving.getSender().getName());

// 이벤트의 대상은 본인이므로, Receiver의 정보를 사용함
Long userId = handWaving.getReceiver().getUser().getId();
Long meetingId = handWaving.getReceiver().getMeeting().getId();

eventService.publish(userId, meetingId, HAND_WAVING_REJECTED, contentsMap);
}

private void publishAcceptedEventToSender(HandWaving handWaving) {
Map<String, String> contentsMap = Map.of("member", handWaving.getReceiver().getName());
Long userId = handWaving.getSender().getUser().getId();
Long meetingId = handWaving.getSender().getMeeting().getId();

eventService.publish(userId, meetingId, HAND_WAVING_ACCEPTED, contentsMap);
}

private void publishAcceptedEventToReceiver(HandWaving handWaving) {
Map<String, String> contentsMap = Map.of("member", handWaving.getSender().getName());
Long userId = handWaving.getReceiver().getUser().getId();
Long meetingId = handWaving.getReceiver().getMeeting().getId();

eventService.publish(userId, meetingId, HAND_WAVING_ACCEPTED, contentsMap);
}
}

0 comments on commit 389b362

Please sign in to comment.