Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.RealMatch.business.application.event;

import com.example.RealMatch.business.domain.enums.ProposalDirection;
import com.example.RealMatch.business.domain.enums.ProposalStatus;

/**
Expand All @@ -11,6 +12,7 @@ public record CampaignProposalStatusChangedEvent(
Long brandUserId,
Long creatorUserId,
ProposalStatus newStatus,
Long actorUserId // 상태 변경을 수행한 사용자 ID (수락/거절한 사용자)
Long actorUserId, // 상태 변경을 수행한 사용자 ID (수락/거절한 사용자)
ProposalDirection proposalDirection // 누가 제안했는지 방향 (BRAND_TO_CREATOR / CREATOR_TO_BRAND)
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ private void publishProposalStatusChangedEvent(CampaignProposal proposal, Propos
brandUserId,
creatorUserId,
newStatus,
actorUserId
actorUserId,
ProposalDirection.fromWhoProposed(proposal.getWhoProposed())
);
eventPublisher.publishEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.springframework.transaction.event.TransactionalEventListener;

import com.example.RealMatch.business.application.event.CampaignProposalStatusChangedEvent;
import com.example.RealMatch.business.domain.enums.ProposalDirection;
import com.example.RealMatch.business.domain.enums.ProposalStatus;
import com.example.RealMatch.chat.domain.enums.ChatProposalDirection;
import com.example.RealMatch.chat.domain.enums.ChatProposalStatus;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -36,6 +38,7 @@ public void handleCampaignProposalStatusChanged(CampaignProposalStatusChangedEve
event.proposalId(), event.newStatus());

ChatProposalStatus chatStatus = toChatProposalStatus(event.newStatus());
ChatProposalDirection direction = toChatProposalDirection(event.proposalDirection());
String eventId = ProposalStatusChangedEvent.generateEventId(event.proposalId(), chatStatus);

ProposalStatusChangedEvent chatEvent = new ProposalStatusChangedEvent(
Expand All @@ -45,7 +48,8 @@ public void handleCampaignProposalStatusChanged(CampaignProposalStatusChangedEve
event.brandUserId(),
event.creatorUserId(),
chatStatus,
event.actorUserId()
event.actorUserId(),
direction
);
eventPublisher.publishEvent(chatEvent);

Expand All @@ -65,4 +69,14 @@ private static ChatProposalStatus toChatProposalStatus(ProposalStatus status) {
case REJECTED -> ChatProposalStatus.REJECTED;
};
}

private static ChatProposalDirection toChatProposalDirection(ProposalDirection direction) {
if (direction == null) {
return ChatProposalDirection.NONE;
}
return switch (direction) {
case BRAND_TO_CREATOR -> ChatProposalDirection.BRAND_TO_CREATOR;
case CREATOR_TO_BRAND -> ChatProposalDirection.CREATOR_TO_BRAND;
};
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.example.RealMatch.chat.application.event.proposal;

import com.example.RealMatch.chat.domain.enums.ChatProposalDirection;
import com.example.RealMatch.chat.domain.enums.ChatProposalStatus;

/**
* 채팅 모듈 내부용 제안 상태 변경 이벤트.
* 채팅 모듈 내부용 제안 상태 변경 이벤트
* 비즈니스 이벤트(CampaignProposalStatusChangedEvent)를 변환한 결과물입니다.
*/
public record ProposalStatusChangedEvent(
Expand All @@ -13,7 +14,8 @@ public record ProposalStatusChangedEvent(
Long brandUserId,
Long creatorUserId,
ChatProposalStatus newStatus,
Long actorUserId // 상태 변경을 수행한 사용자 ID (수락/거절/취소한 사용자)
Long actorUserId, // 상태 변경을 수행한 사용자 ID (수락/거절/취소한 사용자)
ChatProposalDirection proposalDirection
) {
/**
* 같은 proposalId와 newStatus 조합이면 항상 같은 ID가 생성됩니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void handleProposalStatusChanged(ProposalStatusChangedEvent event) {
);

// 매칭 완료 시 추가 카드 전송
if (event.newStatus() == ChatProposalStatus.MATCHED) {
if (event.newStatus() == ChatProposalStatus.MATCHED && event.campaignId() != null) {
String matchedCardKey = String.format("%s:MATCHED_CARD", event.eventId());

SystemEventMeta matchedMeta = new SystemEventMeta(
Expand All @@ -210,18 +210,17 @@ public void handleProposalStatusChanged(ProposalStatusChangedEvent event) {
matchedContextData.put("domainId", event.proposalId());
matchedContextData.put("proposalId", event.proposalId());
}
if (event.campaignId() != null) {
matchedContextData.put("campaignId", event.campaignId());
}
matchedContextData.put("campaignId", event.campaignId());

Long campaignId = event.campaignId();
execute(
matchedMeta,
matchedContextData,
() -> matchedCampaignPayloadProvider.getPayload(event.campaignId())
() -> matchedCampaignPayloadProvider.getPayload(campaignId, event.proposalDirection())
.orElseThrow(() -> {
String message = String.format(
"Failed to get matched campaign payload. campaignId=%d may not exist or be deleted",
event.campaignId()
"Failed to get matched campaign payload. campaignId=%s may not exist or be deleted",
campaignId
);
LOG.warn("[Proposal] {}. eventId={}, roomId={}", message, event.eventId(), roomId);
return new IllegalStateException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import java.util.Optional;

import com.example.RealMatch.chat.domain.enums.ChatProposalDirection;
import com.example.RealMatch.chat.presentation.dto.response.ChatMatchedCampaignPayloadResponse;

public interface MatchedCampaignPayloadProvider {

Optional<ChatMatchedCampaignPayloadResponse> getPayload(Long campaignId);
Optional<ChatMatchedCampaignPayloadResponse> getPayload(Long campaignId, ChatProposalDirection proposalDirection);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.example.RealMatch.campaign.domain.entity.Campaign;
import com.example.RealMatch.campaign.domain.repository.CampaignRepository;
import com.example.RealMatch.chat.domain.enums.ChatProposalDirection;
import com.example.RealMatch.chat.presentation.dto.response.ChatMatchedCampaignPayloadResponse;

import lombok.RequiredArgsConstructor;
Expand All @@ -19,16 +20,17 @@ public class MatchedCampaignPayloadProviderImpl implements MatchedCampaignPayloa
private final CampaignRepository campaignRepository;

@Override
public Optional<ChatMatchedCampaignPayloadResponse> getPayload(Long campaignId) {
public Optional<ChatMatchedCampaignPayloadResponse> getPayload(Long campaignId, ChatProposalDirection proposalDirection) {
if (campaignId == null) {
return Optional.empty();
}
ChatProposalDirection direction = proposalDirection != null ? proposalDirection : ChatProposalDirection.NONE;
return campaignRepository.findById(campaignId)
.filter(c -> !c.isDeleted())
.map(this::toPayload);
.map(c -> toPayload(c, direction));
Comment thread
1000hyehyang marked this conversation as resolved.
Outdated
}

private ChatMatchedCampaignPayloadResponse toPayload(Campaign campaign) {
private ChatMatchedCampaignPayloadResponse toPayload(Campaign campaign, ChatProposalDirection proposalDirection) {
// TODO: orderNumber - 결제/주문 도메인에서 주문 번호 확정 시 채팅으로 전달하거나,
// ProposalStatusChangedEvent(또는 매칭 완료 이벤트)에 orderNumber 포함 후 여기서 사용
return new ChatMatchedCampaignPayloadResponse(
Expand All @@ -37,7 +39,8 @@ private ChatMatchedCampaignPayloadResponse toPayload(Campaign campaign) {
campaign.getRewardAmount() != null ? campaign.getRewardAmount() : 0L,
DEFAULT_CURRENCY,
"",
null
null,
proposalDirection
);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.example.RealMatch.chat.presentation.dto.response;

import com.example.RealMatch.chat.domain.enums.ChatProposalDirection;

public record ChatMatchedCampaignPayloadResponse(
Long campaignId,
String campaignName,
long amount,
String currency,
String orderNumber,
String message
String message,
ChatProposalDirection proposalDirection
) implements ChatSystemMessagePayload {
}
Loading