Skip to content
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

Open
wants to merge 21 commits into
base: tdd-minuyim
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
05f1a50
docs: 요구사항 정리
minuyim Jun 25, 2020
0065b01
feat: Repository에서 number에 맞는 메뉴를 찾는 기능 추가
minuyim Jun 25, 2020
22d91ad
chore: 패키지 구조 변경
minuyim Jun 25, 2020
ecc0f4a
feat: 주문 수량을 나타내는 Amount 추가
minuyim Jun 25, 2020
9507894
feat: 단일 메뉴에 대한 주문 정보를 나타내는 MenuOrder 추가
minuyim Jun 25, 2020
e6388d0
feat: 테이블의 주문 정보를 나타내는 Order 추가
minuyim Jun 26, 2020
387aa7d
feat: TableRepository의 조회 기능 추가 및 Order의 add기능을 Table에 맞게 수정
minuyim Jun 27, 2020
5c48d26
refactor: Order 구조 수정
minuyim Jun 27, 2020
b2f1055
feat: Table 기능 추가
minuyim Jun 27, 2020
130dadf
chore: 패키지 분리
minuyim Jun 27, 2020
05d7e69
feat: 요구사항에 있는 할인 정책 추가
minuyim Jun 27, 2020
49a13c7
feat: Payment 기능 추가
minuyim Jun 27, 2020
7b92c68
feat: service 레이어 추가
minuyim Jun 27, 2020
a8b410c
feat: controller, view 레이어 추가
minuyim Jun 27, 2020
a07defa
fix: 버그 수정
minuyim Jun 27, 2020
b4ea10c
style: 코드 포맷팅
minuyim Jun 27, 2020
842f375
refactor: 기타 누락된 부분 수정
minuyim Jun 27, 2020
e6dfe0e
refactor: 종료 커맨드 입력시 직접 프로그램을 종료하도록 수정
minuyim Jun 28, 2020
fbaaa79
refactor: AmountCache 추가 및 정적 팩토리 메서드 추가
minuyim Jun 28, 2020
1c08d8b
refactor: findTableOrder 시 예외처리 부분을 도메인이 책임을 가지도록 수정
minuyim Jun 28, 2020
3b84828
refactor: 보다 상세한 예외 메세지 표
minuyim Jun 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
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. 결제가 불가능할 경우 예외처리가 필요하다.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ repositories {
dependencies {
testCompile('org.junit.jupiter:junit-jupiter:5.5.2')
testCompile('org.assertj:assertj-core:3.14.0')
}

test {
useJUnitPlatform()
}
35 changes: 21 additions & 14 deletions src/main/java/Application.java
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자가 받는게 아주 많군요!!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서비스가 많다보니 ㅠㅠ 어떻게 바꾸는 편이 좋을까요?

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();
}
}
}
48 changes: 48 additions & 0 deletions src/main/java/controller/ChickenController.java
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘못입력하면 바로 에러가 발생하는게 아니라 addOrder에서 터지겠네요..?
사용자 입장에서는 열심히 입력했는데 슬플것같아요ㅠㅠ

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 공감합니다...

Copy link
Author

Choose a reason for hiding this comment

The 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)));
}
}
29 changes: 29 additions & 0 deletions src/main/java/controller/Command.java
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);
}
}
22 changes: 22 additions & 0 deletions src/main/java/controller/PageController.java
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());
}
}
}
17 changes: 0 additions & 17 deletions src/main/java/domain/Category.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/domain/Menu.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/domain/MenuRepository.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/domain/Payment.java
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);
}
}
14 changes: 0 additions & 14 deletions src/main/java/domain/Table.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/domain/TableRepository.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/java/domain/menu/Category.java
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;
}
}
50 changes: 50 additions & 0 deletions src/main/java/domain/menu/Menu.java
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앨런에게도 물어본 이야기입니다.
#7 (comment)

라테는 어떻게 생각하나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 요구사항 중 getter를 쓰지 않는다.를 지키려다 보니 이런 코드가 나왔네요.
사실 여기서는 감싸여진 클래스가 많다보니 이런 왔다갔다(?)하는 코드가 있는 거라고 생각해서, 이 경우는 getter를 쓰는게 좋을 수도 있을 것 같습니다. 다만 이번 단계에서는 getter 사용 금지에 초점을 맞춰 진행해보았습니다.

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 + "원";
}
}
Loading