Skip to content

Commit

Permalink
Batch-v1.0.4
Browse files Browse the repository at this point in the history
Batch-v1.0.4
  • Loading branch information
ImNM authored Mar 23, 2023
2 parents 90aba15 + 67ad16c commit d4d862d
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute(OrderAlimTalkDto orderAlimTalkDto) {
userInfo.getUserName(), eventInfo.getHostName(), eventInfo.getEventName());
String headerContent = OrderKakaoTalkAlarm.creationHeaderOf();

ncpHelper.sendItemNcpAlimTalk(
ncpHelper.sendDoneOrderAlimTalk(
userInfo.getPhoneNum(),
OrderKakaoTalkAlarm.creationTemplateCode(),
content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void execute(OrderAlimTalkDto orderAlimTalkDto) {
userInfo.getUserName(), eventInfo.getHostName(), eventInfo.getEventName());
String headerContent = OrderKakaoTalkAlarm.deletionHeaderOf();

ncpHelper.sendItemButtonNcpAlimTalk(
ncpHelper.sendCancelOrderAlimTalk(
userInfo.getPhoneNum(),
OrderKakaoTalkAlarm.deletionTemplateCode(),
content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.bucket4j.Bucket;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
Expand All @@ -26,17 +28,28 @@ public class ThrottlingInterceptor implements HandlerInterceptor {
private final IPRateLimiter ipRateLimiter;
private final ObjectMapper objectMapper;

@Value("${acl.whiteList}")
private List<String> aclWhiteList;

private final SlackThrottleErrorSender slackThrottleErrorSender;

@Override
public boolean preHandle(
HttpServletRequest request, HttpServletResponse response, Object handler)
throws IOException {
Long userId = SecurityUtils.getCurrentUserId();
String remoteAddr = request.getRemoteAddr();
log.info("remoteAddr : " + remoteAddr);

// next js ssr 대응
if (aclWhiteList.contains(remoteAddr)) {
log.info("white List pass" + remoteAddr);
return true;
}

Bucket bucket;
if (userId == 0L) {
// 익명 유저 ip 기반처리
String remoteAddr = request.getRemoteAddr();
bucket = ipRateLimiter.resolveBucket(remoteAddr);
} else {
// 비 익명 유저 유저 아이디 기반 처리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import band.gosrock.api.common.page.PageResponse;
import band.gosrock.api.order.docs.ApproveOrderExceptionDocs;
import band.gosrock.api.order.docs.CancelOrderExceptionDocs;
import band.gosrock.api.order.model.dto.request.AdminOrderTableQueryRequest;
import band.gosrock.api.order.model.dto.response.OrderAdminTableElement;
import band.gosrock.api.order.model.dto.response.OrderResponse;
import band.gosrock.api.order.service.ApproveOrderUseCase;
import band.gosrock.api.order.service.CancelOrderUseCase;
import band.gosrock.api.order.service.ReadOrderUseCase;
import band.gosrock.common.annotation.ApiErrorExceptionsExample;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -31,6 +33,7 @@ public class OrderAdminController {

private final ApproveOrderUseCase approveOrderUseCase;
private final ReadOrderUseCase readOrderUseCase;
private final CancelOrderUseCase cancelOrderUseCase;

@Operation(summary = "어드민 목록 내 테이블 조회 OrderStage 는 꼭 보내주삼!")
@GetMapping
Expand All @@ -41,6 +44,14 @@ public PageResponse<OrderAdminTableElement> getEventOrders(
return readOrderUseCase.getEventOrders(eventId, adminOrderTableQueryRequest, pageable);
}

@Operation(summary = "결제 취소요청. 호스트 관리자가 결제를 취소 시킵니다.! (호스트 관리자용(관리자쪽에서 사용))")
@ApiErrorExceptionsExample(CancelOrderExceptionDocs.class)
@PostMapping("/{order_uuid}/cancel")
public OrderResponse cancelOrder(
@PathVariable("eventId") Long eventId, @PathVariable("order_uuid") String orderUuid) {
return cancelOrderUseCase.execute(eventId, orderUuid);
}

@Operation(summary = "주문 승인하기 . 호스트 관리자가 티켓 주문을 승인합니다. ( 어드민 이벤트쪽으로 이동예정 )")
@ApiErrorExceptionsExample(ApproveOrderExceptionDocs.class)
@PostMapping("/{order_uuid}/approve")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import band.gosrock.api.common.slice.SliceResponse;
import band.gosrock.api.order.docs.CancelOrderExceptionDocs;
import band.gosrock.api.order.docs.ConfirmOrderExceptionDocs;
import band.gosrock.api.order.docs.CreateOrderExceptionDocs;
import band.gosrock.api.order.docs.FreeOrderExceptionDocs;
Expand All @@ -13,7 +12,6 @@
import band.gosrock.api.order.model.dto.response.OrderBriefElement;
import band.gosrock.api.order.model.dto.response.OrderResponse;
import band.gosrock.api.order.model.dto.response.OrderTicketResponse;
import band.gosrock.api.order.service.CancelOrderUseCase;
import band.gosrock.api.order.service.ConfirmOrderUseCase;
import band.gosrock.api.order.service.CreateOrderUseCase;
import band.gosrock.api.order.service.CreateTossOrderUseCase;
Expand Down Expand Up @@ -49,7 +47,6 @@ public class OrderController {
private final CreateOrderUseCase createOrderUseCase;
private final ConfirmOrderUseCase confirmOrderUseCase;
private final FreeOrderUseCase freeOrderUseCase;
private final CancelOrderUseCase cancelOrderUseCase;

private final RefundOrderUseCase refundOrderUseCase;
private final ReadOrderUseCase readOrderUseCase;
Expand Down Expand Up @@ -87,13 +84,6 @@ public OrderResponse freeOrder(@PathVariable("order_uuid") String orderUuid) {
return freeOrderUseCase.execute(orderUuid);
}

@Operation(summary = "결제 취소요청. 호스트 관리자가 결제를 취소 시킵니다.! (호스트 관리자용(관리자쪽에서 사용))")
@ApiErrorExceptionsExample(CancelOrderExceptionDocs.class)
@PostMapping("/{order_uuid}/cancel")
public OrderResponse cancelOrder(@PathVariable("order_uuid") String orderUuid) {
return cancelOrderUseCase.execute(orderUuid);
}

@Operation(summary = "결제 환불요청. 본인이 구매한 오더를 환불 시킵니다.! (본인 용)")
@ApiErrorExceptionsExample(RefundOrderExceptionDocs.class)
@PostMapping("/{order_uuid}/refund")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class OrderBriefElement {
public static OrderBriefElement of(Order order, Event event, IssuedTickets issuedTickets) {
return OrderBriefElement.builder()
.refundInfo(event.toRefundInfoVoWithOrderStatus(order.getOrderStatus()))
.stage(issuedTickets.getIssuedTicketsStage())
.stage(issuedTickets.getIssuedTicketsStage(event))
.orderUuid(order.getUuid())
.orderNo(order.getOrderNo())
.orderStatus(order.getOrderStatus())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package band.gosrock.api.order.service;

import static band.gosrock.api.common.aop.hostRole.FindHostFrom.EVENT_ID;
import static band.gosrock.api.common.aop.hostRole.HostQualification.MANAGER;

import band.gosrock.api.config.security.SecurityUtils;
import band.gosrock.api.common.aop.hostRole.HostRolesAllowed;
import band.gosrock.api.order.model.dto.response.OrderResponse;
import band.gosrock.api.order.model.mapper.OrderMapper;
import band.gosrock.common.annotation.UseCase;
Expand All @@ -16,9 +18,9 @@ public class CancelOrderUseCase {

private final OrderMapper orderMapper;

public OrderResponse execute(String orderUuid) {
Long currentUserId = SecurityUtils.getCurrentUserId();
withdrawOrderService.cancelOrder(orderUuid, currentUserId);
@HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID, applyTransaction = false)
public OrderResponse execute(Long eventId, String orderUuid) {
withdrawOrderService.cancelOrder(orderUuid);
return orderMapper.toOrderResponse(orderUuid);
}
}
2 changes: 2 additions & 0 deletions DuDoong-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ swagger:
throttle:
overdraft: ${RATE_LIMIT_OVERDRAFT:60}
greedyRefill: ${RATE_LIMIT_REFILL:60}

acl.whiteList : ${ACL_WHITELIST:127.0.0.1,127.0.0.2}
---
spring:
config:
Expand Down
2 changes: 1 addition & 1 deletion DuDoong-Batch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ COPY ./build/libs/*.jar app.jar
ARG PROFILE=dev
ENV PROFILE=${PROFILE}

ENTRYPOINT ["java","-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ENTRYPOINT ["java","-Dspring.profiles.active=${PROFILE}", "-Djava.security.egd=file:/dev/./urandom","-jar","-Duser.timezone=Asia/Seoul","/app.jar"]
1 change: 0 additions & 1 deletion DuDoong-Batch/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ spring:
- common
batch.job.names: ${job.name:NONE}


---
spring:
config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static String creationHeaderOf() {
}

public static String creationTemplateCode() {
return "doneorder";
return "doneorderv2";
}

public static String deletionOf(String userName, String hostName, String eventName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public Object lock(final ProceedingJoinPoint joinPoint) throws Throwable {
try {
rLock.unlock();
} catch (IllegalMonitorStateException e) {
rLock.forceUnlock();
log.error(e + baseKey + dynamicKey);
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public Boolean isPreparing() {
return this.status == PREPARING;
}

public Boolean isClosed() {
return this.status == CLOSED;
}

public void setEventBasic(EventBasic eventBasic) {
this.validateOpenStatus();
this.eventBasic = eventBasic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import band.gosrock.domain.common.vo.IssuedTicketInfoVo;
import band.gosrock.domain.domains.event.domain.Event;
import java.util.List;
import lombok.Getter;

Expand Down Expand Up @@ -35,12 +36,17 @@ public String getTicketNoName() {
else return String.format("%s ~ %s (%d매)", nos.get(0), nos.get(size - 1), size);
}

public IssuedTicketsStage getIssuedTicketsStage() {
public IssuedTicketsStage getIssuedTicketsStage(Event event) {
if (getTotalQuantity() == 0) return IssuedTicketsStage.APPROVE_WAITING;
List<IssuedTicketStatus> issuedTicketStatuses = getIssuedTicketStatuses();
if (isCanceled(issuedTicketStatuses)) {
return IssuedTicketsStage.CANCELED;
}
// 정상 발급된 티켓이 . 지난 공연이라면 지난 공연으로 통일.
if (event.isClosed()) {
return IssuedTicketsStage.PASSED_EVENT;
}

if (isBeforeEntrance(issuedTicketStatuses)) return IssuedTicketsStage.BEFORE_ENTRANCE;
if (isAfterEntrance(issuedTicketStatuses)) return IssuedTicketsStage.AFTER_ENTRANCE;
return IssuedTicketsStage.ENTERING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public enum IssuedTicketsStage {
// 입장중
ENTERING("ENTERING", "입장중"),
// 취소됨
CANCELED("CANCELED", "취소됨");
CANCELED("CANCELED", "취소됨"),

PASSED_EVENT("PASSED_EVENT", "지난공연");
private final String value;

@JsonValue private final String kr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public class WithdrawOrderService {
private final OrderValidator orderValidator;

@RedissonLock(LockName = "주문", identifier = "orderUuid")
public String cancelOrder(String orderUuid, Long userId) {
public String cancelOrder(String orderUuid) {
Order order = orderAdaptor.findByOrderUuid(orderUuid);
// TODO : 관리자 권환으로 치환.
orderValidator.validOwner(order, userId);
order.cancel(orderValidator);
return orderUuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void setUp() {
AtomicLong successCount = new AtomicLong();
// when
CunCurrencyExecutorService.execute(
() -> withdrawOrderService.cancelOrder(order.getUuid(), userId), successCount);
() -> withdrawOrderService.cancelOrder(order.getUuid()), successCount);

assertThat(successCount.get()).isGreaterThanOrEqualTo(1);
}
Expand Down
Loading

0 comments on commit d4d862d

Please sign in to comment.