forked from 9oormthon-univ/2024_DANPOONG_TEAM_5_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
754b1c0
commit b5de2ba
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