-
Notifications
You must be signed in to change notification settings - Fork 2
[REFACTOR] 주문 내부 API 사용 수정 및 페이징 기능 추가 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kim-jun-won
wants to merge
11
commits into
develop
Choose a base branch
from
#41/refactor-order-connectFegin
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cdc7187
feature(order) : paging, sort 기능 추가
kim-jun-won 2aed57a
feature(order) : FeignClient 기반 내부 통신 구현
kim-jun-won 04e2832
fix(order) : orderIntegrationTest 코드 설정 수정
kim-jun-won 6c3a285
fix(order) : 배송 요청 생성 시 배송요구사항(requestNote) field 추가
kim-jun-won d742604
fix(order) : 주문 생성 이벤트에 사용자ID(ordererId) 추가
kim-jun-won 30d23db
Merge branch 'develop' into #41/refactor-order-connectFegin
kim-jun-won 02ab6d6
refactor(order) : 주문 API 인가처리 추가
kim-jun-won ee14537
Merge branch 'develop' into #41/refactor-order-connectFegin
kim-jun-won 4161d40
fix(order) : 주문생성 event에 배송지 주소 추가
kim-jun-won 5d94a32
fix(order) : feign-client retry예외 unwrapping 전략 추가
kim-jun-won 68d3471
Merge branch 'develop' into #41/refactor-order-connectFegin
kim-jun-won File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...service/src/main/java/com/shipflow/orderservice/application/dto/OrderSearchCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.shipflow.orderservice.application.dto; | ||
|
|
||
| import com.shipflow.orderservice.domain.model.OrderStatus; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| public record OrderSearchCondition( | ||
| OrderStatus status, | ||
| UUID ordererId, | ||
| UUID productId, | ||
| UUID supplierCompanyId, | ||
| UUID receiverCompanyId, | ||
| LocalDateTime createdFrom, | ||
| LocalDateTime createdTo | ||
| ) { | ||
| public OrderSearchCondition withOrdererId(UUID forcedOrdererId) { | ||
| return new OrderSearchCondition(status, forcedOrdererId, productId, | ||
| supplierCompanyId, receiverCompanyId, createdFrom, createdTo); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...ervice/src/main/java/com/shipflow/orderservice/application/service/OrderFetchService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package com.shipflow.orderservice.application.service; | ||
|
|
||
| import com.shipflow.orderservice.application.dto.CreateOrderCommand; | ||
| import com.shipflow.orderservice.infrastructure.client.adapter.CompanyClientAdapter; | ||
| import com.shipflow.orderservice.infrastructure.client.adapter.ProductClientAdapter; | ||
| import com.shipflow.orderservice.infrastructure.client.adapter.UserClientAdapter; | ||
| import com.shipflow.orderservice.infrastructure.client.dto.ProductInfo; | ||
| import com.shipflow.orderservice.infrastructure.client.dto.ReceiverCompanyInfo; | ||
| import com.shipflow.orderservice.infrastructure.client.dto.UserInfo; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.CompletionException; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class OrderFetchService { | ||
|
|
||
| private final ProductClientAdapter productAdapter; | ||
| private final UserClientAdapter userAdapter; | ||
| private final CompanyClientAdapter companyAdapter; | ||
|
|
||
| public CreateOrderCommand fetchAndBuild(UUID ordererId, UUID productId, | ||
| int quantity, LocalDateTime deadline, String note) { | ||
| // Step 1: product, user 병렬 호출 | ||
| CompletableFuture<ProductInfo> productFuture = CompletableFuture.supplyAsync( | ||
| () -> productAdapter.fetch(ordererId.toString(), productId, quantity)); | ||
| CompletableFuture<UserInfo> userFuture = CompletableFuture.supplyAsync( | ||
| () -> userAdapter.fetch(ordererId)); | ||
|
|
||
| try { | ||
| CompletableFuture.allOf(productFuture, userFuture).join(); | ||
| } catch (CompletionException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause instanceof RuntimeException re) { | ||
| throw re; | ||
| } | ||
| if (cause instanceof Error err) { | ||
| throw err; | ||
| } | ||
| throw e; | ||
| } | ||
|
|
||
| ProductInfo product = productFuture.join(); | ||
| UserInfo user = userFuture.join(); | ||
|
kim-jun-won marked this conversation as resolved.
|
||
|
|
||
| // Step 2: receiverCompanyId 확보 후 company 호출 | ||
| ReceiverCompanyInfo company = companyAdapter.fetch(user.receiverCompanyId()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🛡️ null 검증 추가 제안 ProductInfo product = productFuture.join();
UserInfo user = userFuture.join();
// Step 2: receiverCompanyId 확보 후 company 호출
+ UUID receiverCompanyId = user.receiverCompanyId();
+ if (receiverCompanyId == null) {
+ throw new IllegalStateException("User의 receiverCompanyId가 설정되지 않았습니다: " + ordererId);
+ }
- ReceiverCompanyInfo company = companyAdapter.fetch(user.receiverCompanyId());
+ ReceiverCompanyInfo company = companyAdapter.fetch(receiverCompanyId);🤖 Prompt for AI Agents |
||
|
|
||
| return new CreateOrderCommand( | ||
| ordererId, | ||
| user.ordererName(), | ||
| productId, | ||
| product.productName(), | ||
| product.supplierCompanyId(), | ||
| product.supplierCompanyName(), | ||
| user.receiverCompanyId(), | ||
| company.companyName(), | ||
| product.departureHubId(), | ||
| company.hubId(), | ||
| quantity, | ||
| deadline, | ||
| note, | ||
| company.address() | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ce/src/main/java/com/shipflow/orderservice/domain/exception/CompanyNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class CompanyNotFoundException extends BusinessException { | ||
|
|
||
| public CompanyNotFoundException() { | ||
| super(OrderErrorCode.COMPANY_NOT_FOUND); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...ce/src/main/java/com/shipflow/orderservice/domain/exception/ExternalServiceException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class ExternalServiceException extends BusinessException { | ||
|
|
||
| public ExternalServiceException(Throwable cause) { | ||
| super(OrderErrorCode.EXTERNAL_SERVICE_ERROR, cause); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
.../src/main/java/com/shipflow/orderservice/domain/exception/InsufficientStockException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class InsufficientStockException extends BusinessException { | ||
|
|
||
| public InsufficientStockException() { | ||
| super(OrderErrorCode.PRODUCT_INSUFFICIENT_STOCK); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ce/src/main/java/com/shipflow/orderservice/domain/exception/ProductNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class ProductNotFoundException extends BusinessException { | ||
|
|
||
| public ProductNotFoundException() { | ||
| super(OrderErrorCode.PRODUCT_NOT_FOUND); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...rvice/src/main/java/com/shipflow/orderservice/domain/exception/UnauthorizedException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class UnauthorizedException extends BusinessException { | ||
|
|
||
| public UnauthorizedException() { | ||
| super(OrderErrorCode.UNAUTHORIZED); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...rvice/src/main/java/com/shipflow/orderservice/domain/exception/UserNotFoundException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.shipflow.orderservice.domain.exception; | ||
|
|
||
| import com.shipflow.common.exception.BusinessException; | ||
|
|
||
| public class UserNotFoundException extends BusinessException { | ||
|
|
||
| public UserNotFoundException() { | ||
| super(OrderErrorCode.USER_NOT_FOUND); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In Spring, does class-level@transactionalwrap the entire public method body, including Feign/HTTP calls made before the repository save, and are external network calls inside a transaction considered bad practice?💡 Result:
Yes—if the call enters through the Spring transactional proxy, a class-level
@Transactionalapplies to each eligible method (typically public methods) and the transaction advice runs around the entire method invocation (begin before the method body executes, commit/rollback after it returns/throws). In Spring’s default proxy mode, only external calls through the proxy are intercepted (self-invocation won’t trigger the interceptor), but once you’re inside the proxied method, everything you do in that method (including Feign/HTTP calls made beforerepository.save(...)) executes while the transaction is active. [1]That said, the Feign/HTTP call is not part of the database transaction (it can’t be atomically committed/rolled back with your DB work), and Spring explicitly notes it does not propagate transaction contexts across remote calls. [2]
Putting external network calls inside a DB transaction is generally considered bad practice because it can make transactions long-running (holding connections/locks longer, increasing contention/timeouts/deadlock risk). Common guidance is to keep transactions short and avoid I/O/remote calls inside them. [3]
Sources:
[1] Spring Framework Reference (Transaction Management) – proxy mode / external calls intercepted
[2] Spring Framework Data Access reference – no transaction context propagation across remote calls
[3] Best-practices guidance (keep transactions short; avoid I/O/remote calls inside transactions)
🏁 Script executed:
Repository: Ship-Flow/ship-flow
Length of output: 163
🏁 Script executed:
cat -n ./order-service/src/main/java/com/shipflow/orderservice/application/service/OrderCommandService.java | head -60Repository: Ship-Flow/ship-flow
Length of output: 3318
🏁 Script executed:
Repository: Ship-Flow/ship-flow
Length of output: 98
🏁 Script executed:
cat -n ./order-service/src/main/java/com/shipflow/orderservice/application/service/OrderFetchService.java | head -100Repository: Ship-Flow/ship-flow
Length of output: 2809
외부 조회를 트랜잭션 범위 밖으로 이동하세요.
클래스 레벨
@Transactional으로 인해createOrder()메서드 전체가 하나의 데이터베이스 트랜잭션으로 실행됩니다. 현재 코드는orderFetchService.fetchAndBuild()메서드에서 Product, User, Company 서비스로의 Feign 호출 3회를 모두 트랜잭션 내에서 수행한 후 저장하므로, 네트워크 대기 시간이 트랜잭션을 장시간 점유합니다. 이로 인해 데이터베이스 연결이 오래 유지되어 잠금 경합, 타임아웃, 데드락 위험이 증가합니다.외부 조회는 트랜잭션 밖에서 완료하고, 데이터베이스 저장과 이벤트 발행만 별도 트랜잭션으로 감싸도록 구조를 개선하세요.
🤖 Prompt for AI Agents