-
Notifications
You must be signed in to change notification settings - Fork 1
feat : 결제 기능 #15
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
base: jbm
Are you sure you want to change the base?
feat : 결제 기능 #15
Changes from 1 commit
243d011
def2667
cd63784
cf1e207
315dc17
d171c80
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 |
|---|---|---|
|
|
@@ -59,20 +59,20 @@ private static void orderMenu(List<Table> tables, CafeOrderService cafeOrderServ | |
| { | ||
| OutputView.printTables(tables, cafeOrderService); | ||
| int tableNum = InputView.inputTableNumber(); | ||
| boolean isValidTblNum = cafeOrderService.isValidTableNum(tableNum); | ||
| boolean isValidTblNum = cafeOrderService.isValidTableNumber(tableNum); | ||
| if(isValidTblNum==false){ | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| final List<Menu> menus = MenuRepository.menus(); | ||
| OutputView.printMenus(menus); | ||
| int menuNum = InputView.inputMenu(); | ||
| boolean isValidMenuNum = cafeOrderService.checkMenuNum(menuNum); | ||
| boolean isValidMenuNum = cafeOrderService.isValidMenuNumber(menuNum); | ||
| if(isValidMenuNum==false){ | ||
| OutputView.printMenuAlert(); | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| int menuCount = InputView.inputCount(); | ||
| boolean isValidMenuCount = cafeOrderService.canOrderMenu(tableNum, menuNum, menuCount); | ||
| boolean isValidMenuCount = cafeOrderService.checkMaximumCount(tableNum, menuNum, menuCount); | ||
| if(isValidMenuCount==false){ | ||
|
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. 위와 마찬가지인 부분! |
||
| OutputView.printMaxAlert(); | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,27 @@ | ||
| package domain; | ||
|
|
||
| public class Order { | ||
| private final int menuNum; | ||
| private final int tableNum; | ||
| private final int menuNumber; | ||
| private final int tableNumber; | ||
|
|
||
| public Order(int menuNum, int tableNum) { | ||
| this.menuNum = menuNum; | ||
| this.tableNum = tableNum; | ||
| this.menuNumber = menuNum; | ||
| this.tableNumber = tableNum; | ||
| } | ||
|
|
||
| public int getMenuNum() { | ||
| return this.menuNum; | ||
| public int getMenuNumber() { | ||
| return this.menuNumber; | ||
| } | ||
|
|
||
| public int getTableNum() { | ||
| return tableNum; | ||
| public int getTableNumber() { | ||
| return tableNumber; | ||
| } | ||
|
|
||
| public boolean isEqualTable(int tableNum){ | ||
| return this.tableNum == tableNum; | ||
| public boolean isEqualTable(int tableNumber){ | ||
| return this.tableNumber == tableNumber; | ||
| } | ||
|
|
||
| public boolean isEqualMenuNumber(int menuNumber){ | ||
| return this.menuNumber==menuNumber; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ public int getNumber() { | |
| return number; | ||
| } | ||
|
|
||
| public boolean isEqualNumber(int tableNumber){ return this.number==number;} | ||
|
|
||
|
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. 입력받은 파라미터가 사용되지 않고있어요! 이렇게 되면 항상 true를 리턴할 거 같아요! |
||
| @Override | ||
| public String toString() { | ||
| return Integer.toString(number); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,56 +5,59 @@ | |
|
|
||
| import java.util.*; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static java.util.stream.Collectors.*; | ||
|
|
||
| //주문 정보들을 저장하는 클래스 | ||
| public class OrderRepository { | ||
| private static final int MAX_NUMBER_PER_MENU = 30; | ||
| private final List<Order> orders = new ArrayList<>(); | ||
|
|
||
| //주문을 받는다. | ||
| public void addOrder(final Order order) | ||
| { | ||
| orders.add(order); | ||
| } | ||
|
|
||
| public int countMenusNumber(int tableNum, int menuNum){ | ||
| //해당 테이블에서 주문한 해당 메뉴의 수량을 return한다. | ||
| public int countMenusNumber(int tableNumber, int menuNumber){ | ||
| int count= (int)orders.stream() | ||
| .filter(order->order.isEqualTable(tableNum)) | ||
| .filter(order->menuNum==order.getMenuNum()) | ||
| .filter(order->order.isEqualTable(tableNumber)) | ||
|
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. 요 스트림은 인라인으로 빼서 바로 리턴해도 될 거 같습니다! |
||
| .filter(order->order.isEqualMenuNumber(menuNumber)) | ||
| .count(); | ||
| return count; | ||
| } | ||
|
|
||
| public boolean canOrder(int tableNum, int menuNum, int menuCount){ | ||
| int existedMenusNum = countMenusNumber(tableNum, menuNum); | ||
| if(existedMenusNum+menuCount<=MAX_NUMBER_PER_MENU){ | ||
| //해당 테이블에서 주문할 수 있는 한 메뉴의 최대 수량을 넘는지 아닌지 검사한다. | ||
| public boolean checkMaximumPerMenu(int tableNumber, int menuNumber, int menuCount){ | ||
| int existedMenusCount = countMenusNumber(tableNumber, menuNumber); | ||
| if(existedMenusCount+menuCount<=MAX_NUMBER_PER_MENU){ | ||
| return true; | ||
| }else{ | ||
| return false; | ||
| } | ||
| return false; | ||
|
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. return existedMenusCount + menuCount <= MAX_NUMBER_PER_MENU 로 바로 리턴하는건 어떨까요? |
||
| } | ||
|
|
||
| public List<Order> findByTableNumber(int tableNum) | ||
| //해당 테이블에서 주문한 것들을 모두 return한다. | ||
| public List<Order> findByTableNumber(int tableNumber) | ||
| { | ||
| return | ||
| orders.stream() | ||
| .filter(order-> order.isEqualTable(tableNum)) | ||
| .filter(order-> order.isEqualTable(tableNumber)) | ||
| .collect(toList()); | ||
| } | ||
|
|
||
| //해당 테이블에서 해당 메뉴의 수량을 출력하는 메소드 | ||
| public Map<Menu, Long> getBill(int tableNum){ | ||
| List<Order> orders = findByTableNumber(tableNum); | ||
| //해당 테이블에서 주문한 메뉴와 수량을 return한다. | ||
| public Map<Menu, Long> getBill(int tableNumber){ | ||
|
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. Map으로 들고 있는 것보단 객체로 빼서 책임을 할당하는건 어떨까요? 아래 코드에도 bill을 의미하는 맵을 가지고 로직을 처리하는 것보단, 가독성이나 추후 확장성에도 좋아보입니다. 개인적인 견해이니, 참고만 하시면 좋을 거 같습니다! |
||
| List<Order> orders = findByTableNumber(tableNumber); | ||
| Map<Menu, Long> bill = orders.stream() | ||
| .map(order -> MenuRepository.findByNumber(order.getMenuNum())) | ||
| .map(order -> MenuRepository.findByNumber(order.getMenuNumber())) | ||
| .collect(Collectors.groupingBy(order->order,HashMap::new, counting())); | ||
|
|
||
| return bill; | ||
| } | ||
|
|
||
| public void finishedPayment(int tableNum){ | ||
| orders.removeIf(order->order.isEqualTable(tableNum)); | ||
| //지불이 완료되면 해당 테이블의 주문을 모두 삭제한다. | ||
| public void finishedPayment(int tableNumber){ | ||
| orders.removeIf(order->order.isEqualTable(tableNumber)); | ||
| } | ||
|
|
||
| } | ||
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.
isValidMenuNum 이 이미 boolean 이니 false와 비교하지 않고 바로 if(!isValidMenuNum) 으로 사용하셔도 좋을 것 같아요!