Skip to content

Commit

Permalink
feature : 주문 관련, 호스트 초대 이메일 알림 전송 (#297)
Browse files Browse the repository at this point in the history
* feat : footer 추가

* feat : 레이아웃 추가

* feat : 회원가입 포맷 만들기

* refactor : fragments 리팩터링

* refactor : mailFormat 리팩터링

* refactor : 마진값 조정

* feat : 타이틀 컴포넌트 생성

* refactor : 구조 잡기

* feat : 주문 승인 요청 메일 폼

* feat : 주문 승인 요청 알림

* feat : 승인 주문 생성시 이메일 알림

* style : spotless

* feat : 주문관련, 호스트 초대이메일 알림 포맷 완료

* feat : 각 도메인 이벤트 핸들링

* feat : 호스트 초대 이메일 알림

* style : spotless

* fix : 필터 순서 재조정
  • Loading branch information
ImNM authored Feb 6, 2023
1 parent 12bd4aa commit 4e7e56d
Show file tree
Hide file tree
Showing 41 changed files with 1,821 additions and 2,456 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.ForwardedHeaderFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;

@Configuration
@RequiredArgsConstructor
Expand All @@ -25,11 +26,19 @@ public FilterRegistrationBean securityFilterChain(
@Qualifier(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME)
Filter securityFilter) {
FilterRegistrationBean registration = new FilterRegistrationBean(securityFilter);
registration.setOrder(Integer.MAX_VALUE - 2);
registration.setOrder(Integer.MAX_VALUE - 3);
registration.setName(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME);
return registration;
}

@Bean
public FilterRegistrationBean setResourceUrlEncodingFilter() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new ResourceUrlEncodingFilter());
registrationBean.setOrder(Integer.MAX_VALUE - 2);
return registrationBean;
}

@Bean
public FilterRegistrationBean setForwardedHeaderFilterOrder() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package band.gosrock.api.email.dto;


