-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 장바구니 추가 기능 구현 * feat: 장바구니 조회 기능 구현
- Loading branch information
1 parent
bede955
commit c6f9bd4
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/jangburich/domain/order/dto/response/CartResponse.java
This file contains 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,33 @@ | ||
package com.jangburich.domain.order.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record CartResponse( | ||
List<GetCartItemsResponse> cartItems, | ||
Integer totalAmount, | ||
Integer discountAmount, | ||
Integer finalAmount | ||
) { | ||
public static CartResponse of(List<GetCartItemsResponse> cartItems, Integer discountAmount) { | ||
int totalAmount = cartItems.stream() | ||
.mapToInt(item -> item.menuPrice * item.quantity) | ||
.sum(); | ||
|
||
discountAmount = 0; | ||
|
||
int finalAmount = totalAmount - discountAmount; | ||
|
||
return new CartResponse(cartItems, totalAmount, discountAmount, finalAmount); | ||
} | ||
|
||
public record GetCartItemsResponse( | ||
String menuName, | ||
String menuDescription, | ||
Integer quantity, | ||
Integer menuPrice | ||
) { | ||
public static GetCartItemsResponse of(String menuName, String menuDescription, Integer quantity, Integer menuPrice) { | ||
return new GetCartItemsResponse(menuName, menuDescription, quantity, menuPrice); | ||
} | ||
} | ||
} |
This file contains 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