Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-be: 지원서 작성 완료 시 이메일 발송 기능 #960

Open
wants to merge 2 commits into
base: be/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -0,0 +1,8 @@
package com.cruru.applyform.domain.event;

import com.cruru.applicant.domain.Applicant;
import com.cruru.applyform.domain.ApplyForm;
import com.cruru.club.domain.Club;

public record ApplyFormEvent(Club club, ApplyForm applyForm, Applicant applicant) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.cruru.applyform.domain.event;

import com.cruru.applicant.domain.Applicant;
import com.cruru.applyform.domain.ApplyForm;
import com.cruru.club.domain.Club;
import com.cruru.email.service.EmailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
@Slf4j
public class ApplyFormEventListener {

private final EmailService emailService;

@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void handleApplyFormEvent(ApplyFormEvent event) {

log.info("시작");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트때 사용한 로그인가용??ㅋㅋ

Club club = event.club();
ApplyForm applyForm = event.applyForm();
Applicant applicant = event.applicant();

String subject = "지원 완료 안내";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제목에 동아리 이름도 넣어주는건 어떤가요?

String content = String.format(
"안녕하세요, %s님.\n\n%s 지원서가 성공적으로 제출되었습니다.\n\n감사합니다.",
applicant.getName(),
applyForm.getTitle()
);

emailService.send(
club,
applicant,
subject,
content,
null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.cruru.applyform.controller.request.ApplyFormWriteRequest;
import com.cruru.applyform.controller.response.ApplyFormResponse;
import com.cruru.applyform.domain.ApplyForm;
import com.cruru.applyform.domain.event.ApplyFormEvent;
import com.cruru.applyform.exception.badrequest.ApplyFormSubmitOutOfPeriodException;
import com.cruru.applyform.exception.badrequest.PersonalDataCollectDisagreeException;
import com.cruru.applyform.service.ApplyFormService;
import com.cruru.club.domain.Club;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.process.domain.Process;
import com.cruru.process.service.ProcessService;
Expand All @@ -22,6 +24,8 @@
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.hibernate.Hibernate;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -35,6 +39,7 @@ public class ApplyFormFacade {
private final ProcessService processService;
private final ApplicantService applicantService;
private final AnswerService answerService;
private final ApplicationEventPublisher applicationEventPublisher;
private final Clock clock;

public ApplyFormResponse readApplyFormById(long applyFormId) {
Expand Down Expand Up @@ -68,6 +73,10 @@ public void submit(long applyFormId, ApplyFormSubmitRequest request) {
AnswerCreateRequest answerCreateRequest = getAnswerCreateRequest(question, answerCreateRequests);
answerService.saveAnswerReplies(answerCreateRequest, question, applicant);
}

Club club = dashboard.getClub();
Hibernate.initialize(club);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmailServicesend 메서드에서 Club, Applicant를 매개변수로 받고 있더라고요.
Club을 그대로 전달하게 되면 다음과 같은 오류가 발생해서 이메일 전송에 실패합니다.
image

여기에서 강제 초기화해서 전달해두었습니다.!

유연성을 위해서 이메일 전송 발신자, 수신자를 String 매개변수로 하는건 어떨까 싶습니다?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 어떤 대상에게 보낸 이메일만 검색할 수 있는 기능을 넣는다면 현재 구조가 좋다고 생각하지만,, 추후의 유연성을 위해선 String 값인것도 좋을 것 같네요.
현재 상태에서 발신자를 String으로 변경한다면 동아리 이름 중복이 허용되었을 때, 내 동아리가 아닌 다른 동아리의 메일을 구분할 수 없을 것 같네요.

applicationEventPublisher.publishEvent(new ApplyFormEvent(club, applyForm, applicant));
}

private void validatePersonalDataCollection(ApplyFormSubmitRequest request) {
Expand Down
Loading