Skip to content

Commit

Permalink
feat-be: 지원서 작성 완료 시 이메일 발송 기능 (#960)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Leetaehoon <[email protected]>
  • Loading branch information
github-actions[bot] and xogns1514 authored Jan 2, 2025
1 parent 8397c42 commit d63a3b3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
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,44 @@
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) {

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

String subject = "지원 완료 안내";
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);
applicationEventPublisher.publishEvent(new ApplyFormEvent(club, applyForm, applicant));
}

private void validatePersonalDataCollection(ApplyFormSubmitRequest request) {
Expand Down

0 comments on commit d63a3b3

Please sign in to comment.