Skip to content

Commit

Permalink
๐Ÿš€ :: Api-v0.1.2
Browse files Browse the repository at this point in the history
๐Ÿš€ :: Api-v0.1.2
  • Loading branch information
ImNM authored Feb 6, 2023
2 parents 69330b5 + 4e7e56d commit 674d99a
Show file tree
Hide file tree
Showing 62 changed files with 1,939 additions and 2,521 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
Expand Up @@ -37,6 +37,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.permitAll()
.mvcMatchers(HttpMethod.GET, "/v1/events/{eventId:[\\d+]}/ticketItems")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/v1/coupons/campaigns")
.hasRole("SUPER_ADMIN")
.anyRequest()
.authenticated();
http.apply(filterConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import band.gosrock.domain.domains.coupon.domain.*;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import javax.validation.constraints.*;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.Nullable;
Expand All @@ -17,9 +14,6 @@
@RequiredArgsConstructor
public class CreateCouponCampaignRequest {

@NotNull(message = "host Id๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
private Long hostId;

@NotNull(message = "discountType์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
private DiscountType discountType;

Expand Down Expand Up @@ -54,4 +48,9 @@ public class CreateCouponCampaignRequest {

@NotBlank(message = "couponCode๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
private String couponCode;

@Schema(description = "์ฟ ํฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ตœ์†Œ ๊ฒฐ์ œ ๊ธˆ์•ก(์›๋‹จ์œ„, 10000์› ์ด์ƒ๋ถ€ํ„ฐ ์ž…๋ ฅ ๊ฐ€๋Šฅ)")
@NotNull(message = "minimumCost(์› ๋‹จ์œ„)๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
@Min(value = 10000, message = "10000์› ์ด์ƒ๋ถ€ํ„ฐ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.")
private Long minimumCost;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public record CreateCouponCampaignResponse(
@Schema(description = "์ฟ ํฐ ์บ ํŽ˜์ธ ID") Long couponCampaignId,
@Schema(description = "์ฟ ํฐ ์ฝ”๋“œ") String couponCode,
@Schema(description = "์ƒ์„ฑํ•œ ์ฟ ํฐ ์ด ๋งค์ˆ˜") Long issuedAmount,
@Schema(description = "์ฟ ํฐ ์ƒ์„ฑํ•œ ํ˜ธ์ŠคํŠธ ID") Long hostId) {}
@Schema(description = "์ฟ ํฐ ์ƒ์„ฑํ•œ ์Šˆํผ ์–ด๋“œ๋ฏผ user ID") Long userId) {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
public class CouponCampaignMapper {

public static CreateCouponCampaignResponse toCreateCouponCampaignResponse(
CouponCampaign couponCampaign, Long hostId) {
CouponCampaign couponCampaign, Long userId) {
return CreateCouponCampaignResponse.builder()
.couponCampaignId(couponCampaign.getId())
.couponCode(couponCampaign.getCouponCode())
.issuedAmount(couponCampaign.getCouponStockInfo().getIssuedAmount())
.hostId(hostId)
.userId(userId)
.build();
}

Expand All @@ -35,7 +35,8 @@ public static DateTimePeriod toDateTimePeriod(LocalDateTime startAt, LocalDateTi
return DateTimePeriod.builder().startAt(startAt).endAt(endAt).build();
}

public CouponCampaign toEntity(CreateCouponCampaignRequest createCouponCampaignRequest) {
public CouponCampaign toEntity(
CreateCouponCampaignRequest createCouponCampaignRequest, Long userId) {

CouponStockInfo couponStockInfo =
toCouponStockInfo(createCouponCampaignRequest.getIssuedAmount());
Expand All @@ -45,14 +46,15 @@ public CouponCampaign toEntity(CreateCouponCampaignRequest createCouponCampaignR
createCouponCampaignRequest.getEndAt());

return CouponCampaign.builder()
.hostId(createCouponCampaignRequest.getHostId())
.userId(userId)
.discountType(createCouponCampaignRequest.getDiscountType())
.applyTarget(createCouponCampaignRequest.getApplyTarget())
.validTerm(createCouponCampaignRequest.getValidTerm())
.dateTimePeriod(dateTimePeriod)
.couponStockInfo(couponStockInfo)
.discountAmount(createCouponCampaignRequest.getDiscountAmount())
.couponCode(createCouponCampaignRequest.getCouponCode())
.minimumCost(createCouponCampaignRequest.getMinimumCost())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@ public CreateCouponCampaignResponse execute(
CreateCouponCampaignRequest createCouponCampaignRequest) {
// ์กด์žฌํ•˜๋Š” ์œ ์ €์ธ์ง€ ๊ฒ€์ฆ
User user = userUtils.getCurrentUser();
// ์Šˆํผ ํ˜ธ์ŠคํŠธ์ธ์ง€ ๊ฒ€์ฆ
hostService.validateManagerHostUser(createCouponCampaignRequest.getHostId(), user.getId());
// ์ด๋ฏธ ์ƒ์„ฑ๋œ ์ฟ ํฐ ์ฝ”๋“œ์ธ์ง€ ๊ฒ€์ฆ
createCouponCampaignDomainService.checkCouponCodeExists(
createCouponCampaignRequest.getCouponCode());
// ์ฟ ํฐ ์ƒ์„ฑ
CouponCampaign couponCampaign =
createCouponCampaignDomainService.createCouponCampaign(
couponCampaignMapper.toEntity(createCouponCampaignRequest));
return CouponCampaignMapper.toCreateCouponCampaignResponse(
couponCampaign, couponCampaign.getHostId());
couponCampaignMapper.toEntity(createCouponCampaignRequest, user.getId()));
return CouponCampaignMapper.toCreateCouponCampaignResponse(couponCampaign, user.getId());
}
}

This file was deleted.

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);
}
}
Loading

0 comments on commit 674d99a

Please sign in to comment.