-
Notifications
You must be signed in to change notification settings - Fork 0
feat(order): 사용자별 주문 조회(세션) #50
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
The head ref may contain hidden characters: "feature/#30-\uC8FC\uBB38CRUD"
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| package com.example.gtable.orderitem.dto; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import com.example.gtable.orderitem.entity.OrderItem; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import lombok.AllArgsConstructor; | ||||||||||||||||||||||||||||||||||||||||||||
| import lombok.Builder; | ||||||||||||||||||||||||||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||||||||||||||||||||||||||
| import lombok.NoArgsConstructor; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||||||||||||||||||||||||
| @Builder | ||||||||||||||||||||||||||||||||||||||||||||
| @NoArgsConstructor | ||||||||||||||||||||||||||||||||||||||||||||
| @AllArgsConstructor | ||||||||||||||||||||||||||||||||||||||||||||
| public class OrderItemListGetResponseDto { | ||||||||||||||||||||||||||||||||||||||||||||
| private Long orderId; | ||||||||||||||||||||||||||||||||||||||||||||
| private String menuName; | ||||||||||||||||||||||||||||||||||||||||||||
| private Integer quantity; | ||||||||||||||||||||||||||||||||||||||||||||
| private Integer price; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| public static OrderItemListGetResponseDto fromEntity(OrderItem orderItem) { | ||||||||||||||||||||||||||||||||||||||||||||
| return OrderItemListGetResponseDto.builder() | ||||||||||||||||||||||||||||||||||||||||||||
| .orderId(orderItem.getUserOrder().getId()) | ||||||||||||||||||||||||||||||||||||||||||||
| .menuName(orderItem.getMenu().getName()) | ||||||||||||||||||||||||||||||||||||||||||||
| .quantity(orderItem.getQuantity()) | ||||||||||||||||||||||||||||||||||||||||||||
| .price(orderItem.getMenu().getPrice()) | ||||||||||||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+28
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. 🛠️ Refactor suggestion 엔티티 접근 시 null 안전성 고려가 필요합니다.
다음과 같이 null 안전성을 추가해보세요: public static OrderItemListGetResponseDto fromEntity(OrderItem orderItem) {
+ if (orderItem == null || orderItem.getUserOrder() == null || orderItem.getMenu() == null) {
+ throw new IllegalArgumentException("OrderItem과 연관된 엔티티들이 null일 수 없습니다");
+ }
return OrderItemListGetResponseDto.builder()
.orderId(orderItem.getUserOrder().getId())
.menuName(orderItem.getMenu().getName())
.quantity(orderItem.getQuantity())
.price(orderItem.getMenu().getPrice())
.build();
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
API 응답 일관성과 세션 보안을 고려해주세요.
새로운 엔드포인트가 잘 구현되었지만, 몇 가지 개선사항을 제안드립니다.
ApiUtils.success()로 래핑@GetMapping("/items/{storeId}/{tableId}") @Operation(summary = "테이블별 주문 아이템 조회", description = "비로그인(세션) 기준으로 테이블의 내 주문 목록만 조회") @ApiResponse(responseCode = "200", description = "주문 조회") -public ResponseEntity<List<OrderItemListGetResponseDto>> getOrderItems( +public ResponseEntity<?> getOrderItems( @PathVariable Long storeId, @PathVariable Long tableId, HttpSession session ) { + if (session.isNew()) { + throw new IllegalStateException("유효하지 않은 세션입니다"); + } + String sessionId = session.getId(); List<OrderItemListGetResponseDto> orderItems = orderService.getOrderItems(storeId, tableId, sessionId); - return ResponseEntity.ok(orderItems); + return ResponseEntity.ok(ApiUtils.success(orderItems)); }📝 Committable suggestion
🤖 Prompt for AI Agents