Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,14 +1,20 @@
package dmu.dasom.api.domain.applicant.repository;

import dmu.dasom.api.domain.applicant.entity.Applicant;
import dmu.dasom.api.domain.applicant.enums.ApplicantStatus;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ApplicantRepository extends JpaRepository<Applicant, Long> {

@Query("SELECT a FROM Applicant a ORDER BY a.id DESC")
Page<Applicant> findAllWithPageRequest(final Pageable pageable);

// 상태별 지원자 조회
List<Applicant> findByStatus(ApplicantStatus status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface ApplicantService {

ApplicantDetailsResponseDto updateApplicantStatus(final Long id, final ApplicantStatusUpdateRequestDto request);

void sendEmailsToApplicants();
void sendDocumentPassEmailsToApplicants();

void sendFinalPassEmailsToDocumentPassApplicants();

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dmu.dasom.api.domain.applicant.dto.ApplicantResponseDto;
import dmu.dasom.api.domain.applicant.dto.ApplicantStatusUpdateRequestDto;
import dmu.dasom.api.domain.applicant.entity.Applicant;
import dmu.dasom.api.domain.applicant.enums.ApplicantStatus;
import dmu.dasom.api.domain.applicant.repository.ApplicantRepository;
import dmu.dasom.api.domain.common.exception.CustomException;
import dmu.dasom.api.domain.common.exception.ErrorCode;
Expand Down Expand Up @@ -64,19 +65,48 @@ public ApplicantDetailsResponseDto updateApplicantStatus(final Long id, final Ap

// 지원자 이메일 보내기
@Override
public void sendEmailsToApplicants(){
public void sendDocumentPassEmailsToApplicants(){
Copy link
Member

Choose a reason for hiding this comment

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

AdminController 코멘트와 마찬가지로 메일 발송 메소드를 하나로 정의하고 발송 타입에 따라 다르게 동작되도록 구현하면 좋을 것 같습니다.

List<Applicant> applicants = applicantRepository.findAll();

if(applicants.isEmpty()) {
throw new CustomException(ErrorCode.EMPTY_RESULT);
}

String subject = "다솜 지원 결과";
String subject = "다솜 서류 지원 결과";

for(Applicant applicant : applicants){
try {
emailService.sendEmail(applicant.getEmail(), subject, applicant.getName());
log.info("HTML 이메일 전송 완료: {}", applicant.getEmail());
emailService.sendEmail(
applicant.getEmail(),
subject,
"document-pass-template",
applicant.getName()
);
log.info("이메일 전송 완료: {}", applicant.getEmail());
} catch (MessagingException e) {
log.error("이메일 전송 실패: {}", applicant.getEmail(), e);
}
}
}

@Override
public void sendFinalPassEmailsToDocumentPassApplicants() {
List<Applicant> applicants = applicantRepository.findByStatus(ApplicantStatus.DOCUMENT_PASSED);

if(applicants.isEmpty()){
throw new CustomException(ErrorCode.EMPTY_RESULT);
}

String subject = "다솜 최종 합격 결과";
for (Applicant applicant : applicants) {
try {
emailService.sendEmail(
applicant.getEmail(),
subject,
"final-pass-template",
applicant.getName()
);
log.info("이메일 전송 완료: {}", applicant.getEmail());
} catch (MessagingException e) {
log.error("이메일 전송 실패: {}", applicant.getEmail(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public class EmailService {
@Value("${spring.mail.username}")
private String from;

public void sendEmail(String to, String subject, String name) throws MessagingException {
public void sendEmail(String to, String subject, String templateName, String name) throws MessagingException {
// HTML 템플릿에 전달할 데이터 설정
Context context = new Context();
context.setVariable("name", name); // 지원자 이름 전달

// HTML 템플릿 처리
String htmlBody = templateEngine.process("email-template", context);
String htmlBody = templateEngine.process(templateName, context);

// 이메일 생성 및 전송
MimeMessage message = javaMailSender.createMimeMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ResponseEntity<ApplicantDetailsResponseDto> updateApplicantStatus(@PathVa
return ResponseEntity.ok(applicantService.updateApplicantStatus(id, request));
}

@Operation(summary = "지원자 메일 전송")
@Operation(summary = "서류 결과 메일 전송")
Copy link
Member

@ysw789 ysw789 Feb 18, 2025

Choose a reason for hiding this comment

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

서류, 최종 결과 메일 발송 메소드를 따로 나누지 않고 메일 발송 메소드 식으로 하나로 합쳐 클라이언트 요청에 따라 다르게 처리할 수 있을 것 같네요.
Enum으로 타입을 정의해놓고 클라이언트로부터 요청과 함께 메일 발송 타입을 전달받으면 그에 따라 발송되는 식으로 하는 건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is good idea!!

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "메일 전송 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청",
Expand All @@ -89,15 +89,37 @@ public ResponseEntity<ApplicantDetailsResponseDto> updateApplicantStatus(@PathVa
examples = {
@ExampleObject(
name = "전송 실패",
value = "{ \"code\": \"C013\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
value = "{ \"code\": \"C014\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
)
}
)
)
})
@PostMapping("/applicants/send-email")
public ResponseEntity<String> sendEmailsToApplicants() {
applicantService.sendEmailsToApplicants();
@PostMapping("/applicants/send-document-pass-email")
public ResponseEntity<String> sendDocumentPassEmails() {
applicantService.sendDocumentPassEmailsToApplicants();
return ResponseEntity.ok("이메일 전송 성공");
}

@Operation(summary = "최종 결과 메일 전송")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "메일 전송 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ErrorResponse.class),
examples = {
@ExampleObject(
name = "전송 실패",
value = "{ \"code\": \"C014\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
)
}
)
)
})
@PostMapping("/applicants/send-final-pass-email")
public ResponseEntity<String> sendFinalPassEmail(){
applicantService.sendFinalPassEmailsToDocumentPassApplicants();
return ResponseEntity.ok("이메일 전송 성공");
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/template/email-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
.header {
font-size: 24px;
font-weight: bold;
color: #4caf50;
color: #00B493;
margin-bottom: 20px;
}
.sub-header {
font-size: 16px;
background-color: #4caf50;
background-color: #00B493;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
Expand All @@ -41,19 +41,19 @@
margin-bottom: 10px;
}
.highlight {
color: #4caf50;
color: #00B493;
}
.button {
display: inline-block;
background-color: #4caf50;
background-color: #00B493;
color: #ffffff;
padding: 12px 24px;
border-radius: 5px;
text-decoration: none;
font-size: 16px;
}
.button:hover {
background-color: #45a049;
background-color: #00B493;
}
</style>
</head>
Expand All @@ -63,7 +63,7 @@
<div class="header">DASOM</div>

<!-- Sub-header Section -->
<div class="sub-header">컴퓨터 소프트웨어 공학과 전공 동아리 다솜<br>34기 합격자 조회</div>
<div class="sub-header">컴퓨터소프트웨어공학과 전공동아리 다솜<br>34기 서류 합격자 조회</div>

<!-- Content Section -->
<div class="content">
Expand Down