Skip to content

Commit

Permalink
Merge pull request #99 from 1223v/sale
Browse files Browse the repository at this point in the history
Feat: Progress.INTEGRATION 대기, 진행 접수 통합 API 기능 추가
  • Loading branch information
1223v authored May 19, 2024
2 parents 2cb9d43 + d8dc16b commit 8520c08
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public class RedisConfig {
@Bean
public RedisConnectionFactory redisConnectionFactory() {

LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(host, port);
log.info("RedisConfig.redisConnectionFactory() called" + lettuceConnectionFactory);
return lettuceConnectionFactory;
return new LettuceConnectionFactory(host, port);
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/readyvery/readyverydemo/domain/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Order extends BaseTimeEntity {
@Column(name = "order_idx")
private Long id;

// 결제 가격
// 토스 결제 가격
@Column
private Long amount;

Expand All @@ -52,7 +52,7 @@ public class Order extends BaseTimeEntity {
@Column
private String orderName;

// 토스 결제 가격
// 결제 가격
@Column
private Long totalAmount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum Progress {
MAKE("MAKE", "음식 제조 중"),
COMPLETE("COMPLETE", "제조 완료"),
PICKUP("PICKUP", "픽업 완료"),
FAIL("FAIL", "주문 실패");
FAIL("FAIL", "주문 실패"),
INTEGRATION("INTEGRATION", "통합 주문");

private final String key;
private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
log.error("응답 작성 중 에러 발생", e);

}
log.info("로그인에 실패했습니다. 메시지: {}", exception.getMessage());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
// RefreshToken까지 보낸 것이므로 리프레시 토큰이 DB의 리프레시 토큰과 일치하는지 판단 후,
// 일치한다면 AccessToken을 재발급해준다.
if (refreshToken != null) {
log.info("refreshToken이 존재합니다.");

checkRefreshTokenAndReIssueAccessToken(response, refreshToken); // 이줄이 문제
return; // RefreshToken을 보낸 경우에는 AccessToken을 재발급 하고 인증 처리는 하지 않게 하기위해 바로 return으로 필터 진행 막기
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void sendAccessAndRefreshToken(HttpServletResponse response, String acces
jwtTokenizer.addAccessRefreshTokenResponseBody(response, accessToken, refreshToken, role);
jwtTokenizer.addAccessTokenCookie(response, accessToken);
jwtTokenizer.addRefreshTokenCookie(response, refreshToken);
log.info("Access Token, Refresh Token 헤더 설정 완료");

}

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ public Optional<String> extractEmail(String accessToken) {
// 토큰 유효성 검사하는 데에 사용할 알고리즘이 있는 JWT verifier builder 반환
return jwtTokenizer.verifyAccessToken(accessToken);
} catch (Exception e) {
log.error("액세스 토큰이 유효하지 않습니다.");

return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
ServletException {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().write("소셜 로그인 실패! 서버 로그를 확인해주세요.");
log.info("소셜 로그인에 실패했습니다. 에러 메시지 : {}", exception.getMessage());

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class OrderController {
})
@GetMapping("/order")
public OrderRegisterRes getOrder(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestParam(required = false) Progress status) {
@RequestParam Progress status) {
return orderServiceImpl.getOrders(userDetails.getId(), status);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ public OrderRegisterRes getOrders(Long id, Progress progress) {
}
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
LocalDateTime endOfDay = startOfDay.plusDays(1).minusNanos(1);
List<Order> orders = orderRepository.findAllByProgressAndStoreIdAndCreatedAtBetween(
progress, ceoInfo.getStore().getId(), startOfDay, endOfDay);

if (orders.isEmpty()) {
return OrderRegisterRes.builder()
.orders(Collections.emptyList())
.build();
if (progress == Progress.INTEGRATION) {
List<Order> waitOrders = orderRepository.findAllByProgressAndStoreIdAndCreatedAtBetween(
Progress.ORDER, ceoInfo.getStore().getId(), startOfDay, endOfDay);
List<Order> makeOrders = orderRepository.findAllByProgressAndStoreIdAndCreatedAtBetween(
Progress.MAKE, ceoInfo.getStore().getId(), startOfDay, endOfDay);

return orderMapper.orderToOrderRegisterRes(ceoInfo.getStore().getId(), waitOrders, makeOrders);
}
return orderMapper.orderToOrderRegisterRes(orders);

List<Order> orders = orderRepository.findAllByProgressAndStoreIdAndCreatedAtBetween(
progress, ceoInfo.getStore().getId(), startOfDay, endOfDay);
return orderMapper.orderToOrderRegisterRes(ceoInfo.getStore().getId(), orders, Collections.emptyList());
}

@Override
Expand Down Expand Up @@ -221,20 +225,69 @@ private TosspaymentDto makeZeroPaymentCancelDto(String rejectReason) {
}

private void verifyPostProgress(Order order, OrderStatusUpdateReq request) {
if (order.getProgress() == Progress.ORDER && request.getStatus() == Progress.MAKE) { // 주문 -> 제조
if (request.getTime() == null) {
throw new BusinessLogicException(ExceptionCode.NOT_FOUND_TIME);
}
order.orderTime(request.getTime());
} else if (order.getProgress() == Progress.ORDER && request.getStatus() == Progress.CANCEL) {
if (request.getRejectReason() == null) {
throw new BusinessLogicException(ExceptionCode.NOT_FOUND_REJECT_REASON);
}
cancelTossPayment(order, request);
} else if (order.getProgress() == Progress.MAKE && request.getStatus() == Progress.COMPLETE) { // 제조 -> 완료
} else if (order.getProgress() == Progress.COMPLETE && request.getStatus() == Progress.PICKUP) { // 완료 -> 픽업
} else {
throw new BusinessLogicException(ExceptionCode.NOT_CHANGE_ORDER);

switch (order.getProgress()) {
case ORDER:
if (request.getStatus() == Progress.MAKE) {
checkEstimatedTime(request.getTime());
order.orderTime(request.getTime());
break;
} else if (request.getStatus() == Progress.CANCEL) {
checkRejectReason(request.getRejectReason());
cancelTossPayment(order, request);
break;
}
case MAKE:
if (request.getStatus() == Progress.COMPLETE) {
break;
}

case COMPLETE:
if (request.getStatus() == Progress.PICKUP) {
break;
}
default:
throw new BusinessLogicException(ExceptionCode.NOT_CHANGE_ORDER);
}

// if (order.getProgress() == Progress.ORDER && request.getStatus() == Progress.MAKE) { // 주문 -> 제조
// if (request.getTime() == null) {
// throw new BusinessLogicException(ExceptionCode.NOT_FOUND_TIME);
// }
// order.orderTime(request.getTime());
// } else if (order.getProgress() == Progress.ORDER && request.getStatus() == Progress.CANCEL) {
// if (request.getRejectReason() == null) {
// throw new BusinessLogicException(ExceptionCode.NOT_FOUND_REJECT_REASON);
// }
// cancelTossPayment(order, request);
// } else if (order.getProgress() == Progress.MAKE && request.getStatus() == Progress.COMPLETE) { // 제조 -> 완료
// } else if (order.getProgress() == Progress.COMPLETE && request.getStatus() == Progress.PICKUP) { // 완료 -> 픽업
// } else {
// throw new BusinessLogicException(ExceptionCode.NOT_CHANGE_ORDER);
// }
}

/**
* 주문 취소시 estimatedTime이 정당한 값인지 확인
*
* @param estimatedTime
* @throws BusinessLogicException
*/
private void checkEstimatedTime(Long estimatedTime) throws BusinessLogicException {
if (estimatedTime == null) {
throw new BusinessLogicException(ExceptionCode.NOT_FOUND_TIME);
}
}

/**
* 주문 취소시 rejectReason이 정당한 값인지 확인
*
* @param rejectReason
* @throws BusinessLogicException
*/
private void checkRejectReason(String rejectReason) throws BusinessLogicException {
if (rejectReason == null) {
throw new BusinessLogicException(ExceptionCode.NOT_FOUND_REJECT_REASON);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.readyvery.readyverydemo.src.order.dto;

import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Component;
Expand All @@ -11,13 +12,19 @@
@Component
public class OrderMapper {

public OrderRegisterRes orderToOrderRegisterRes(List<Order> order) {
if (order.isEmpty()) {
return OrderRegisterRes.builder()
.build();
}
public OrderRegisterRes orderToOrderRegisterRes(Long storeIdx, List<Order> order,
List<Order> integrationMakeOrder) {

List<OrderDto> integratedMakeOrderDtos = integrationMakeOrder.isEmpty() ? Collections.emptyList() :
integrationMakeOrder.stream().map(this::toOrderDto).toList();

List<OrderDto> orderDtos = order.isEmpty() ? Collections.emptyList() :
order.stream().map(this::toOrderDto).toList();

return OrderRegisterRes.builder()
.orders(order.stream().map(this::toOrderDto).toList())
.storeIdx(storeIdx)
.integrationMakeOrders(integratedMakeOrderDtos)
.orders(orderDtos)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
@Getter
@Builder
public class OrderRegisterRes {

private Long storeIdx;
private List<OrderDto> orders;

private List<OrderDto> integrationMakeOrders;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public boolean sendMessage(String to, String from, String content) {
messageService.send(message);
return true;
} catch (NurigoMessageNotReceivedException exception) {
log.error(exception.getFailedMessageList().toString());

return false;
} catch (Exception exception) {
log.error(exception.getMessage());

return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SmsSendRes sendSmsFromSolApi(String phoneNumber, String code) {
.smsMessage("인증번호가 발송되었습니다.")
.build();
} else {
log.error("Message sending failed.");

return SmsSendRes.builder()
.isSuccess(false)
.smsMessage("메시지 발송에 실패하였습니다.")
Expand Down

0 comments on commit 8520c08

Please sign in to comment.