import band.gosrock.infrastructure.config.mail.dto.EmailEventInfo;
import band.gosrock.infrastructure.config.mail.dto.EmailOrderInfo;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class OrderMailDto {
private final EmailUserInfo userInfo;
private final EmailOrderInfo orderInfo;
private final EmailEventInfo eventInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package band.gosrock.api.email.handler;


import band.gosrock.api.email.service.OrderApproveRequestEmailService;
import band.gosrock.api.email.service.OrderMailInfoHelper;
import band.gosrock.domain.common.events.order.CreateOrderEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
@Slf4j
public class CreateOrderEventEmailHandler {

private final OrderApproveRequestEmailService orderApproveRequestEmailService;

private final OrderMailInfoHelper orderMailInfoHelper;

@Async
@TransactionalEventListener(
classes = CreateOrderEvent.class,
phase = TransactionPhase.AFTER_COMMIT)
public void handleDoneOrderFailEvent(CreateOrderEvent createOrderEvent) {
log.info(createOrderEvent.getOrderUuid() + "주문 생성 이메일 요청");

// 승인 주문만 생성시에 이메일을 보낸다.
if (createOrderEvent.getOrderMethod().isPayment()) {
return;
}

orderApproveRequestEmailService.execute(
orderMailInfoHelper.execute(createOrderEvent.getOrderUuid()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package band.gosrock.api.email.handler;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.api.email.service.OrderApproveConfirmEmailService;
import band.gosrock.api.email.service.OrderMailInfoHelper;
import band.gosrock.api.email.service.OrderPaymentDoneEmailService;
import band.gosrock.domain.common.events.order.DoneOrderEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
@Slf4j
public class DoneOrderEventEmailHandler {

private final OrderMailInfoHelper orderMailInfoHelper;

private final OrderApproveConfirmEmailService orderApproveConfirmEmailService;
private final OrderPaymentDoneEmailService orderPaymentDoneEmailService;

@Async
@TransactionalEventListener(
classes = DoneOrderEvent.class,
phase = TransactionPhase.AFTER_COMMIT)
public void handleDoneOrderEvent(DoneOrderEvent doneOrderEvent) {
log.info(doneOrderEvent.getOrderUuid() + "주문 상태 완료, 이메일 보내기");
OrderMailDto orderMailDto = orderMailInfoHelper.execute(doneOrderEvent.getOrderUuid());

// 결제용
if (doneOrderEvent.getOrderMethod().isPayment()) {
orderPaymentDoneEmailService.execute(orderMailDto);
return;
}
// 승인용
orderApproveConfirmEmailService.execute(orderMailDto);
log.info(doneOrderEvent.getOrderUuid() + "주문 상태 완료, 이메일 보내기 완료");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class RegisterUserEventHandler {
public class RegisterUserEventEmailHandler {

private final UserAdaptor userAdaptor;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package band.gosrock.api.email.handler;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.api.email.service.OrderMailInfoHelper;
import band.gosrock.api.email.service.OrderWithDrawCancelEmailService;
import band.gosrock.api.email.service.OrderWithDrawRefundEmailService;
import band.gosrock.domain.common.events.order.WithDrawOrderEvent;
import band.gosrock.domain.domains.order.domain.OrderStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
@Slf4j
public class WithDrawOrderEventEmailHandler {

private final OrderWithDrawRefundEmailService orderWithDrawRefundEmailService;
private final OrderWithDrawCancelEmailService orderWithDrawCancelEmailService;
private final OrderMailInfoHelper orderMailInfoHelper;

@Async
@TransactionalEventListener(
classes = WithDrawOrderEvent.class,
phase = TransactionPhase.AFTER_COMMIT)
public void handleWithDrawOrderEvent(WithDrawOrderEvent withDrawOrderEvent) {
OrderStatus orderStatus = withDrawOrderEvent.getOrderStatus();
OrderMailDto orderMailDto = orderMailInfoHelper.execute(withDrawOrderEvent.getOrderUuid());

// 관리자에 의한 취소
if (orderStatus == OrderStatus.CANCELED) {
orderWithDrawCancelEmailService.execute(orderMailDto);
return;
}
// 구매자에의한 환불 요청
orderWithDrawRefundEmailService.execute(orderMailDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package band.gosrock.api.email.service;


import band.gosrock.domain.domains.host.domain.HostRole;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class HostInviteEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(EmailUserInfo userInfo, String hostName, HostRole hostRole) {
Context context = new Context();
context.setVariable("userInfo", userInfo);
context.setVariable("hostName", hostName);
context.setVariable("role", hostRole.getValue());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥" + hostName + " 호스트 초대 알림 드립니다.", "hostInvite", context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class OrderApproveConfirmEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(OrderMailDto orderMailDto) {
Context context = new Context();
EmailUserInfo userInfo = orderMailDto.getUserInfo();
context.setVariable("userInfo", userInfo);
context.setVariable("orderInfo", orderMailDto.getOrderInfo());
context.setVariable("eventInfo", orderMailDto.getEventInfo());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥 주문승인 완료 알림드립니다.", "orderApproveConfirm", context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class OrderApproveRequestEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(OrderMailDto orderMailDto) {
Context context = new Context();
EmailUserInfo userInfo = orderMailDto.getUserInfo();
context.setVariable("userInfo", userInfo);
context.setVariable("orderInfo", orderMailDto.getOrderInfo());
context.setVariable("eventInfo", orderMailDto.getEventInfo());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥 주문승인 요청 알림드립니다.", "orderApproveRequest", context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.common.annotation.Helper;
import band.gosrock.domain.domains.event.adaptor.EventAdaptor;
import band.gosrock.domain.domains.event.domain.Event;
import band.gosrock.domain.domains.host.adaptor.HostAdaptor;
import band.gosrock.domain.domains.host.domain.Host;
import band.gosrock.domain.domains.order.adaptor.OrderAdaptor;
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import band.gosrock.domain.domains.user.domain.User;
import band.gosrock.infrastructure.config.mail.dto.EmailEventInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@Helper
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class OrderMailInfoHelper {
private final OrderAdaptor orderAdaptor;
private final UserAdaptor userAdaptor;
private final EventAdaptor eventAdaptor;
private final HostAdaptor hostAdaptor;

public OrderMailDto execute(String orderUuid) {
Order order = orderAdaptor.find(orderUuid);
User user = userAdaptor.queryUser(order.getUserId());
Event event = eventAdaptor.findById(order.getEventId());
Host host = hostAdaptor.findById(event.getHostId());
return new OrderMailDto(
user.toEmailUserInfo(), order.toEmailOrderInfo(), getEventInfo(event, host));
}

private EmailEventInfo getEventInfo(Event event, Host host) {
return new EmailEventInfo(host.getProfile().getName(), event.getEventBasic().getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class OrderPaymentDoneEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(OrderMailDto orderMailDto) {
Context context = new Context();
EmailUserInfo userInfo = orderMailDto.getUserInfo();
context.setVariable("userInfo", userInfo);
context.setVariable("orderInfo", orderMailDto.getOrderInfo());
context.setVariable("eventInfo", orderMailDto.getEventInfo());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥 주문 완료 알림드립니다.", "orderPaymentDone", context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class OrderWithDrawCancelEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(OrderMailDto orderMailDto) {
Context context = new Context();
EmailUserInfo userInfo = orderMailDto.getUserInfo();
context.setVariable("userInfo", userInfo);
context.setVariable("orderInfo", orderMailDto.getOrderInfo());
context.setVariable("eventInfo", orderMailDto.getEventInfo());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥 주문 철회 알림 드립니다.", "orderWithdrawCancel", context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package band.gosrock.api.email.service;


import band.gosrock.api.email.dto.OrderMailDto;
import band.gosrock.infrastructure.config.mail.dto.EmailUserInfo;
import band.gosrock.infrastructure.config.ses.AwsSesUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;

@Service
@RequiredArgsConstructor
public class OrderWithDrawRefundEmailService {
private final AwsSesUtils awsSesUtils;

public void execute(OrderMailDto orderMailDto) {
Context context = new Context();
EmailUserInfo userInfo = orderMailDto.getUserInfo();
context.setVariable("userInfo", userInfo);
context.setVariable("orderInfo", orderMailDto.getOrderInfo());
context.setVariable("eventInfo", orderMailDto.getEventInfo());
awsSesUtils.singleEmailRequest(
userInfo.getEmail(), "두둥 주문 철회 알림 드립니다.", "orderWithdrawRefund", context);
}
}
Loading

0 comments on commit 4e7e56d

Please sign in to comment.