-
Notifications
You must be signed in to change notification settings - Fork 0
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
[라테] 치킨집 미션 제출합니다. #6
base: tdd-minuyim
Are you sure you want to change the base?
Changes from all commits
05f1a50
0065b01
22d91ad
ecc0f4a
9507894
e6388d0
387aa7d
5c48d26
b2f1055
130dadf
05d7e69
49a13c7
7b92c68
a8b410c
a07defa
b4ea10c
842f375
e6dfe0e
fbaaa79
1c08d8b
3b84828
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 +1,18 @@ | ||
# java-chicken-2019 | ||
# java-chicken-2020-tdd | ||
|
||
## 기능 요구사항 | ||
1. pos 프로그램을 통해 주문하기, 계산하기 기능을 실행할 수 있어야 한다. | ||
2. 테이블을 선택해 메뉴를 주문할 수 있어야 한다. | ||
1. 테이블을 구현한다. | ||
2. 메뉴를 구현한다. | ||
3. 번호에 맞게 테이블, 메뉴를 선택할 수 있어야 한다. | ||
4. 주문 수량을 정할 수 있어야 한다. | ||
1. 메뉴 당 주문 수량은 99개 이하여야 한다. | ||
3. 주문이 남아있는 테이블은 콘솔에 표시되어야 한다. | ||
4. 테이블 별 주문 내역을 통해 주문 내역을 계산해야 한다. | ||
1. 주문 내역을 표시해야 한다. | ||
2. 주문 내역에 따른 총 가격을 계산해야 한다. | ||
3. 총 가격을 할인 정책에 따라 계산 후 최종 가격을 표시해야 한다. | ||
1. 지불 방식 별 할인 정책을 세울 수 있어야 한다. | ||
2. 주문 내역에 따라 할인 정책을 세울 수 있어야 한다. | ||
4. 결제가 불가능할 경우 예외처리가 필요하다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
import domain.Menu; | ||
import domain.MenuRepository; | ||
import domain.Table; | ||
import domain.TableRepository; | ||
import java.util.Scanner; | ||
|
||
import controller.ChickenController; | ||
import controller.PageController; | ||
import domain.menu.MenuRepository; | ||
import domain.table.TableRepository; | ||
import service.MenuService; | ||
import service.PaymentService; | ||
import service.TableOrderService; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
import java.util.List; | ||
|
||
public class Application { | ||
// TODO 구현 진행 | ||
public static void main(String[] args) { | ||
final List<Table> tables = TableRepository.tables(); | ||
OutputView.printTables(tables); | ||
public static void main(String[] args) { | ||
MenuRepository menuRepository = new MenuRepository(); | ||
TableRepository tableRepository = new TableRepository(); | ||
InputView inputView = new InputView(new Scanner(System.in)); | ||
|
||
final int tableNumber = InputView.inputTableNumber(); | ||
ChickenController chickenController = new ChickenController(inputView, | ||
new OutputView(), new MenuService(menuRepository), | ||
new PaymentService(tableRepository), new TableOrderService(tableRepository, menuRepository)); | ||
|
||
final List<Menu> menus = MenuRepository.menus(); | ||
OutputView.printMenus(menus); | ||
} | ||
PageController pageController = new PageController(inputView, chickenController); | ||
while (true) { | ||
pageController.run(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package controller; | ||
|
||
import service.MenuService; | ||
import service.PaymentService; | ||
import service.TableOrderService; | ||
import service.dto.PayRequest; | ||
import service.dto.TableOrderRequest; | ||
import view.InputView; | ||
import view.OutputView; | ||
|
||
public class ChickenController { | ||
private final InputView inputView; | ||
private final OutputView outputView; | ||
private final MenuService menuService; | ||
private final PaymentService paymentService; | ||
private final TableOrderService tableOrderService; | ||
|
||
public ChickenController(InputView inputView, OutputView outputView, MenuService menuService, | ||
PaymentService paymentService, TableOrderService tableOrderService) { | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
this.menuService = menuService; | ||
this.paymentService = paymentService; | ||
this.tableOrderService = tableOrderService; | ||
} | ||
|
||
public void order() { | ||
outputView.printTables(tableOrderService.findAllTables()); | ||
int tableNumber = inputView.inputTableNumber(); | ||
|
||
outputView.printMenus(menuService.findAllMenus()); | ||
int menuNumber = inputView.inputMenuNumber(); | ||
|
||
int amount = inputView.inputAmount(); | ||
|
||
tableOrderService.addOrder(new TableOrderRequest(tableNumber, menuNumber, amount)); | ||
Comment on lines
+28
to
+36
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. 잘못입력하면 바로 에러가 발생하는게 아니라 addOrder에서 터지겠네요..? 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. 저도 공감합니다... 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. 콘솔을 웹처럼 구현하다보니 불가피한 부분이 존재하더라고요... |
||
} | ||
|
||
public void pay() { | ||
outputView.printTables(tableOrderService.findAllTables()); | ||
int tableNumber = inputView.inputTableNumber(); | ||
|
||
outputView.printOrder(tableOrderService.findTableOrder(tableNumber)); | ||
int paymentNumber = inputView.inputPaymentNumber(); | ||
|
||
outputView.printPaymentAmount(paymentService.payOrder(new PayRequest(tableNumber, paymentNumber))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package controller; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Consumer; | ||
|
||
public enum Command { | ||
ORDER(1, ChickenController::order), | ||
PAY(2, ChickenController::pay), | ||
EXIT(3, chickenController -> System.exit(0)); | ||
|
||
private final int number; | ||
private final Consumer<ChickenController> consumer; | ||
|
||
Command(int number, Consumer<ChickenController> consumer) { | ||
this.number = number; | ||
this.consumer = consumer; | ||
} | ||
|
||
public static Command findByNumber(int number) { | ||
return Arrays.stream(values()) | ||
.filter(command -> command.number == number) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("값에 해당하는 명령이 없습니다. number : " + number)); | ||
} | ||
|
||
public void execute(ChickenController chickenController) { | ||
consumer.accept(chickenController); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package controller; | ||
|
||
import view.InputView; | ||
|
||
public class PageController { | ||
private final InputView inputView; | ||
private final ChickenController chickenController; | ||
|
||
public PageController(InputView inputView, ChickenController chickenController) { | ||
this.inputView = inputView; | ||
this.chickenController = chickenController; | ||
} | ||
|
||
public void run() { | ||
try { | ||
Command command = Command.findByNumber(inputView.inputCommandNumber()); | ||
command.execute(chickenController); | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package domain; | ||
|
||
import java.util.Arrays; | ||
|
||
public enum Payment { | ||
CARD(1, price -> price), | ||
CASH(2, price -> (int)(0.95 * price)); | ||
|
||
private final int number; | ||
private final PricingDiscountStrategy pricingDiscountStrategy; | ||
|
||
Payment(int number, PricingDiscountStrategy pricingDiscountStrategy) { | ||
this.number = number; | ||
this.pricingDiscountStrategy = pricingDiscountStrategy; | ||
} | ||
|
||
public static Payment findByNumber(int number) { | ||
return Arrays.stream(values()) | ||
.filter(payment -> payment.number == number) | ||
.findAny() | ||
.orElseThrow(() -> new IllegalArgumentException("해당하는 결제 수단이 존재하지 않습니다. number : " + number)); | ||
} | ||
|
||
public int calculatePay(int price) { | ||
return pricingDiscountStrategy.calculate(price); | ||
} | ||
|
||
private interface PricingDiscountStrategy { | ||
int calculate(int price); | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package domain.menu; | ||
|
||
public enum Category { | ||
CHICKEN("치킨"), | ||
BEVERAGE("음료"); | ||
|
||
private final String name; | ||
|
||
Category(final String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + name + "]"; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package domain.menu; | ||
|
||
import domain.order.Amount; | ||
|
||
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 boolean isSameNumber(int other) { | ||
return number == other; | ||
} | ||
|
||
public boolean isSameCategory(Category other) { | ||
return category == other; | ||
} | ||
|
||
public int calculateMultiplePrice(Amount amount) { | ||
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. 앨런에게도 물어본 이야기입니다. 라테는 어떻게 생각하나요? 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 amount.multiply(price); | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getCategoryName() { | ||
return category.getName(); | ||
} | ||
|
||
public int getPrice() { | ||
return price; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return category + " " + number + " - " + name + " : " + price + "원"; | ||
} | ||
} |
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.
생성자가 받는게 아주 많군요!!!
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.
서비스가 많다보니 ㅠㅠ 어떻게 바꾸는 편이 좋을까요?