프로젝트에서 주문 취소시 주문 생성 후 5분 초과시 취소할 수 없게 구현 해야하는 요건이 존재
LocalTime
Duration
Order order = orderRepository.findOneByOrderIdAndDeletedAtIsNull(orderId).orElseThrow(()->{
log.error("주문 정보를 찾을 수 없음");
return new ResponseStatusException(HttpStatus.NOT_FOUND, "주문 정보를 찾을 수 없음");
}
);
LocalDateTime now = LocalDateTime.now()
LocalTime currentTime = now.toLocalTime();
LocalTime createdTime = order.getCreatedAt().toLocalTime();
long diffMin = Duration.between(createdTime, currentTime).isNegative() ?
Duration.between(createdTime, now).plusDays(1).toMinutes() : Duration.between(createdTime, currentTime).toMinutes();
if(diffMin >= 5 || !now.toLocalDate().equals(order.getCreatedAt().toLocalDate())){
log.error("주문 후 5분 초과로 취소 불가");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "주문 후 5분 초과로 취소 불가");
}