Skip to content

Commit

Permalink
feat: 커피챗 메일 발송 가능하도록 수정 (#570)
Browse files Browse the repository at this point in the history
- request validation 추가
- sender return 조건 수정
  • Loading branch information
jun02160 authored Dec 28, 2024
1 parent c5da3f0 commit aa87e2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.sopt.makers.internal.external;

import lombok.RequiredArgsConstructor;

import org.sopt.makers.internal.external.email.EmailChatSender;
import org.sopt.makers.internal.external.gabia.SmsChatSender;
import org.sopt.makers.internal.member.domain.coffeechat.ChatCategory;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -13,10 +13,13 @@ public class MessageSenderFactory {
private final SmsChatSender smsChatSender;
private final EmailChatSender emailChatSender;

public MessageSender getSender(ChatCategory category) {
return switch (category) {
case COFFEE_CHAT -> smsChatSender;
case FRIENDSHIP, APPJAM_TEAM_BUILD, PROJECT_PROPOSAL, OTHER -> emailChatSender;
};
public MessageSender getSender(String senderEmail, String senderPhone) {
if (senderEmail != null) {
return emailChatSender;
}
if (senderPhone != null) {
return smsChatSender;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import org.sopt.makers.internal.exception.ClientBadRequestException;
import org.sopt.makers.internal.member.domain.coffeechat.ChatCategory;

import javax.validation.constraints.NotBlank;
Expand All @@ -28,4 +30,13 @@ public record CoffeeChatRequest(
@NotBlank(message = "수신 본문은 필수 입력 값입니다.")
@Size(max = 500, message = "본문은 500자를 초과할 수 없습니다.")
String content
) {}
) {
public CoffeeChatRequest {
if (senderEmail == null && senderPhone == null) {
throw new ClientBadRequestException("발신자 이메일 또는 전화번호 중 하나는 필수 입력 값입니다.");
}
if (senderEmail != null && senderPhone != null) {
throw new ClientBadRequestException("발신자 이메일과 전화번호는 모두 요청이 불가능합니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void sendCoffeeChatRequest (CoffeeChatRequest request, Long senderId) {

String replyInfo = getReplyInfo(request, sender);

MessageSender senderStrategy = messageSenderFactory.getSender(request.category());
MessageSender senderStrategy = messageSenderFactory.getSender(request.senderEmail(), request.senderPhone());
senderStrategy.sendMessage(sender, receiver, request.content(), replyInfo, request.category());

createHistoryByCategory(request, sender, receiver);
Expand Down

0 comments on commit aa87e2f

Please sign in to comment.