Skip to content

Commit

Permalink
Merge pull request #194 from CEOS-Developers/refact/mail
Browse files Browse the repository at this point in the history
메일링 서비스 리크루팅 기간 내 발송 가능하도록 수정
  • Loading branch information
yoonsseo authored Aug 14, 2024
2 parents a4d12d7 + dcbbaab commit 317c3f6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.

This file was deleted.

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 InvalidActionAfter extends BaseErrorException {

public static final InvalidActionAfter EXCEPTION = new InvalidActionAfter();

private InvalidActionAfter() {
super(SubscriberErrorCode.INVALID_ACTION_AFTER);
}
}
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 InvalidActionBefore extends BaseErrorException {

public static final InvalidActionBefore EXCEPTION = new InvalidActionBefore();

private InvalidActionBefore() {
super(SubscriberErrorCode.INVALID_ACTION_BEFORE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
public enum SubscriberErrorCode implements BaseErrorCode {

/* Data */
INVALID_ACTION(BAD_REQUEST, "SUBSCRIBER_400_1", "리쿠르팅 시작 전입니다."),
INVALID_ACTION_BEFORE(BAD_REQUEST, "SUBSCRIBER_400_1", "리쿠르팅 시작 전입니다."),
INVALID_ACTION_AFTER(BAD_REQUEST, "SUBSCRIBER_400_2", "리쿠르팅 마감 후입니다."),
DUPLICATE_DATA(CONFLICT, "SUBSCRIBER_409_1", "이미 존재하는 데이터입니다");

private HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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.exception.InvalidActionAfter;
import ceos.backend.domain.subscriber.exception.InvalidActionBefore;
import ceos.backend.domain.subscriber.repository.SubscriberRepository;
import ceos.backend.global.common.dto.AwsSESRecruitMail;
import ceos.backend.global.common.event.Event;
Expand All @@ -22,9 +23,11 @@ public void validateEmail(String email) {
}
}

public void validateDate(LocalDate date, LocalDate now) {
if (!date.equals(now)) {
throw InvalidAction.EXCEPTION;
public void validateDate(LocalDate startDate, LocalDate endDate, LocalDate now) {
if (now.isBefore(startDate)) {
throw InvalidActionBefore.EXCEPTION;
} else if (now.isAfter(endDate)) {
throw InvalidActionAfter.EXCEPTION;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ public void subscribeMail(SubscribeRequest subscribeRequest) {

@Transactional(readOnly = true)
public void sendRecruitingMail() {
LocalDate date = recruitmentRepository.findAll().get(0).getStartDateDoc().toLocalDate();
LocalDate startDate = recruitmentRepository.findAll().get(0).getStartDateDoc().toLocalDate();
LocalDate endDate = recruitmentRepository.findAll().get(0).getEndDateDoc().toLocalDate();
LocalDate now = LocalDate.now();
List<Subscriber> subscribers = subscriberRepository.findAll();

//리쿠르팅 시작 날짜 검증
subscriberHelper.validateDate(date, now);
//리쿠르팅 기간 검증
subscriberHelper.validateDate(startDate, endDate, now);

// 메일 보내기
for (Subscriber subscriber : subscribers) {
Expand Down

0 comments on commit 317c3f6

Please sign in to comment.