Skip to content

Commit

Permalink
feat : private -> private matching request mail auto send 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
oznchex committed Aug 6, 2024
1 parent dbd3aac commit b581566
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 61 deletions.
23 changes: 0 additions & 23 deletions src/main/java/liaison/linkit/mail/presentation/MailController.java

This file was deleted.

36 changes: 34 additions & 2 deletions src/main/java/liaison/linkit/mail/service/MailService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
package liaison.linkit.mail.service;

import java.time.LocalDateTime;

public interface MailService {
// 메일 발송
void sendSimpleMessage(String to)throws Exception;

// 1. 내 이력서 -> 내 이력서 매칭 요청 보낸 경우
void mailPrivateToPrivate(
final String receiverName,
final String senderName,
final LocalDateTime requestDate,
final String requestMessage
) throws Exception;

/*
1. 수신자 이름 - receiverName
2. 발신자 이름 - senderName
3. 매칭 요청 발생 날짜 - requestDate
4. 매칭 요청 보낼 때 메시지 - requestMessage
*/






// // 2. 내 이력서 -> 팀 소개서 매칭 요청 보낸 경우
// void mailPrivateToTeam() throws Exception;
// // 3. 팀 소개서 -> 내 이력서 매칭 요청 보낸 경우
// void mailTeamToPrivate() throws Exception;
// // 4. 팀 소개서 -> 팀 소개서 매칭 요청 보낸 경우
// void mailTeamToTeam() throws Exception;
//
// // 5. 내 이력서 관련 - 매칭 성사된 경우
// void mailSuccessPrivate() throws Exception;
// // 6. 팀 소개서 관련 - 매칭 성사된 경우
// void mailSuccessTeam() throws Exception;
}
60 changes: 31 additions & 29 deletions src/main/java/liaison/linkit/mail/service/MailServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
Expand All @@ -22,35 +22,40 @@ public class MailServiceImpl implements MailService {
@Value("${naver.id}")
private String id;

// 1. 내 이력서 -> 내 이력서 매칭 요청 보낸 경우
@Override
public void sendSimpleMessage(String to) throws Exception {
MimeMessage message = createMessage(to); // "to" 로 메일 발송
log.info("********생성된 메시지******** => " + message);
public void mailPrivateToPrivate(
final String receiverName,
final String senderName,
final LocalDateTime requestDate,
final String requestMessage
) throws Exception {
final MimeMessage mimeMessage = createPrivateToPrivateMail(
receiverName,
senderName,
requestDate,
requestMessage
);

try {
emailSender.send(message);
emailSender.send(mimeMessage);
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException();
}
}

private MimeMessage createMessage(String to) throws MessagingException, UnsupportedEncodingException {
log.info("메일받을 사용자 : " + to);

MimeMessage message = emailSender.createMimeMessage();
message.addRecipients(Message.RecipientType.TO, to);
message.setSubject("관리자 회원가입을 위한 이메일 인증코드");

// Define dynamic content
String recipientName = "Recipient Name"; // e.g., fetched from user info
String senderName = "Sukki";
String requestDate = "7월 12일";
String matchingRequestMessage = "매칭 요청 본문";
String profileSummary = "홍익대학교 시각디자인과 재학 중 초기 창업팀 근무 경험(5개월)";

// Use String.format() to insert variables into the message body
String msgg = String.format("""
private MimeMessage createPrivateToPrivateMail(
final String receiverName,
final String senderName,
final LocalDateTime requestDate,
final String requestMessage
) throws MessagingException {
final MimeMessage mimeMessage = emailSender.createMimeMessage();
mimeMessage.addRecipients(Message.RecipientType.TO, receiverName);
mimeMessage.setSubject("[링킷] 내 이력서 매칭 요청 알림");

final String msgg = String.format("""
<div class="container" style="font-family: 'Pretendard', sans-serif; margin: 0; padding: 0; box-sizing: border-box; background-color: #F0F2F6; display: flex; width: 100%%; flex-direction: column; align-items: center; justify-content: center; padding-top: 5rem; padding-bottom: 5rem;">
<div class="mail-wrapper" style="display: flex; flex-direction: column; width: 40.125rem; padding: 3.75rem 1.25rem 5.625rem 1.25rem; gap: 3.125rem; background-color: white; align-items: flex-start;">
<div class="center-content" style="display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2.125rem; width: 100%%;">
Expand Down Expand Up @@ -92,7 +97,7 @@ private MimeMessage createMessage(String to) throws MessagingException, Unsuppor
<div class="normal-text font-semibold" style="font-size: 0.875rem; font-weight: 400; line-height: 1.5625rem; color: var(--, #000); font-feature-settings: 'liga' off, 'clig' off;">
%s님의 이력</div>
<div class="normal-text" style="color: var(--Grey-scale-grey80, #27364B); line-height: 1.4375rem; font-size: 0.875rem; font-weight: 400; color: var(--, #000); font-feature-settings: 'liga' off, 'clig' off;">
%s
이력 설명
</div>
<div class="profile-link" style="display: flex; justify-content: flex-end; align-items: center; gap: 0.625rem; width: 100%%;">
<div class="right-text" style="text-align: right; font-size: 0.875rem; font-weight: 600; line-height: 1.5625rem; color: var(--, #000); font-feature-settings: 'liga' off, 'clig' off;">
Expand Down Expand Up @@ -121,13 +126,10 @@ private MimeMessage createMessage(String to) throws MessagingException, Unsuppor
</div>
</div>
</div>
""", recipientName, recipientName, senderName, requestDate, senderName, matchingRequestMessage, senderName, profileSummary, senderName);

message.setText(msgg, "utf-8", "html");
message.setFrom(id);
log.info("********createMessage 함수에서 생성된 msgg 메시지********" + msgg);
log.info("********createMessage 함수에서 생성된 리턴 메시지********" + message);
""", receiverName, receiverName, senderName, requestDate, senderName, requestMessage, senderName, senderName);
mimeMessage.setText(msgg, "utf-8", "html");
mimeMessage.setFrom(id);

return message;
return mimeMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import liaison.linkit.matching.dto.response.SuccessMatchingResponse;
import liaison.linkit.matching.dto.response.contact.SuccessContactResponse;
import liaison.linkit.matching.dto.response.existence.ExistenceProfileResponse;
import liaison.linkit.matching.dto.response.messageResponse.*;
import liaison.linkit.matching.dto.response.messageResponse.ReceivedPrivateMatchingMessageResponse;
import liaison.linkit.matching.dto.response.messageResponse.ReceivedTeamMatchingMessageResponse;
import liaison.linkit.matching.dto.response.messageResponse.RequestPrivateMatchingMessageResponse;
import liaison.linkit.matching.dto.response.messageResponse.RequestTeamMatchingMessageResponse;
import liaison.linkit.matching.service.MatchingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -62,7 +65,7 @@ public ResponseEntity<Void> createTeamProfileMatchingToPrivate(
@Auth final Accessor accessor,
@PathVariable final Long profileId,
@RequestBody @Valid MatchingCreateRequest matchingCreateRequest
) {
) throws Exception {
matchingService.createTeamProfileMatchingToPrivate(accessor.getMemberId(), profileId, matchingCreateRequest);
return ResponseEntity.status(CREATED).build();
}
Expand All @@ -78,6 +81,7 @@ public ResponseEntity<Void> createTeamProfileMatchingToTeam(
@RequestBody @Valid MatchingCreateRequest matchingCreateRequest
) {
matchingService.createTeamProfileMatchingToTeam(accessor.getMemberId(), teamMemberAnnouncementId, matchingCreateRequest);

return ResponseEntity.status(CREATED).build();
}

Expand Down Expand Up @@ -218,6 +222,7 @@ public ResponseEntity<RequestTeamMatchingMessageResponse> getRequestPrivateToTea
return ResponseEntity.status(HttpStatus.OK).body(requestTeamMatchingMessageResponse);
}


// 내 이력서 관련 매칭일 때 수락/거절하기 버튼을 누른 경우
// 이메일 발송 자동화 필요
@PostMapping("/allow/private/matching/{privateMatchingId}")
Expand All @@ -231,7 +236,7 @@ public ResponseEntity<Void> acceptReceivePrivateMatching(
return ResponseEntity.status(HttpStatus.OK).build();
}

// 팀 소개서 관련 매칭일 때 수락하기 버튼을 누른 경우
// 팀 소개서 관련 매칭일 때 수락/거절하기 버튼을 누른 경우
// 이메일 발송 자동화 필요
@PostMapping("/allow/team/matching/{teamMatchingId}")
@MemberOnly
Expand All @@ -244,6 +249,8 @@ public ResponseEntity<Void> acceptReceiveTeamMatching(
return ResponseEntity.status(HttpStatus.OK).build();
}



// 내 이력서 관련 매칭일 때 연락하기 버튼을 누른 경우
// 수신자가 내 이력서일 때
@GetMapping("/success/private/matching/contact/{privateMatchingId}")
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/liaison/linkit/matching/service/MatchingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import liaison.linkit.global.exception.AuthException;
import liaison.linkit.global.exception.BadRequestException;
import liaison.linkit.mail.service.MailService;
import liaison.linkit.matching.domain.PrivateMatching;
import liaison.linkit.matching.domain.TeamMatching;
import liaison.linkit.matching.domain.repository.PrivateMatchingRepository;
Expand Down Expand Up @@ -61,12 +62,13 @@ public class MatchingService {
private final PrivateMatchingRepository privateMatchingRepository;
private final TeamMatchingRepository teamMatchingRepository;
private final ProfileJobRoleRepository profileJobRoleRepository;

private final TeamProfileRepository teamProfileRepository;
private final TeamMemberAnnouncementRepository teamMemberAnnouncementRepository;

private final TeamMemberAnnouncementJobRoleRepository teamMemberAnnouncementJobRoleRepository;

// 매칭 관리 -> 이메일 발송 자동화 service 계층 필요
public final MailService mailService;

// 회원 정보를 가져오는 메서드
private Member getMember(final Long memberId) {
return memberRepository.findById(memberId)
Expand Down Expand Up @@ -157,7 +159,7 @@ public void createTeamProfileMatchingToPrivate(
final Long memberId,
final Long profileId,
final MatchingCreateRequest matchingCreateRequest
) {
) throws Exception {
final Member member = getMember(memberId);
final Profile profile = getProfileById(profileId);
if (Objects.equals(getProfile(memberId).getId(), profile.getId())) {
Expand All @@ -181,7 +183,14 @@ public void createTeamProfileMatchingToPrivate(
REMAINED
);

privateMatchingRepository.save(newPrivateMatching);
final PrivateMatching savedPrivateMatching = privateMatchingRepository.save(newPrivateMatching);

mailService.mailPrivateToPrivate(
profile.getMember().getMemberBasicInform().getMemberName(),
member.getMemberBasicInform().getMemberName(),
savedPrivateMatching.getCreatedAt(),
savedPrivateMatching.getRequestMessage()
);
}

// 3번
Expand Down

0 comments on commit b581566

Please sign in to comment.