@Service
@RequiredArgsConstructor
public class ChatMessageService {
**private final NotificationCommandService notificationCommandService;**
**@Transactional**
public void sendMessage(Long roomId, Long senderId, Long receiverId, String content) {
notificationCommandService.sendChat(receiverId, roomId, senderName, message);
}
}
@Service
@RequiredArgsConstructor
public class ChatMessageService {
private final ChatMessageRepository chatMessageRepository;
private final MemberRepository memberRepository;
private final NotificationCommandService notificationCommandService;
@Transactional
public Long sendMessage(Long roomId, Long senderId, Long receiverId, String content) {
// 1) 채팅 메시지 저장
ChatMessage msg = chatMessageRepository.save(
ChatMessage.of(roomId, senderId, receiverId, content)
);
// 2) 발신자 이름 조회(미리 조합해두면 좋음)
String senderName = memberRepository.findMemberById(senderId)
.map(Member::getName)
.orElse("알 수 없음");
// 3) 알림 보내기 호출
notificationCommandService.sendChat(receiverId, roomId, senderName, content);
return msg.getId();
}
}
@Service
@RequiredArgsConstructor
public class SuggestionService {
private final SuggestionRepository suggestionRepository;
private final NotificationCommandService notificationCommandService;
@Transactional
public Long submitSuggestion(Long receiverId, SuggestionCreateDto dto) {
Suggestion s = suggestionRepository.save(Suggestion.create(dto));
notificationCommandService.sendPartnerSuggestion(receiverId, s.getId());
return s.getId();
}
}
@Service
@RequiredArgsConstructor
public class OrderService {
private final OrderRepository orderRepository;
private final NotificationCommandService notificationCommandService;
@Transactional
public Long placeOrder(OrderCreateDto dto) {
Order order = orderRepository.save(Order.create(dto));
notificationCommandService.sendOrder(
/*receiverId: 사장님 아이디*/ order.getOwnerId(),
/*orderId (아무 int 값이나 넘겨주세요..)*/ order.getId(),
/*tableNum*/ dto.getTableNum(),
/*paperContent*/ dto.getPromoPaperText() //예: "20,000원 이상 10% 할인"
);
return order.getId();
}
}
@Service
@RequiredArgsConstructor
public class ProposalService {
private final ProposalRepository proposalRepository;
private final NotificationCommandService notificationCommandService;
@Transactional
public Long propose(Long receiverId, String partnerName, ProposalDto dto) {
Proposal p = proposalRepository.save(Proposal.create(dto));
notificationCommandService.sendPartnerProposal(receiverId, p.getId(), partnerName);
return p.getId();
}
}
목적: ORDER 제외 타입에 대해 “해당 상세로 이동” 이벤트 뿌리기