-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] 메일 템플릿 및 기능 구현 * [feat] 도메인 및 ENUM 작성 * [feat] 메일링 서비스 구현 * [feat] 에러 처리 * [refact] url 및 메서드 명 변경 * [add] 루트 권한 설정 * [chore] enum 필드 삭제
- Loading branch information
1 parent
8af6019
commit 084f952
Showing
18 changed files
with
410 additions
and
2 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/ceos/backend/domain/subscriber/SubscriberController.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,35 @@ | ||
package ceos.backend.domain.subscriber; | ||
|
||
|
||
import ceos.backend.domain.subscriber.dto.request.SubscribeRequest; | ||
import ceos.backend.domain.subscriber.service.SubscriberService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/subscribe") | ||
@Tag(name = "Subscriber") | ||
public class SubscriberController { | ||
|
||
private final SubscriberService subscriberService; | ||
|
||
@Operation(summary = "메일링 서비스 구독") | ||
@PostMapping | ||
public void subscribeMail(@RequestBody @Valid SubscribeRequest subscribeRequest) { | ||
log.info("메일링 서비스 구독"); | ||
subscriberService.subscribeMail(subscribeRequest); | ||
} | ||
|
||
@Operation(summary = "슈퍼유저 - 메일링 서비스") | ||
@GetMapping("/mail") | ||
public void setRecruitingMail() { | ||
log.info("슈퍼유저 - 메일링 서비스"); | ||
subscriberService.sendRecruitingMail(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/ceos/backend/domain/subscriber/domain/Subscriber.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,37 @@ | ||
package ceos.backend.domain.subscriber.domain; | ||
|
||
|
||
import ceos.backend.global.common.entity.BaseEntity; | ||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class Subscriber extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "subscriber_id") | ||
private Long id; | ||
|
||
@NotNull | ||
@Size(max = 255) | ||
private String email; | ||
|
||
// 생성자 | ||
@Builder | ||
private Subscriber(String email) { | ||
this.email = email; | ||
} | ||
|
||
public static Subscriber from(String email) { | ||
return Subscriber.builder() | ||
.email(email) | ||
.build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/ceos/backend/domain/subscriber/dto/request/SubscribeRequest.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,14 @@ | ||
package ceos.backend.domain.subscriber.dto.request; | ||
|
||
|
||
import ceos.backend.global.common.annotation.ValidEmail; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SubscribeRequest { | ||
|
||
@Schema(defaultValue = "[email protected]", description = "이메일") | ||
@ValidEmail | ||
private String email; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ceos/backend/domain/subscriber/exception/DuplicateData.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,13 @@ | ||
package ceos.backend.domain.subscriber.exception; | ||
|
||
|
||
import ceos.backend.global.error.BaseErrorException; | ||
|
||
public class DuplicateData extends BaseErrorException { | ||
|
||
public static final DuplicateData EXCEPTION = new DuplicateData(); | ||
|
||
private DuplicateData() { | ||
super(SubscriberErrorCode.DUPLICATE_DATA); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/ceos/backend/domain/subscriber/exception/InvalidAction.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,13 @@ | ||
package ceos.backend.domain.subscriber.exception; | ||
|
||
|
||
import ceos.backend.global.error.BaseErrorException; | ||
|
||
public class InvalidAction extends BaseErrorException { | ||
|
||
public static final InvalidAction EXCEPTION = new InvalidAction(); | ||
|
||
private InvalidAction() { | ||
super(SubscriberErrorCode.INVALID_ACTION); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/ceos/backend/domain/subscriber/exception/SubscriberErrorCode.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,27 @@ | ||
package ceos.backend.domain.subscriber.exception; | ||
|
||
import ceos.backend.global.common.dto.ErrorReason; | ||
import ceos.backend.global.error.BaseErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SubscriberErrorCode implements BaseErrorCode { | ||
|
||
/* Data */ | ||
INVALID_ACTION(BAD_REQUEST, "SUBSCRIBER_400_1", "리쿠르팅 시작 전입니다."), | ||
DUPLICATE_DATA(CONFLICT, "SUBSCRIBER_409_1", "이미 존재하는 데이터입니다"); | ||
|
||
private HttpStatus status; | ||
private String code; | ||
private String reason; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.of(status.value(), code, reason); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/ceos/backend/domain/subscriber/helper/SubscriberHelper.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,35 @@ | ||
package ceos.backend.domain.subscriber.helper; | ||
|
||
import ceos.backend.domain.subscriber.exception.DuplicateData; | ||
import ceos.backend.domain.subscriber.exception.InvalidAction; | ||
import ceos.backend.domain.subscriber.repository.SubscriberRepository; | ||
import ceos.backend.global.common.dto.AwsSESRecruitMail; | ||
import ceos.backend.global.common.event.Event; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SubscriberHelper { | ||
|
||
private final SubscriberRepository subscriberRepository; | ||
|
||
public void validateEmail(String email) { | ||
if (subscriberRepository.findByEmail(email).isPresent()) { | ||
throw DuplicateData.EXCEPTION; | ||
} | ||
} | ||
|
||
public void validateDate(LocalDate date, LocalDate now) { | ||
if (!date.equals(now)) { | ||
throw InvalidAction.EXCEPTION; | ||
} | ||
} | ||
|
||
public void sendRecruitEmail(String email) { | ||
Event.raise(AwsSESRecruitMail.from(email)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/ceos/backend/domain/subscriber/repository/SubscriberRepository.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 ceos.backend.domain.subscriber.repository; | ||
|
||
|
||
import ceos.backend.domain.subscriber.domain.Subscriber; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface SubscriberRepository extends JpaRepository<Subscriber, Long> { | ||
Optional<Subscriber> findByEmail(String email); | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/ceos/backend/domain/subscriber/service/SubscriberService.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,50 @@ | ||
package ceos.backend.domain.subscriber.service; | ||
|
||
|
||
import ceos.backend.domain.recruitment.repository.RecruitmentRepository; | ||
import ceos.backend.domain.subscriber.domain.Subscriber; | ||
import ceos.backend.domain.subscriber.dto.request.SubscribeRequest; | ||
import ceos.backend.domain.subscriber.helper.SubscriberHelper; | ||
import ceos.backend.domain.subscriber.repository.SubscriberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SubscriberService { | ||
|
||
private final SubscriberHelper subscriberHelper; | ||
private final RecruitmentRepository recruitmentRepository; | ||
private final SubscriberRepository subscriberRepository; | ||
|
||
@Transactional | ||
public void subscribeMail(SubscribeRequest subscribeRequest) { | ||
|
||
//이메일 중복 검증 | ||
subscriberHelper.validateEmail(subscribeRequest.getEmail()); | ||
|
||
Subscriber subscriber = Subscriber.from(subscribeRequest.getEmail()); | ||
subscriberRepository.save(subscriber); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public void sendRecruitingMail() { | ||
LocalDate date = recruitmentRepository.findAll().get(0).getStartDateDoc().toLocalDate(); | ||
LocalDate now = LocalDate.now(); | ||
List<Subscriber> subscribers = subscriberRepository.findAll(); | ||
|
||
//리쿠르팅 시작 날짜 검증 | ||
subscriberHelper.validateDate(date, now); | ||
|
||
// 메일 보내기 | ||
for (Subscriber subscriber : subscribers) { | ||
subscriberHelper.sendRecruitEmail(subscriber.getEmail()); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/ceos/backend/global/common/dto/AwsSESRecruitMail.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,21 @@ | ||
package ceos.backend.global.common.dto; | ||
|
||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class AwsSESRecruitMail { | ||
//수정 예정 -> 이름을 받을 것인가 말 것인가... | ||
private String email; | ||
|
||
@Builder | ||
private AwsSESRecruitMail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public static AwsSESRecruitMail from(String email) { | ||
return AwsSESRecruitMail.builder().email(email) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/ceos/backend/global/common/dto/mail/EmailInfo.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,22 @@ | ||
package ceos.backend.global.common.dto.mail; | ||
|
||
|
||
import ceos.backend.global.common.dto.AwsSESRecruitMail; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class EmailInfo { | ||
private String email; | ||
|
||
@Builder | ||
private EmailInfo(String email) { | ||
this.email = email; | ||
} | ||
|
||
public static EmailInfo from(AwsSESRecruitMail awsSESRecruitMail) { | ||
return EmailInfo.builder() | ||
.email(awsSESRecruitMail.getEmail()) | ||
.build(); | ||
} | ||
} |
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
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,30 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> | ||
<meta content="width=device-width, initial-scale=1.0" name="viewport" /> | ||
</head> | ||
<div th:fragment="passwordInfo(passwordInfo)"> | ||
<div style=" | ||
width: 680px; | ||
"> | ||
<span style=" | ||
text-decoration: none; | ||
outline: 0px; | ||
font-family: Pretendard, AppleSDGothic, apple sd gothic neo, | ||
noto sans korean, noto sans korean regular, noto sans cjk kr, | ||
noto sans cjk, nanum gothic, malgun gothic, dotum, arial, | ||
helvetica, MS Gothic, sans-serif; | ||
font-style: normal; | ||
font-weight: 600; | ||
font-size: 16px; | ||
line-height: 150%; | ||
color: #232527;" | ||
> | ||
세오스 리루르팅 시작 알림 | ||
텍스트추가텍스트추가 | ||
</span> | ||
|
||
<div style="height: 16px; width: 680px"></div> | ||
</div> | ||
</div> | ||
</html> |
Oops, something went wrong.