-
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 4 commits
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 |
|---|---|---|
| @@ -1,66 +1,81 @@ | ||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
|
|
||
| import domain.Bill; | ||
| import domain.Menu; | ||
| //import jdk.internal.util.xml.impl.Input; | ||
| import repository.MenuRepository; | ||
| import domain.PayType; | ||
| import domain.Table; | ||
| import repository.MenuRepository; | ||
| import repository.OrderRepository; | ||
| import repository.PayTypeRepository; | ||
| import repository.TableRepository; | ||
| import service.CafeOrderService; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Application { | ||
| // TODO 구현 진행 | ||
| public static void main(String[] args) { | ||
| OutputView.printMain(); | ||
| final CafeOrderService cafeOrderService = new CafeOrderService(new OrderRepository()); | ||
| final List<Table> tables = TableRepository.tables(); | ||
| int func = InputView.inputFunction(); | ||
| final static int ORDER = 1; | ||
| final static int PAY = 2; | ||
| final static int STOP = 3; | ||
|
|
||
| // TODO 구현 진행 | ||
| public static void main(String[] args) { | ||
| OutputView.printMain(); | ||
| final CafeOrderService cafeOrderService = new CafeOrderService(new OrderRepository()); | ||
| final List<Table> tables = TableRepository.tables(); | ||
| int func = InputView.inputFunction(); | ||
|
|
||
| while(func!=3) | ||
| { | ||
| if(func == 1) | ||
| { | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| if(func == 2) | ||
| { | ||
| payOrders(tables, cafeOrderService); | ||
| } | ||
| OutputView.printMain(); | ||
| func = InputView.inputFunction(); | ||
| } | ||
| } | ||
| while (func != STOP) { | ||
| if (func == ORDER) { | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| if (func == PAY) { | ||
| payOrders(tables, cafeOrderService); | ||
| } else if (func > STOP || func < ORDER) { | ||
| throw new NoSuchElementException("해당 기능은 존재하지 않습니다."); | ||
| } | ||
bominjang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OutputView.printMain(); | ||
| func = InputView.inputFunction(); | ||
| } | ||
| } | ||
|
|
||
| private static void payOrders(List<Table> tables, CafeOrderService cafeOrderService) { | ||
| OutputView.printTables(tables, cafeOrderService); | ||
| int tableNum = InputView.inputPayTableNumber(); | ||
| OutputView.printOrders(cafeOrderService, tableNum); | ||
| } | ||
| private static void payOrders(List<Table> tables, CafeOrderService cafeOrderService) { | ||
|
||
| OutputView.printTables(tables, cafeOrderService); | ||
| int tableNum = InputView.inputPayTableNumber(); | ||
| if (!cafeOrderService.checkOrderedTable(tableNum)) { | ||
| OutputView.printNoOrder(); | ||
| return; | ||
| } | ||
| Bill bill = cafeOrderService.getBillByTable(tableNum); | ||
| OutputView.printBill(bill); | ||
| OutputView.printPayMessage(tableNum); | ||
| int payTypeNumber = InputView.inputPayType(); | ||
| PayType payType = PayTypeRepository.findByNumber(payTypeNumber); | ||
| long amountOfPayment = cafeOrderService.getAmountOfPayment(bill, payType); | ||
| OutputView.printAmountOfPayment(amountOfPayment); | ||
| } | ||
|
|
||
| private static void orderMenu(List<Table> tables, CafeOrderService cafeOrderService) | ||
| { | ||
| OutputView.printTables(tables, cafeOrderService); | ||
| int tableNum = InputView.inputTableNumber(); | ||
| boolean isValidTblNum = cafeOrderService.isValidTableNum(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); | ||
| if(isValidMenuNum==false){ | ||
| OutputView.printMenuAlert(); | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| int menuCount = InputView.inputCount(); | ||
| boolean isValidMenuCount = cafeOrderService.canOrderMenu(tableNum, menuNum, menuCount); | ||
| if(isValidMenuCount==false){ | ||
| OutputView.printMaxAlert(); | ||
| return; | ||
| } | ||
| cafeOrderService.orderMenu(menuNum, menuCount, tableNum); | ||
| } | ||
| private static void orderMenu(List<Table> tables, CafeOrderService cafeOrderService) { | ||
| OutputView.printTables(tables, cafeOrderService); | ||
| int tableNumber = InputView.inputTableNumber(); | ||
| boolean isValidTableNumber = cafeOrderService.isValidTableNumber(tableNumber); | ||
| if (!isValidTableNumber) { | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| final List<Menu> menus = MenuRepository.menus(); | ||
| OutputView.printMenus(menus); | ||
| int menuNumber = InputView.inputMenu(); | ||
| boolean isValidMenuNum = cafeOrderService.isValidMenuNumber(menuNumber); | ||
| if (!isValidMenuNum) { | ||
| OutputView.printMenuAlert(); | ||
| orderMenu(tables, cafeOrderService); | ||
| } | ||
| int menuCount = InputView.inputCount(); | ||
| boolean isMaxMenuCount = cafeOrderService.checkMaximumCount(tableNumber, menuNumber, menuCount); | ||
| if (!isMaxMenuCount) { | ||
| OutputView.printMaxAlert(); | ||
| return; | ||
| } | ||
| cafeOrderService.orderMenu(tableNumber, menuNumber, menuCount); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import repository.MenuRepository; | ||
| import repository.OrderRepository; | ||
|
|
||
| //주문 메뉴와 수량을 알고있는 객체. OrderRepository는 이 객체를 통해 주문을 추가한다. | ||
| public class Bill { | ||
| private final int tableNumber; | ||
| Map<Menu, Integer> orderedMenus; | ||
|
|
||
| public Bill(int tableNumber) { | ||
| this.tableNumber = tableNumber; | ||
| this.orderedMenus = Collections.emptyMap(); | ||
| } | ||
|
|
||
| //해당 테이블에서 주문한 메뉴와 수량을 return한다. | ||
| public Bill(OrderRepository orderRepository, 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. Bill 객체가 orderRepository를 인자로 받아서 생성하지 않고 Bill 객체를 생성하는 주체가 orderRepository에서 order List를 조회해서 넘겨주는 방식은 어떻게 생각하시나요??? |
||
| List<Order> orders = orderRepository.findByTableNumber(tableNumber); | ||
| Map<Menu, Integer> orderedMenus = orders.stream() | ||
| .filter(order -> order.getTableNumber() == tableNumber) | ||
| .collect(Collectors.toMap(order -> MenuRepository.findByNumber(order.getMenuNumber()), | ||
| order -> order.getMenuCount(), (c1, c2) -> c1 + c2)); | ||
|
|
||
| this.tableNumber = tableNumber; | ||
| this.orderedMenus = orderedMenus; | ||
| } | ||
|
|
||
| public int getTableNumber() { | ||
| return tableNumber; | ||
| } | ||
|
|
||
| public Map<Menu, Integer> getOrderedMenus() { | ||
| return this.orderedMenus; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| package domain; | ||
|
|
||
| public enum Category { | ||
| CAKE("케이크"), | ||
| BEVERAGE("음료"); | ||
| CAKE("케이크"), | ||
| BEVERAGE("음료"); | ||
|
|
||
| private final String name; | ||
| private final String name; | ||
|
|
||
| Category(final String name) { | ||
| this.name = name; | ||
| } | ||
| Category(final String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[" + name + "]"; | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return "[" + name + "]"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,44 @@ | ||
| package domain; | ||
|
|
||
| public class Menu { | ||
| private final int number; | ||
| private final String name; | ||
| private final Category category; | ||
| private final int price; | ||
|
|
||
| public Menu(final int number, final String name, final Category category, final int price) { | ||
| this.number = number; | ||
| this.name = name; | ||
| this.category = category; | ||
| this.price = price; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public Category getCategory() { | ||
| return category; | ||
| } | ||
|
|
||
| public int getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return category + " " + number + " - " + name + " : " + price + "원"; | ||
| } | ||
| private final int number; | ||
| private final String name; | ||
| private final Category category; | ||
| private final int price; | ||
|
|
||
| public Menu(final int number, final String name, final Category category, final int price) { | ||
| this.number = number; | ||
| this.name = name; | ||
| this.category = category; | ||
| this.price = price; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public Category getCategory() { | ||
| return category; | ||
| } | ||
|
|
||
| public int getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| public boolean isEqualNumber(int number) { | ||
| return this.number == number; | ||
| } | ||
|
|
||
| public boolean isThisCake() { | ||
| return this.category == Category.CAKE; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return category + " " + number + " - " + name + " : " + price + "원"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,33 @@ | ||
| package domain; | ||
|
|
||
| public class Order { | ||
| private final int menuNum; | ||
| private final int tableNum; | ||
| private final int tableNumber; | ||
| private final int menuNumber; | ||
| private final int menuCount; | ||
|
|
||
| public Order(int menuNum, int tableNum) { | ||
| this.menuNum = menuNum; | ||
| this.tableNum = tableNum; | ||
| } | ||
| public Order(int tableNumber, int menuNumber, int menuCount) { | ||
| this.tableNumber = tableNumber; | ||
| this.menuNumber = menuNumber; | ||
| this.menuCount = menuCount; | ||
| } | ||
|
|
||
| public int getMenuNum() { | ||
| return this.menuNum; | ||
| } | ||
| public int getMenuNumber() { | ||
| return this.menuNumber; | ||
| } | ||
|
|
||
| public int getTableNum() { | ||
| return tableNum; | ||
| } | ||
| public int getTableNumber() { | ||
| return this.tableNumber; | ||
| } | ||
|
|
||
| public boolean isEqualTable(int tableNum){ | ||
| return this.tableNum == tableNum; | ||
| } | ||
| public int getMenuCount() { | ||
| return this.menuCount; | ||
| } | ||
|
|
||
| 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package domain; | ||
|
|
||
| //지불 수단 | ||
| public class PayType { | ||
| private final int number; | ||
| private final int discountRate; | ||
|
|
||
| public PayType(int number, int discountRate) { | ||
| this.number = number; | ||
| this.discountRate = discountRate; | ||
| } | ||
|
|
||
| public boolean isEqualPayType(int number) { | ||
| return this.number == number; | ||
| } | ||
|
|
||
| public int getDiscountRate() { | ||
| return this.discountRate; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,22 @@ | ||
| package domain; | ||
|
|
||
| public class Table { | ||
| private final int number; | ||
| private final int number; | ||
|
|
||
| public Table(final int number) { | ||
| this.number = number; | ||
| } | ||
| public Table(final int number) { | ||
| this.number = number; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return Integer.toString(number); | ||
| } | ||
| public boolean isEqualNumber(int tableNumber) { | ||
| return this.number == tableNumber; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return Integer.toString(number); | ||
| } | ||
| } |
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.
상수 👍