-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] 주문 도메인 API 구현 #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8cdbe03
feat: Order 관련 엔티티 생성
mingdodev e1aea6a
docs: 가게 목록 조회 Swagger 설명 수정
mingdodev 5136dc6
refactor: 가게 DTO 이름 변경
mingdodev 65c55af
feat: 고객의 주문 목록 조회 구현
mingdodev 1e4a522
feat: 사장님의 주문 목록 조회 구현
mingdodev 45f8b49
feat: 고객의 주문 생성 구현
mingdodev a2af3b0
refactor: 주문 입력 정보 패키지 변경
mingdodev 6fdb033
feat: 주문 내역에 대한 접근 권한 확인 메서드 추가
mingdodev b6eb3b5
feat: 사장님의 주문 항목 수정 구현
mingdodev d1b976b
feat: 사장님의 주문 수락 또는 거절 구현
mingdodev e79a9ab
refactor: 사장님의 주문 수정 API Http Method 및 URL 변경
mingdodev 90c2d3f
feat: PATCH 메서드에 대한 요청 허용
mingdodev fab4419
feat: 주문 요청 필드에 대한 검증 추가
mingdodev 45dcf74
fix: 주문 총액에 대한 필드명 통일
mingdodev d55476a
fix: 빌더 사용 시에도 기본 값 초기화가 이루어지도록 수정
mingdodev 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
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
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
62 changes: 62 additions & 0 deletions
62
src/main/java/danji/danjiapi/domain/order/controller/OrderController.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,62 @@ | ||
| package danji.danjiapi.domain.order.controller; | ||
|
|
||
| import danji.danjiapi.domain.order.dto.request.OrderCreateRequest; | ||
| import danji.danjiapi.domain.order.dto.request.OrderStatusUpdateRequest; | ||
| import danji.danjiapi.domain.order.dto.request.OrderUpdateRequest; | ||
| import danji.danjiapi.domain.order.dto.response.CustomerOrderDetail; | ||
| import danji.danjiapi.domain.order.dto.response.MerchantOrderDetail; | ||
| import danji.danjiapi.domain.order.dto.response.OrderCreateResponse; | ||
| import danji.danjiapi.domain.order.dto.response.OrderStatusUpdateResponse; | ||
| import danji.danjiapi.domain.order.service.OrderService; | ||
| import danji.danjiapi.global.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import jakarta.validation.Valid; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api") | ||
| @RequiredArgsConstructor | ||
| public class OrderController { | ||
| private final OrderService orderService; | ||
|
|
||
| @GetMapping("/customers/me/orders") | ||
| @Operation(summary = "고객의 주문 목록 조회", description = "고객이 모든 주문 목록을 조회합니다. 주문은 주문 항목들과 주문 상태를 포함합니다.") | ||
| public ApiResponse<List<CustomerOrderDetail>> getCustomerOrders() { | ||
| return ApiResponse.success(orderService.getCustomerOrders()); | ||
| } | ||
|
|
||
| @GetMapping("/merchants/me/orders") | ||
| @Operation(summary = "사장님의 주문 목록 조회", description = "사장님이 모든 주문 목록을 조회합니다. 주문은 주문 항목들과 주문 상태를 포함합니다.") | ||
| public ApiResponse<List<MerchantOrderDetail>> getMerchantOrders() { | ||
| return ApiResponse.success(orderService.getMerchantOrders()); | ||
| } | ||
|
|
||
| @PostMapping("/orders") | ||
| @Operation(summary = "고객의 주문 요청", description = "고객이 주문을 요청(생성)합니다. 요청은 PENDING 상태로 생성됩니다.") | ||
| public ApiResponse<OrderCreateResponse> create(@Valid @RequestBody OrderCreateRequest request) { | ||
| return ApiResponse.success(orderService.create(request)); | ||
| } | ||
|
|
||
| @PatchMapping("/orders/{orderId}") | ||
| @Operation(summary = "사장님의 주문 수정", description = "사장님이 주문(주문 항목의 가격, 수량)을 수정합니다.") | ||
| public ApiResponse<Void> update(@PathVariable Long orderId, | ||
| @Valid @RequestBody OrderUpdateRequest request) { | ||
| orderService.update(orderId, request); | ||
| return ApiResponse.success(null, "주문 수정이 완료되었습니다."); | ||
| } | ||
|
|
||
| @PatchMapping("/orders/{orderId}/status") | ||
| @Operation(summary = "사장님의 주문 수락 및 거절", description = "사장님이 주문 상태를 수락 또는 거절로 변경합니다.") | ||
| public ApiResponse<OrderStatusUpdateResponse> updateStatus(@PathVariable Long orderId, | ||
| @Valid @RequestBody OrderStatusUpdateRequest request) { | ||
| return ApiResponse.success(orderService.updateStatus(orderId, request)); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/danji/danjiapi/domain/order/dto/request/OrderCreateRequest.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,18 @@ | ||
| package danji.danjiapi.domain.order.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotEmpty; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public record OrderCreateRequest( | ||
| @NotNull(message = "가게 id가 누락되었습니다.") | ||
| Long marketId, | ||
| @NotNull(message = "배송 일자가 누락되었습니다.") | ||
| LocalDateTime date, | ||
| String deliveryAddress, | ||
| @NotNull(message = "주문 항목이 누락되었습니다.") | ||
| @NotEmpty(message = "주문 상품 목록은 비어있을 수 없습니다.") | ||
| List<OrderItemInfo> orderItems | ||
| ) { | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/main/java/danji/danjiapi/domain/order/dto/request/OrderItemDetail.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,17 @@ | ||
| package danji.danjiapi.domain.order.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.math.BigDecimal; | ||
|
|
||
| public record OrderItemDetail( | ||
| @NotNull(message = "상품 id가 누락되었습니다.") | ||
| Long id, | ||
| @NotBlank(message = "상품명이 누락되었습니다.") | ||
| String name, | ||
| @NotNull(message = "상품 가격이 누락되었습니다.") | ||
| BigDecimal price, | ||
| @NotNull(message = "상품 수량이 누락되었습니다.") | ||
| Integer quantity | ||
| ) { | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/danji/danjiapi/domain/order/dto/request/OrderItemInfo.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,15 @@ | ||
| package danji.danjiapi.domain.order.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.math.BigDecimal; | ||
|
|
||
| public record OrderItemInfo( | ||
| @NotBlank(message = "상품명이 누락되었습니다.") | ||
| String name, | ||
| @NotNull(message = "상품 가격이 누락되었습니다.") | ||
| BigDecimal price, | ||
| @NotNull(message = "상품 수량이 누락되었습니다.") | ||
| Integer quantity | ||
| ) { | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/danji/danjiapi/domain/order/dto/request/OrderStatusUpdateRequest.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,8 @@ | ||
| package danji.danjiapi.domain.order.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record OrderStatusUpdateRequest( | ||
| @NotNull(message = "주문 상태가 누락되었습니다.") | ||
| String status | ||
| ) {} |
12 changes: 12 additions & 0 deletions
12
src/main/java/danji/danjiapi/domain/order/dto/request/OrderUpdateRequest.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,12 @@ | ||
| package danji.danjiapi.domain.order.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotEmpty; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.util.List; | ||
|
|
||
| public record OrderUpdateRequest( | ||
| @NotNull(message = "주문 상품 목록이 누락되었습니다.") | ||
| @NotEmpty(message = "주문 상품 목록은 비어있을 수 없습니다.") | ||
| List<OrderItemDetail> orderItems | ||
| ) { | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/danji/danjiapi/domain/order/dto/response/CustomerOrderDetail.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,37 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.market.entity.Market; | ||
| import danji.danjiapi.domain.order.entity.Order; | ||
| import java.math.BigDecimal; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public record CustomerOrderDetail( | ||
| Long orderId, | ||
| String orderStatus, | ||
| LocalDateTime date, | ||
| String deliveryAddress, | ||
| MarketSummary market, | ||
| List<OrderItemDetail> orderItems, | ||
| BigDecimal totalPrice | ||
| ) { | ||
| public static CustomerOrderDetail from(Order order, Market market) { | ||
| List<OrderItemDetail> orderItemDetails = order.getOrderItems().stream() | ||
| .map(OrderItemDetail::from) | ||
| .toList(); | ||
|
|
||
| BigDecimal totalPrice = orderItemDetails.stream() | ||
| .map(item -> item.price().multiply(BigDecimal.valueOf(item.quantity()))) | ||
| .reduce(BigDecimal.ZERO, BigDecimal::add); | ||
|
|
||
| return new CustomerOrderDetail( | ||
| order.getId(), | ||
| order.getStatus().name(), | ||
| order.getDate(), | ||
| order.getDeliveryAddress(), | ||
| MarketSummary.from(market), | ||
| orderItemDetails, | ||
| totalPrice | ||
| ); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/danji/danjiapi/domain/order/dto/response/CustomerSummary.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,15 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.user.entity.User; | ||
|
|
||
| public record CustomerSummary( | ||
| Long id, | ||
| String name | ||
| ) { | ||
| public static CustomerSummary from(User user) { | ||
| return new CustomerSummary( | ||
| user.getId(), | ||
| user.getName() | ||
| ); | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/danji/danjiapi/domain/order/dto/response/MarketSummary.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,17 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.market.entity.Market; | ||
|
|
||
| public record MarketSummary( | ||
| Long id, | ||
| String name, | ||
| String address | ||
| ) { | ||
| public static MarketSummary from(Market market) { | ||
| return new MarketSummary( | ||
| market.getId(), | ||
| market.getName(), | ||
| market.getAddress() | ||
| ); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/java/danji/danjiapi/domain/order/dto/response/MerchantOrderDetail.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,37 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.order.entity.Order; | ||
| import danji.danjiapi.domain.user.entity.User; | ||
| import java.math.BigDecimal; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| public record MerchantOrderDetail( | ||
| Long orderId, | ||
| String orderStatus, | ||
| LocalDateTime date, | ||
| String deliveryAddress, | ||
| CustomerSummary customer, | ||
| List<OrderItemDetail> orderItems, | ||
| BigDecimal totalPrice | ||
| ) { | ||
| public static MerchantOrderDetail from(Order order, User customer) { | ||
| List<OrderItemDetail> orderItemDetails = order.getOrderItems().stream() | ||
| .map(OrderItemDetail::from) | ||
| .toList(); | ||
|
|
||
| BigDecimal totalPrice = orderItemDetails.stream() | ||
| .map(item -> item.price().multiply(BigDecimal.valueOf(item.quantity()))) | ||
| .reduce(BigDecimal.ZERO, BigDecimal::add); | ||
|
|
||
| return new MerchantOrderDetail( | ||
| order.getId(), | ||
| order.getStatus().name(), | ||
| order.getDate(), | ||
| order.getDeliveryAddress(), | ||
| CustomerSummary.from(customer), | ||
| orderItemDetails, | ||
| totalPrice | ||
| ); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/java/danji/danjiapi/domain/order/dto/response/OrderCreateResponse.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,13 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.order.entity.Order; | ||
|
|
||
| public record OrderCreateResponse( | ||
| Long id | ||
| ) { | ||
| public static OrderCreateResponse from(Order order) { | ||
| return new OrderCreateResponse( | ||
| order.getId() | ||
| ); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/danji/danjiapi/domain/order/dto/response/OrderItemDetail.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,20 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.order.entity.OrderItem; | ||
| import java.math.BigDecimal; | ||
|
|
||
| public record OrderItemDetail( | ||
| Long id, | ||
| String name, | ||
| Integer quantity, | ||
| BigDecimal price | ||
| ) { | ||
| public static OrderItemDetail from(OrderItem orderItem) { | ||
| return new OrderItemDetail( | ||
| orderItem.getId(), | ||
| orderItem.getName(), | ||
| orderItem.getQuantity(), | ||
| orderItem.getPrice() | ||
| ); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/danji/danjiapi/domain/order/dto/response/OrderStatusUpdateResponse.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,12 @@ | ||
| package danji.danjiapi.domain.order.dto.response; | ||
|
|
||
| import danji.danjiapi.domain.order.entity.Order; | ||
|
|
||
| public record OrderStatusUpdateResponse( | ||
| Long orderId, | ||
| String updatedStatus | ||
| ) { | ||
| public static OrderStatusUpdateResponse from(Order order) { | ||
| return new OrderStatusUpdateResponse(order.getId(), order.getStatus().name()); | ||
| } | ||
mingdodev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.