-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] #42 사전알림 기능 구현
- Loading branch information
Showing
13 changed files
with
319 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/land/leets/domain/mail/controller/dto/RecruitMailRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package land.leets.domain.mail.controller.dto; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record RecruitMailRequest( | ||
@NotBlank | ||
String email | ||
) { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/land/leets/domain/mail/domain/RecruitMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package land.leets.domain.mail.domain; | ||
|
||
import jakarta.persistence.*; | ||
import land.leets.domain.shared.BaseTimeEntity; | ||
import lombok.*; | ||
|
||
@Entity(name = "recruit_mails") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class RecruitMail extends BaseTimeEntity { | ||
|
||
@Id | ||
@Column(nullable = false) | ||
private String email; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/land/leets/domain/mail/domain/repository/RecruitMailRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package land.leets.domain.mail.domain.repository; | ||
|
||
import land.leets.domain.mail.domain.RecruitMail; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface RecruitMailRepository extends JpaRepository<RecruitMail, Long> { | ||
List<RecruitMail> findAll(); | ||
|
||
boolean existsByEmail(String email); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/land/leets/domain/mail/exception/MailAlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package land.leets.domain.mail.exception; | ||
|
||
import land.leets.global.error.ErrorCode; | ||
import land.leets.global.error.exception.ServiceException; | ||
|
||
public class MailAlreadyExistsException extends ServiceException { | ||
public MailAlreadyExistsException() { | ||
super(ErrorCode.EMAIL_ALREADY_EXISTS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/land/leets/domain/mail/usecase/SendRecruitMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package land.leets.domain.mail.usecase; | ||
|
||
import land.leets.domain.mail.domain.Mail; | ||
import land.leets.domain.mail.domain.repository.RecruitMailRepository; | ||
import land.leets.domain.mail.service.MailManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.context.Context; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional | ||
public class SendRecruitMail { | ||
|
||
private static final String MAIL_TITLE = "[Leets] 5기 모집 시작 안내 메일입니다."; | ||
private static final String GENERATION_FIELD = "generation"; | ||
private static final String TEMPLATE = "Recruit.html"; | ||
|
||
private final RecruitMailRepository recruitMailRepository; | ||
private final TemplateEngine templateEngine; | ||
private final MailManager mailManager; | ||
|
||
public void execute() { | ||
List<Mail> mails = recruitMailRepository.findAll().stream() | ||
.map(recruitMail -> { | ||
Context context = makeContext(); | ||
String message = templateEngine.process(TEMPLATE, context); | ||
return new Mail(MAIL_TITLE, recruitMail.getEmail(), message); | ||
}) | ||
.toList(); | ||
|
||
mailManager.sendEmails(mails); | ||
} | ||
|
||
private Context makeContext() { | ||
Context context = new Context(); | ||
context.setVariable(GENERATION_FIELD, 5); | ||
return context; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/land/leets/domain/mail/usecase/SubscribeRecruitMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package land.leets.domain.mail.usecase; | ||
|
||
import land.leets.domain.mail.controller.dto.RecruitMailRequest; | ||
import land.leets.domain.mail.domain.RecruitMail; | ||
import land.leets.domain.mail.domain.repository.RecruitMailRepository; | ||
import land.leets.domain.mail.exception.MailAlreadyExistsException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class SubscribeRecruitMail { | ||
|
||
private final RecruitMailRepository recruitMailRepository; | ||
|
||
public void execute(RecruitMailRequest request) { | ||
if (recruitMailRepository.existsByEmail(request.email())) { | ||
throw new MailAlreadyExistsException(); | ||
} | ||
RecruitMail recruitMail = new RecruitMail(request.email()); | ||
|
||
recruitMailRepository.save(recruitMail); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.