Skip to content

Commit 79d3fd5

Browse files
committed
feat: 서류 지원결과와 최종 합격 결과 API 나누기
1 parent 52651c0 commit 79d3fd5

File tree

6 files changed

+78
-18
lines changed

6 files changed

+78
-18
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package dmu.dasom.api.domain.applicant.repository;
22

33
import dmu.dasom.api.domain.applicant.entity.Applicant;
4+
import dmu.dasom.api.domain.applicant.enums.ApplicantStatus;
45
import org.springframework.data.domain.Page;
56
import org.springframework.data.domain.Pageable;
67
import org.springframework.data.jpa.repository.JpaRepository;
78
import org.springframework.data.jpa.repository.Query;
89

10+
import java.util.List;
11+
912
public interface ApplicantRepository extends JpaRepository<Applicant, Long> {
1013

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

17+
// 상태별 지원자 조회
18+
List<Applicant> findByStatus(ApplicantStatus status);
19+
1420
}

src/main/java/dmu/dasom/api/domain/applicant/service/ApplicantService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public interface ApplicantService {
1616

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

19-
void sendEmailsToApplicants();
19+
void sendDocumentPassEmailsToApplicants();
20+
21+
void sendFinalPassEmailsToDocumentPassApplicants();
2022

2123
}

src/main/java/dmu/dasom/api/domain/applicant/service/ApplicantServiceImpl.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dmu.dasom.api.domain.applicant.dto.ApplicantResponseDto;
66
import dmu.dasom.api.domain.applicant.dto.ApplicantStatusUpdateRequestDto;
77
import dmu.dasom.api.domain.applicant.entity.Applicant;
8+
import dmu.dasom.api.domain.applicant.enums.ApplicantStatus;
89
import dmu.dasom.api.domain.applicant.repository.ApplicantRepository;
910
import dmu.dasom.api.domain.common.exception.CustomException;
1011
import dmu.dasom.api.domain.common.exception.ErrorCode;
@@ -64,19 +65,48 @@ public ApplicantDetailsResponseDto updateApplicantStatus(final Long id, final Ap
6465

6566
// 지원자 이메일 보내기
6667
@Override
67-
public void sendEmailsToApplicants(){
68+
public void sendDocumentPassEmailsToApplicants(){
6869
List<Applicant> applicants = applicantRepository.findAll();
6970

7071
if(applicants.isEmpty()) {
7172
throw new CustomException(ErrorCode.EMPTY_RESULT);
7273
}
7374

74-
String subject = "다솜 지원 결과";
75+
String subject = "다솜 서류 지원 결과";
7576

7677
for(Applicant applicant : applicants){
7778
try {
78-
emailService.sendEmail(applicant.getEmail(), subject, applicant.getName());
79-
log.info("HTML 이메일 전송 완료: {}", applicant.getEmail());
79+
emailService.sendEmail(
80+
applicant.getEmail(),
81+
subject,
82+
"document-pass-template",
83+
applicant.getName()
84+
);
85+
log.info("이메일 전송 완료: {}", applicant.getEmail());
86+
} catch (MessagingException e) {
87+
log.error("이메일 전송 실패: {}", applicant.getEmail(), e);
88+
}
89+
}
90+
}
91+
92+
@Override
93+
public void sendFinalPassEmailsToDocumentPassApplicants() {
94+
List<Applicant> applicants = applicantRepository.findByStatus(ApplicantStatus.DOCUMENT_PASSED);
95+
96+
if(applicants.isEmpty()){
97+
throw new CustomException(ErrorCode.EMPTY_RESULT);
98+
}
99+
100+
String subject = "다솜 최종 합격 결과";
101+
for (Applicant applicant : applicants) {
102+
try {
103+
emailService.sendEmail(
104+
applicant.getEmail(),
105+
subject,
106+
"final-pass-template",
107+
applicant.getName()
108+
);
109+
log.info("이메일 전송 완료: {}", applicant.getEmail());
80110
} catch (MessagingException e) {
81111
log.error("이메일 전송 실패: {}", applicant.getEmail(), e);
82112
}

src/main/java/dmu/dasom/api/domain/email/service/EmailService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class EmailService {
2121
@Value("${spring.mail.username}")
2222
private String from;
2323

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

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

3232
// 이메일 생성 및 전송
3333
MimeMessage message = javaMailSender.createMimeMessage();

src/main/java/dmu/dasom/api/global/admin/controller/AdminController.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public ResponseEntity<ApplicantDetailsResponseDto> updateApplicantStatus(@PathVa
7979
return ResponseEntity.ok(applicantService.updateApplicantStatus(id, request));
8080
}
8181

82-
@Operation(summary = "지원자 메일 전송")
82+
@Operation(summary = "서류 결과 메일 전송")
8383
@ApiResponses(value = {
8484
@ApiResponse(responseCode = "200", description = "메일 전송 성공"),
8585
@ApiResponse(responseCode = "400", description = "잘못된 요청",
@@ -89,15 +89,37 @@ public ResponseEntity<ApplicantDetailsResponseDto> updateApplicantStatus(@PathVa
8989
examples = {
9090
@ExampleObject(
9191
name = "전송 실패",
92-
value = "{ \"code\": \"C013\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
92+
value = "{ \"code\": \"C014\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
9393
)
9494
}
9595
)
9696
)
9797
})
98-
@PostMapping("/applicants/send-email")
99-
public ResponseEntity<String> sendEmailsToApplicants() {
100-
applicantService.sendEmailsToApplicants();
98+
@PostMapping("/applicants/send-document-pass-email")
99+
public ResponseEntity<String> sendDocumentPassEmails() {
100+
applicantService.sendDocumentPassEmailsToApplicants();
101+
return ResponseEntity.ok("이메일 전송 성공");
102+
}
103+
104+
@Operation(summary = "최종 결과 메일 전송")
105+
@ApiResponses(value = {
106+
@ApiResponse(responseCode = "200", description = "메일 전송 성공"),
107+
@ApiResponse(responseCode = "400", description = "잘못된 요청",
108+
content = @Content(
109+
mediaType = "application/json",
110+
schema = @Schema(implementation = ErrorResponse.class),
111+
examples = {
112+
@ExampleObject(
113+
name = "전송 실패",
114+
value = "{ \"code\": \"C014\", \"message\": \"이메일 전송에 실패하였습니다.\" }"
115+
)
116+
}
117+
)
118+
)
119+
})
120+
@PostMapping("/applicants/send-final-pass-email")
121+
public ResponseEntity<String> sendFinalPassEmail(){
122+
applicantService.sendFinalPassEmailsToDocumentPassApplicants();
101123
return ResponseEntity.ok("이메일 전송 성공");
102124
}
103125

src/main/resources/template/email-template.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
.header {
2424
font-size: 24px;
2525
font-weight: bold;
26-
color: #4caf50;
26+
color: #00B493;
2727
margin-bottom: 20px;
2828
}
2929
.sub-header {
3030
font-size: 16px;
31-
background-color: #4caf50;
31+
background-color: #00B493;
3232
padding: 10px;
3333
border-radius: 5px;
3434
margin-bottom: 20px;
@@ -41,19 +41,19 @@
4141
margin-bottom: 10px;
4242
}
4343
.highlight {
44-
color: #4caf50;
44+
color: #00B493;
4545
}
4646
.button {
4747
display: inline-block;
48-
background-color: #4caf50;
48+
background-color: #00B493;
4949
color: #ffffff;
5050
padding: 12px 24px;
5151
border-radius: 5px;
5252
text-decoration: none;
5353
font-size: 16px;
5454
}
5555
.button:hover {
56-
background-color: #45a049;
56+
background-color: #00B493;
5757
}
5858
</style>
5959
</head>
@@ -63,7 +63,7 @@
6363
<div class="header">DASOM</div>
6464

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

6868
<!-- Content Section -->
6969
<div class="content">

0 commit comments

Comments
 (0)