Conversation
📝 WalkthroughWalkthrough주막 주문 도메인이 추가됩니다: 주문 엔티티(수량 포함), 저장소, 커맨드/쿼리 응용서비스, 컨트롤러, 요청/응답 DTO들, 예외 코드 및 .gitignore 패턴이 추가되어 주문 생성·조회·삭제 흐름을 구현합니다. Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant CmdCtrl as PubOrderCommandController
participant CmdSvc as PubOrderCommandService
participant TableQS as PubTableSessionQueryService
participant MenuQS as PubMenuQueryService
participant OrderRepo as PubOrderRepository
participant DB as Database
Client->>CmdCtrl: POST /admin/v1/pubOrder\nPubOrderRequestDto
CmdCtrl->>CmdSvc: createOrder(request)
CmdSvc->>TableQS: findByPubTableSessionId(sessionId)
TableQS-->>CmdSvc: PubTableSession
loop each orderMenu
CmdSvc->>MenuQS: findPubMenuById(menuId)
MenuQS-->>CmdSvc: PubMenu
CmdSvc->>OrderRepo: save(PubOrder with quantity)
OrderRepo->>DB: INSERT pub_order
DB-->>OrderRepo: persisted PubOrder
end
CmdSvc-->>CmdCtrl: PubOrderResponseDto
CmdCtrl-->>Client: 200 OK
Client->>CmdCtrl: GET /admin/v1/pubOrder/{sessionId}
CmdCtrl->>PubOrderQueryService: getAllByPubTableSessionId(sessionId)
PubOrderQueryService->>OrderRepo: findAllByPubTableSessionId(sessionId)
OrderRepo->>DB: SELECT *
DB-->>OrderRepo: List<PubOrder>
loop each pubOrder
PubOrderQueryService->>MenuQS: findPubMenuById(menuId)
MenuQS-->>PubOrderQueryService: PubMenu
end
PubOrderQueryService-->>CmdCtrl: PubOrderResponseDto (mapped)
CmdCtrl-->>Client: 200 OK
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderCommandController.java (2)
23-26: POST 요청 시201 Created반환 권장리소스 생성 시 REST 규약에 따라
200 OK대신201 Created를 반환하는 것이 더 적절합니다.♻️ HTTP 상태 코드 개선
`@PostMapping` public ResponseEntity<PubOrderResponseDto> createOrder(`@Valid` `@RequestBody` PubOrderRequestDto request) { - return ResponseEntity.ok().body(pubOrderCommandService.createOrder(request)); + return ResponseEntity.status(HttpStatus.CREATED).body(pubOrderCommandService.createOrder(request)); }
HttpStatusimport 추가 필요:import org.springframework.http.HttpStatus;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderCommandController.java` around lines 23 - 26, Change the createOrder handler in PubOrderCommandController to return 201 Created instead of 200 by using ResponseEntity.status(HttpStatus.CREATED).body(pubOrderCommandService.createOrder(request)); ensure the HttpStatus import (org.springframework.http.HttpStatus) is added to the file so the reference resolves; keep the existing call to pubOrderCommandService.createOrder(request) unchanged.
28-32: DELETE 요청 시204 No Content반환 권장삭제 성공 시 응답 본문이 없으므로
200 OK대신204 No Content가 더 적절합니다.AdminPubBoothController의delete메서드에서도noContent()를 사용하고 있어 일관성 측면에서도 권장됩니다.♻️ HTTP 상태 코드 개선
`@DeleteMapping`("/{pubOrderId}") public ResponseEntity<Void> deleteOrder(`@PathVariable`("pubOrderId") Long pubOrderId) { pubOrderCommandService.deleteOrder(pubOrderId); - return ResponseEntity.ok().build(); + return ResponseEntity.noContent().build(); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderCommandController.java` around lines 28 - 32, The deleteOrder method in PubOrderCommandController currently returns 200 OK; change it to return 204 No Content by replacing the ResponseEntity.ok().build() with ResponseEntity.noContent().build() in the deleteOrder(`@PathVariable`("pubOrderId") Long pubOrderId) method and keep invoking pubOrderCommandService.deleteOrder(pubOrderId) as-is to maintain behavior consistent with AdminPubBoothController's delete pattern.src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderQueryController.java (1)
12-22: LGTM!쿼리 컨트롤러가 깔끔하게 구현되어 있습니다. 단, Line 21에
ResponseEntity.ok()앞에 공백이 두 개 있는 사소한 포맷팅 이슈가 있습니다.- return ResponseEntity.ok(pubOrderQueryService.getAllByPubTableSessionId(pubTableSessionId)); + return ResponseEntity.ok(pubOrderQueryService.getAllByPubTableSessionId(pubTableSessionId));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderQueryController.java` around lines 12 - 22, There is an extra double space before the ResponseEntity.ok() call in the getAllByPubTableSessionId method of PubOrderQueryController; remove the extra space so the return statement is formatted consistently (locate the getAllByPubTableSessionId method in class PubOrderQueryController and adjust the spacing before ResponseEntity.ok(...)).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/kr/co/knuserver/application/pubOrder/PubOrderCommandService.java`:
- Around line 29-42: In createOrder, avoid the N+1 by collecting menu IDs from
request.orderMenus() after saving pubOrders, call a batch fetch (add
PubMenuQueryService.findAllByIds(List<Long> ids) or use
pubMenuRepository.findAllById(ids)) to retrieve all PubMenu entities in one
query, build a Map<Long,PubMenu> keyed by menuId, then map savedPubOrders to
OrderedMenus using the map instead of calling
pubMenuQueryService.findPubMenuById for each PubOrder; update createOrder to use
the batch method and preserve usage of PubOrder.createPubOrder and
pubOrderRepository.saveAll.
In
`@src/main/java/kr/co/knuserver/application/pubOrder/PubOrderQueryService.java`:
- Around line 30-34: 현재 pubOrderList 스트림에서 각 PubOrder마다
pubMenuQueryService.findPubMenuById를 호출해 N+1 문제가 발생합니다; pubOrderList에서 모든
pubMenuId를 수집한 뒤 한 번에 메뉴들을 조회하고 ID->PubMenu 맵을 만든 다음 OrderedMenus.fromEntity를
호출할 때 맵에서 해당 메뉴를 꺼내 사용하도록 변경하세요 (참고 심볼:
pubOrderRepository.findAllByPubTableSessionId,
pubMenuQueryService.findPubMenuById, OrderedMenus.fromEntity, pubOrderList). 만약
bulk 조회 메서드(예: findPubMenusByIds or findAllByIdIn)가 없다면 pubMenuQueryService 또는
레포지토리에 추가해 한 번에 조회하도록 구현하고 기존 per-order 호출을 대체하세요.
In `@src/main/java/kr/co/knuserver/domain/pubOrder/entity/PubOrder.java`:
- Around line 36-41: The createPubOrder factory currently allows
null/zero/negative quantities which can create invalid orders; update
PubOrder.createPubOrder to validate the quantity (e.g., check not null and
quantity > 0) and throw a clear runtime exception (IllegalArgumentException or a
domain-specific exception) when the check fails, then only call
PubOrder.builder()...build() with a verified quantity; reference the
createPubOrder method and the PubOrder builder in your change so all invalid
inputs are blocked at creation time.
In
`@src/main/java/kr/co/knuserver/presentation/pubOrder/dto/PubOrderRequestDto.java`:
- Line 8: In PubOrderRequestDto change the orderMenus declaration to enforce
non-empty and cascade validation: replace the `@NotNull` on the orderMenus field
with `@NotEmpty` and annotate the list elements with `@Valid` (i.e., use List<@Valid
OrderMenus> orderMenus), and add the necessary imports for
javax.validation.Valid and javax.validation.constraints.NotEmpty so nested
OrderMenus field constraints are propagated.
---
Nitpick comments:
In
`@src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderCommandController.java`:
- Around line 23-26: Change the createOrder handler in PubOrderCommandController
to return 201 Created instead of 200 by using
ResponseEntity.status(HttpStatus.CREATED).body(pubOrderCommandService.createOrder(request));
ensure the HttpStatus import (org.springframework.http.HttpStatus) is added to
the file so the reference resolves; keep the existing call to
pubOrderCommandService.createOrder(request) unchanged.
- Around line 28-32: The deleteOrder method in PubOrderCommandController
currently returns 200 OK; change it to return 204 No Content by replacing the
ResponseEntity.ok().build() with ResponseEntity.noContent().build() in the
deleteOrder(`@PathVariable`("pubOrderId") Long pubOrderId) method and keep
invoking pubOrderCommandService.deleteOrder(pubOrderId) as-is to maintain
behavior consistent with AdminPubBoothController's delete pattern.
In
`@src/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderQueryController.java`:
- Around line 12-22: There is an extra double space before the
ResponseEntity.ok() call in the getAllByPubTableSessionId method of
PubOrderQueryController; remove the extra space so the return statement is
formatted consistently (locate the getAllByPubTableSessionId method in class
PubOrderQueryController and adjust the spacing before ResponseEntity.ok(...)).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 12fb4f19-f265-46b6-bc95-c5a7cff6163b
📒 Files selected for processing (12)
.gitignoresrc/main/java/kr/co/knuserver/application/pubOrder/PubOrderCommandService.javasrc/main/java/kr/co/knuserver/application/pubOrder/PubOrderQueryService.javasrc/main/java/kr/co/knuserver/domain/pubOrder/entity/PubOrder.javasrc/main/java/kr/co/knuserver/domain/pubOrder/repository/PubOrderRepository.javasrc/main/java/kr/co/knuserver/global/exception/BusinessErrorCode.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderCommandController.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/controller/PubOrderQueryController.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/dto/OrderMenus.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/dto/OrderedMenus.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/dto/PubOrderRequestDto.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/dto/PubOrderResponseDto.java
src/main/java/kr/co/knuserver/application/pubOrder/PubOrderCommandService.java
Show resolved
Hide resolved
src/main/java/kr/co/knuserver/application/pubOrder/PubOrderQueryService.java
Show resolved
Hide resolved
src/main/java/kr/co/knuserver/presentation/pubOrder/dto/PubOrderRequestDto.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/main/java/kr/co/knuserver/domain/pubOrder/entity/PubOrder.java`:
- Line 26: The entity PubOrder's primary key field id was remapped to
`@Column`(name = "pub_order_id") which will break runtime SQL if the deployed DB
still uses the old column name (pub_table_id); revert the column mapping on the
id field to the existing DB column name (use `@Column`(name = "pub_table_id") or
remove the name attribute so it matches the current schema) until the DB
migration that renames pub_table_id→pub_order_id has been applied, and ensure
any deployment that introduces `@Column`(name = "pub_order_id") is gated behind
the corresponding migration being applied in production.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0540f43b-f797-4f2a-8b1f-b0c286641a47
📒 Files selected for processing (2)
src/main/java/kr/co/knuserver/domain/pubOrder/entity/PubOrder.javasrc/main/java/kr/co/knuserver/presentation/pubOrder/dto/PubOrderRequestDto.java
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/main/java/kr/co/knuserver/application/pubOrder/PubOrderCommandService.java`:
- Around line 39-51: The code may NPE when mapping savedPubOrders to menus
because pubMenuMap.get(pubOrder.getPubMenuId()) can be null; before calling
pubOrderRepository.saveAll(pubOrders) perform a validation using
pubMenuQueryService.findAllPubMenuByIds(...) against the incoming pubOrders'
pubMenuId list, detect any missing IDs, and if any are absent throw a
BusinessException listing the invalid menu IDs; then proceed to save and
continue using OrderedMenus.fromEntity(pubOrder, pubMenu) with the guaranteed
non-null pubMenu.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 571baf1b-e8e5-4651-ba65-23cac9524e79
📒 Files selected for processing (2)
src/main/java/kr/co/knuserver/application/pubMenu/PubMenuQueryService.javasrc/main/java/kr/co/knuserver/application/pubOrder/PubOrderCommandService.java
✨ 구현한 기능
📢 논의하고 싶은 내용
🎸 기타
기존 설계는 주문 시 메뉴를 하나씩만 주문한다는 가정이 있었는데, 실제로는 하나의 메뉴를 여러 개 주문하는 경우도 있으므로 PubOrder 엔티티에 quantity 필드를 추가하였습니다.
아래 코드 리뷰 과정에서 N + 1 쿼리 문제 해결을 위해 PubMenuQueryService에 findAllPubMenuByIds 메서드를 추가하였습니다.
close #26
Summary by CodeRabbit
새로운 기능
개선 사항
기타