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

[4기 - 소재훈] SpringBoot Part2 Weekly Mission 제출합니다. #852

Open
wants to merge 159 commits into
base: jay-so
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
5e0f655
refactor: ConsoleApplication 리팩토링
jay-so Jul 3, 2023
5f8b98f
init: Voucher TestCode 세팅
jay-so Jul 3, 2023
02dfa0f
feat:Customer 클래스(Customer Domain Class) 구현
jay-so Jul 6, 2023
f1f9c5f
refactor:VoucherType의 오류 메시지 리팩토링
jay-so Jul 6, 2023
10b60ad
refactor:Command enum 리팩토링
jay-so Jul 6, 2023
ce917df
feat: VoucherType에 따른 고정 할인 바우처, 퍼센트 비율 할인 바우처의 지정 범위를 벗어나는 경우 에러 메시지…
jay-so Jul 6, 2023
2ba1de8
refactor:Console 클래스 리팩토링
jay-so Jul 6, 2023
5c158a1
refactor: ConsoleApplication 리팩토링
jay-so Jul 6, 2023
0d6236e
Rename: 각 Controller, Service, doamin 폴더 안의 Voucher패키지로 Voucher 관련 Co…
jay-so Jul 6, 2023
50faf9e
refactor: Output
jay-so Jul 6, 2023
b244133
feat: 고정할인 바우처(FixedDiscountVoucherTest) 테스트
jay-so Jul 7, 2023
3561696
feat: 비율할인 바우처(PercentDiscountVoucher) 테스트 코드
jay-so Jul 7, 2023
65775ed
feat: ConsoleApplication 테스트 코드
jay-so Jul 7, 2023
7b6afd7
feat:VoucherService 테스트 코드
jay-so Jul 7, 2023
fac02cf
feat:VoucherController 테스트 코드 작성
jay-so Jul 7, 2023
85a7f28
refactor:불 필요한 주석 제거
jay-so Jul 7, 2023
b4d1d4d
rename: Voucher Controller,Service,repository 폴더 위치 변경
jay-so Jul 8, 2023
b253bc7
refactor: VoucherService의 공백 제거
jay-so Jul 8, 2023
64686ea
refactor:ConsoleApplication 리팩토링
jay-so Jul 8, 2023
eff8ead
refactor: origin/w2-1 브랜치와 차이가 나는 로컬 w2-1 브랜치 수정
jay-so Jul 8, 2023
1388473
refactor: origin/main 브랜치와 차이가 나는 로컬 main 브랜치 수정
jay-so Jul 8, 2023
a39864f
feat: customer 도메인 구현
jay-so Jul 8, 2023
b57abb4
feat:CustomerController 클래스 생성
jay-so Jul 8, 2023
8184b01
feat:CustomerRepository 클래스 생성
jay-so Jul 8, 2023
2881991
feat:CustomerService 클래스 생성
jay-so Jul 8, 2023
e639fc4
fefactor: Customer클래스 명 수정
jay-so Jul 8, 2023
b6d9c82
feat: CustomerRepository 인터페이스 구현
jay-so Jul 8, 2023
55a476b
feat:CustomerRepository의 구현체로 CustomerJdbcRepository가 되도록 변경
jay-so Jul 8, 2023
b78737c
refactor:CustomerService 인터페이스로 리팩토링
jay-so Jul 8, 2023
c6211fb
feat:CustomerService의 구현체 CustomerServiceImpl 생성
jay-so Jul 8, 2023
24d66a4
refactor:Build.gradle 의존성 리팩토링(Jdbc, mysql 의존성 추가, Text.io 의존성 삭제)
jay-so Jul 8, 2023
99261f6
refactor:Customer 클래스 수정
jay-so Jul 8, 2023
3c1325c
feat:CustomerDto 클래스 생성
jay-so Jul 8, 2023
d8a26dc
rm:CustomerServiceImpl 클래스 삭제
jay-so Jul 8, 2023
65aa986
refactor:CustomerService 클래스 수정
jay-so Jul 8, 2023
708d122
refactor: CustomerRepository 인터페이스 리팩토링
jay-so Jul 8, 2023
c5fbc8c
refactor:CustomerJdbcRepository 클래스 수정
jay-so Jul 8, 2023
3bcd69d
feat:VoucherDto 클래스 생성
jay-so Jul 8, 2023
c3ebd78
refactor:VocherController에 추가할 메소드 명 생성
jay-so Jul 8, 2023
7692e6e
refactor:VoucherService에 추가할 task명 생성
jay-so Jul 8, 2023
5b01135
refactor:CustomerDto 수정
jay-so Jul 9, 2023
ca67652
refactor:VoucherController Task 수정
jay-so Jul 9, 2023
d2ec5ed
refactor:VoucherService의 검증 로직 제거
jay-so Jul 9, 2023
f4cabf6
refactor:Voucher 인터페이스 리팩토링
jay-so Jul 9, 2023
f2b76ec
refactor: FixedDiscountVoucher 도메인 리팩토링 & 검증 로직 추가
jay-so Jul 9, 2023
9fe22df
refactor: PercentDiscountVoucher 도메인 리팩토링 & 검증 로직 추가
jay-so Jul 9, 2023
4850beb
fix:병합 중 충돌 부분 수정
jay-so Jul 10, 2023
b8c3259
refactor: FixedDiscountVoucher 금액 수정
jay-so Jul 10, 2023
3c52213
refactor: PercentDiscountVoucher discount 필드 수정
jay-so Jul 10, 2023
8eb2131
feat:CreateRequsetDto 생성
jay-so Jul 10, 2023
2f63b14
feat:VoucherUpdate Dto 생성
jay-so Jul 10, 2023
adbe066
feat: Voucher List 응답 Dto 생성
jay-so Jul 10, 2023
00486b7
feat: Voucher 응답 Dto 생성
jay-so Jul 10, 2023
be89fea
refactor: VoucherController 리팩토링
jay-so Jul 10, 2023
610d29d
refactor:VoucherRepository 인터페이스 리팩토링(Read, Update,Delete 추가)
jay-so Jul 10, 2023
32ef993
remove: 변경전 VoucherDTO 삭제
jay-so Jul 12, 2023
32f5bc9
refactor: Custeor domain 리팩토링
jay-so Jul 12, 2023
78ae65a
remove: 변경전 VoucherDto 삭제
jay-so Jul 12, 2023
eb37421
refactor: VoucherServie 리팩토링
jay-so Jul 12, 2023
9f8cb2e
refactor:VoucherRepository 리팩토링
jay-so Jul 12, 2023
efb2c17
w2-2 브랜치 병합
jay-so Jul 12, 2023
0ae3b88
refactor:Voucher 리팩토링
jay-so Jul 12, 2023
ef5f7fc
refactor:Voucher 인터페이스 리팩토링
jay-so Jul 12, 2023
80d6da6
rename:FixedDiscountVoucher -> FixedVoucher로 클래스명 변경
jay-so Jul 12, 2023
0a5b530
rename:PercentDiscountVoucher-> RateVoucher로 클래스명 변경
jay-so Jul 12, 2023
782d1ff
refactor:Voucher 리팩토링
jay-so Jul 12, 2023
57fc4f8
feat: FixedVoucher의 getDiscount메소드 구현
jay-so Jul 12, 2023
ef200db
feat: RateVoucher의 getDiscount메소드 구현
jay-so Jul 12, 2023
4f0e153
refactor: VoucherReposponse 리팩토링
jay-so Jul 12, 2023
efe50a5
refactor:VoucherRepository interface refactoring
jay-so Jul 12, 2023
f9bbf30
refactor: MemoryVoucherRepository refactoring
jay-so Jul 12, 2023
39c05b6
refactor:MemoryVoucherRepository refactoring
jay-so Jul 12, 2023
62829f2
refactor: VoucherRepository rectoring
jay-so Jul 12, 2023
a2819da
refactor:MemoryVoucherRepository refactoring
jay-so Jul 12, 2023
2fc6c31
feat:VoucherService CRUD functional implementation
jay-so Jul 12, 2023
0b3dddb
feat:VoucherType 추가
jay-so Jul 12, 2023
242de2e
feat:VoucherType 추가
jay-so Jul 12, 2023
823a26e
feat:Voucher 타입별 조회 추가
jay-so Jul 12, 2023
4776765
refactor:바우처 Controller refactoring
jay-so Jul 12, 2023
0cabf00
refactor: VoucherService refactoring
jay-so Jul 12, 2023
7ecf182
feat:VoucherJdbcRepository
jay-so Jul 12, 2023
0408b1b
refactor: build.gralde refactoring
jay-so Jul 12, 2023
ef16d6e
feat:Voucher shema 추가
jay-so Jul 12, 2023
5dbff20
refactor:VoucherType Perenct -> RATE로 변경
jay-so Jul 12, 2023
086aa43
refactor:VoucherType enum 변경
jay-so Jul 12, 2023
b367cff
refactor:FixedVoucher domain refactoring
jay-so Jul 12, 2023
ed1dab1
refactor:RateVoucher refactoring
jay-so Jul 12, 2023
11c9919
test:fixedVoucher 클래스의 모든 메소드 테스트
jay-so Jul 12, 2023
1e466a2
test:RateVoucher 도메인의 모든 메소드 테스트
jay-so Jul 12, 2023
7c26f43
refactor: Voucher 도메인 refactoring(@Setter add)
jay-so Jul 13, 2023
01850ce
refactor:Customer domain find Member refactoring(final keyword remove)
jay-so Jul 13, 2023
c40da75
refactor:VoucherJdbcRepository update method refactoring
jay-so Jul 13, 2023
f5b3d23
remove:CustomerDto remove
jay-so Jul 13, 2023
50d0a70
feat: CustomerCreateRequest Dto add
jay-so Jul 13, 2023
fb882c6
feat: CustomerUpdateRequestDto add
jay-so Jul 13, 2023
d862fb2
feat: CustomerListResponse Dto add
jay-so Jul 13, 2023
a3a21db
feat: CustomerResponse Dto add
jay-so Jul 13, 2023
db6bae1
refactor: CustomerRepository interface refactoring(find - Id,crateAt,…
jay-so Jul 13, 2023
b597e23
refactor: VoucherService refacotring(update Method divide Voucher Type)
jay-so Jul 13, 2023
fced138
refactor: CustomerService refactoring(crate,update, find - id, crateA…
jay-so Jul 13, 2023
60d1d0a
refactor: CustomerJdbcRepository refactoring(save, find - id, crateAt…
jay-so Jul 13, 2023
7c47aa9
refactor: schema.sql refacotring(add customer table)
jay-so Jul 13, 2023
4a273f6
feat:CustomerController(Create,Update,Read,Delete)
jay-so Jul 13, 2023
42f649b
refactor:InputView refactoring
jay-so Jul 14, 2023
1ee5042
refactor: InputView refactoring
jay-so Jul 16, 2023
f662eed
refactor:Output refactoring
jay-so Jul 16, 2023
d7b413c
Chore: mysql 의존성 추가
jay-so Jul 16, 2023
c938213
refactor: VoucherType refactoring
jay-so Jul 16, 2023
24b25fd
feat: Console Menu enum 생성
jay-so Jul 16, 2023
6bee80e
feat: VoucherMenu(CRUD) enum 추가
jay-so Jul 16, 2023
b591334
feat: Voucher 조회 메뉴(all, type, ID, createdAt) enum 생성
jay-so Jul 16, 2023
59f070d
feat: voucherDelete Menu enum 생성
jay-so Jul 16, 2023
59e4988
refactoring: 바우처와 관련된 Console View refactoring
jay-so Jul 16, 2023
14a424a
feat: Voucher와 관련된 Console 생성
jay-so Jul 16, 2023
324a8c5
refactor: Voucher 프로그램과 관련된 enum 패키지를 생성 & 분리
jay-so Jul 16, 2023
0a97825
feat: Customer와 관련된 enum (Menu,Select, Delete) 생성
jay-so Jul 16, 2023
67c521e
remove: Command enum 삭제
jay-so Jul 16, 2023
b5c9be8
feat: Voucher 프로그램, Customer 프로그램
jay-so Jul 17, 2023
cd18193
Chore: h2 DB의존성 추가, mysql 의존성 제거
jay-so Jul 17, 2023
a68efd6
rm: application.properties 제거
jay-so Jul 17, 2023
8d01a64
feat: application.yaml 파일 생성
jay-so Jul 17, 2023
7f1413d
refactoring:CustomerController의 create 메소드 수정
jay-so Jul 17, 2023
417a24f
refactor: VoucherController의 create메소드 refactoring
jay-so Jul 17, 2023
8391d8d
refactor: CustomerService의 create메소드 리팩토링
jay-so Jul 17, 2023
29c9377
refactor:VoucherService create 메소드 refactoring
jay-so Jul 17, 2023
fd8fa6d
refactor: 스펠링 오류 refactoring
jay-so Jul 17, 2023
1b36080
refactor: VoucherRepository refactoring
jay-so Jul 17, 2023
8eed838
refactoring: Output refactoring
jay-so Jul 17, 2023
aece849
refactor: ConsoleCustomer 리팩토링
jay-so Jul 17, 2023
6e42178
refactor: ConsoleApplciation refactoring
jay-so Jul 17, 2023
4b9625c
refactor: ConsoleVoucher refactoring
jay-so Jul 17, 2023
cde2b26
refactor: schema.sql 주석 제거
jay-so Jul 17, 2023
9540fc5
refactor:CustomerJdbcRepsoitory refactoring
jay-so Jul 17, 2023
77650eb
Chore: ParameterizedTest 의존성 추가
jay-so Jul 18, 2023
3caf6f1
refactor: FixedVoucherTest refactoring
jay-so Jul 18, 2023
3ba1020
refactor:FixedVoucherTest refactoring
jay-so Jul 18, 2023
3e1fecc
refactor:FixedVoucherTest refactoring
jay-so Jul 18, 2023
74c8884
refactor: RateVoucherTest refactoring
jay-so Jul 18, 2023
b614849
femove:jar파일 제거
jay-so Jul 18, 2023
ff3a646
remove: 이전 FixedDiscountVoucher, PercentDiscountVoucher 테스트 삭제
jay-so Jul 18, 2023
16c5564
refactor:FixedVoucherTest refactoring
jay-so Jul 18, 2023
64a1afc
refactor:RateVoucherTest refactoring
jay-so Jul 18, 2023
bff8d3c
feat: CustomerTest 구현
jay-so Jul 18, 2023
5f1e161
remove: 이전 VoucherControllerTest 삭제
jay-so Jul 18, 2023
36ebafa
feat: VoucherControllerTest 구현
jay-so Jul 18, 2023
377801a
feat: CustoemrJdbcRepository 테스트 추가
jay-so Jul 18, 2023
f6ec177
Chore: lombok 테스트 추가
jay-so Jul 18, 2023
92f7d04
remove: 이전 ConsoleApplication 테스트 삭제
jay-so Jul 18, 2023
6df903a
remove: VoucherController 테스트 삭제
jay-so Jul 18, 2023
1ac32b0
feat: Profile 설정 추가
jay-so Jul 18, 2023
576c14b
refactoring: application.yaml 파일 수정
jay-so Jul 18, 2023
71a078a
feat: 테스트용 application.yaml 추가
jay-so Jul 18, 2023
4df4706
revoce: 이전 VoucherService 테스트 삭제
jay-so Jul 18, 2023
054e071
feat: CustomerService 테스트 생성
jay-so Jul 18, 2023
0e1ac94
feat:VoucherJdbcRepository 테스트
jay-so Jul 18, 2023
1751735
feat:VoucherService 테스트 생성
jay-so Jul 18, 2023
0173c56
feat: voucher,customer Test tnwjd
jay-so Jul 18, 2023
a588bfc
refactor: voucher,customer repository refactoring
jay-so Jul 18, 2023
523487f
Chore:h2 DB 수정
jay-so Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ repositories {
}

dependencies {
//Text.io 설정
implementation 'org.beryx:text-io:3.3.0'

implementation 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//ParameterizedTest의존성 추가
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
//Logback 설정
implementation 'ch.qos.logback:logback-classic:1.2.6'
implementation 'ch.qos.logback:logback-core:1.2.6'

implementation 'org.springframework.boot:spring-boot-starter-jdbc'
runtimeOnly 'com.h2database:h2'

testCompileOnly 'org.projectlombok:lombok:1.18.28'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.28'
}

tasks.named('test') {
test{
useJUnitPlatform()
}
Binary file removed build/libs/springboot-basic-0.0.1-SNAPSHOT-plain.jar
Binary file not shown.
53 changes: 20 additions & 33 deletions src/main/java/com/prgrms/springbootbasic/ConsoleApplication.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
package com.prgrms.springbootbasic;

import com.prgrms.springbootbasic.controller.VoucherController;
import com.prgrms.springbootbasic.domain.Voucher;
import com.prgrms.springbootbasic.enums.Command;
import com.prgrms.springbootbasic.enums.VoucherType;
import com.prgrms.springbootbasic.enums.ConsoleMenu;
import com.prgrms.springbootbasic.view.Console;
import java.util.Map;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Profile("!test")
@Slf4j
@Component
@RequiredArgsConstructor
public class ConsoleApplication implements CommandLineRunner {

private final ConsoleVoucher consoleVoucher;
private final ConsoleCustomer consoleCustomer;
private final Console console;
private final VoucherController voucherController;

@Override
public void run(String... args) throws Exception {
console.consoleMenu();

while (true) {
String command = console.inputCommand();
Command inputCommand = Command.checkInputCommand(command);

switch (inputCommand) {
case CREATE -> createVoucher();
case LIST -> getVoucherList();
case EXIT -> {
console.printMessage("프로그램을 종료합니다.");
return;
console.printConsoleMenu();
try {
ConsoleMenu inputMenu = ConsoleMenu.of(console.inputCommand());

switch (inputMenu) {
case CUSTOMER -> consoleCustomer.menu();
case VOUCHER -> consoleVoucher.menu();
case EXIT -> {
console.printExitMessage();
return;
}
}
} catch (IllegalArgumentException e) {
log.error("명령어가 잘못 입력되었습니다.", e.getMessage());
} catch (Exception e) {
log.error("프로그램에서 오류가 발생하였습니다.", e.getMessage());
}
}
}

private void createVoucher() {
String voucherTypeInput = console.inputVoucherType();
VoucherType voucherType = VoucherType.checkVoucherType(voucherTypeInput);

long voucherDiscount = console.inputVoucherDiscount();

voucherController.createVoucher(voucherType, voucherDiscount);
console.printMessage("바우처가 생성되었습니다!");
}

private void getVoucherList() {
Map<UUID, Voucher> voucherMap = voucherController.printVoucherList();
console.printlnVoucherList(voucherMap);
}
}
128 changes: 128 additions & 0 deletions src/main/java/com/prgrms/springbootbasic/ConsoleCustomer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package com.prgrms.springbootbasic;

import com.prgrms.springbootbasic.controller.customer.CustomerController;
import com.prgrms.springbootbasic.dto.customer.request.CustomerCreateRequest;
import com.prgrms.springbootbasic.dto.customer.request.CustomerUpdateRequest;
import com.prgrms.springbootbasic.dto.customer.response.CustomerListResponse;
import com.prgrms.springbootbasic.dto.customer.response.CustomerResponse;
import com.prgrms.springbootbasic.enums.customer.CustomerDeleteMenu;
import com.prgrms.springbootbasic.enums.customer.CustomerMenu;
import com.prgrms.springbootbasic.enums.customer.CustomerSelectMenu;
import com.prgrms.springbootbasic.view.Console;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class ConsoleCustomer {

private final CustomerController customerController;
private final Console console;

public void menu() {
console.printCustomerMenu();
switch (CustomerMenu.of(console.inputCommand())) {
case CREATE -> createCustomer();
case UPDATE -> updateCustomer();
case SELECT -> selectCustomer();
case DELETE -> deleteCustomer();
}
}

//생성(Create)

private void createCustomer() {
console.printCustomerCreateMenu();

CustomerCreateRequest createRequest = console.inputCustomerCreateMessage();

customerController.create(createRequest);
console.printCompleteMessage();
}

//변경
private void updateCustomer() {
console.printCustomerUpdateByID();
UUID customerId = console.inputUUID();
CustomerUpdateRequest updateRequest = console.inputCustomerUpdateMessage(customerId);

customerController.update(updateRequest);
console.printCompleteMessage();
}


private void selectCustomer() {
console.printCustomerSelectMenu();
//선택 - Id, CreateAt, All
switch (CustomerSelectMenu.of(console.inputCommand())) {

Choose a reason for hiding this comment

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

정확히 어떤걸 의미하는지 나타내기 위해 이름을 가진 변수로 빼주는게 좋을것 같아요~

case ID -> {
console.printCustomerSelectById();
UUID customerId = console.inputUUID();

if (!customerController.checkCustomerId(customerId)) {
console.printErrorMessage("해당 ID를 가진 고객을 찾을 수 없습니다.");
} else {
Comment on lines +65 to +67

Choose a reason for hiding this comment

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

여기서 먼저 체크하지 않아도 service 계층의 findById 메소드에서 값을 찾을 수 없는 경우 exception을 throw해주면 될것 같네요

Choose a reason for hiding this comment

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

service쪽 다시 보니까 excpetion을 던져주고 있네요. check 부분은 필요 없을것 같습니다.

CustomerResponse customerResponse = customerController.findById(customerId);
System.out.println("해당 고객의 ID: " + customerResponse.getCustomerId());
System.out.println("해당 고객의 이름: " + customerResponse.getCustomerName());
System.out.println("해당 고객의 이메일: " + customerResponse.getCustomerEmail());
System.out.println("해당 고객의 생성일: " + customerResponse.getCreateAt());
hanjo8813 marked this conversation as resolved.
Show resolved Hide resolved
}
}
//생성일 순으로 조회 - 오류
case CREATEDAT -> {
console.printCutomerSelectByCreatedAt();
CustomerListResponse customerListResponse = customerController.findByCreateAt();
if (!customerListResponse.getCustomerResponseList().isEmpty()) {
console.printCustomerSelectByCreatedAt(customerListResponse);
} else {
console.printErrorMessage("현재 저장된 고객이 존재하지 않습니다.");
}
Comment on lines +79 to +83

Choose a reason for hiding this comment

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

early return을 사용해보는건 어떨까요?
그리고 가독성을 높이기 위해 조건문의 순서를 바꿔주면 좋을것 같습니다.

Suggested change
if (!customerListResponse.getCustomerResponseList().isEmpty()) {
console.printCustomerSelectByCreatedAt(customerListResponse);
} else {
console.printErrorMessage("현재 저장된 고객이 존재하지 않습니다.");
}
if (customerListResponse.getCustomerResponseList().isEmpty()) {
console.printErrorMessage("현재 저장된 고객이 존재하지 않습니다.");
break;
}
console.printCustomerSelectByCreatedAt(customerListResponse);

}
//모든 리스트 조회
case ALL -> {
CustomerListResponse customerListResponse = customerController.findAllList();
if (!customerListResponse.getCustomerResponseList().isEmpty()) {
console.printCustomerSelectAll(customerListResponse);
} else {
console.printErrorMessage("현재 저장된 고객이 없습니다.");
}
Comment on lines +88 to +92

Choose a reason for hiding this comment

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

위 리뷰처럼 더 간결하게 바꿔주세요~

}
default -> console.printErrorMessage("잘못된 Customer SelectMenu를 선택하셨습니다. 다시 확인해주세요.");

Choose a reason for hiding this comment

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

여기서 로깅 빼먹으신것 같습니다~

}
}


private void deleteCustomer() {
console.printCustomerDeleteMenu();
//선택 - id, all
switch (CustomerDeleteMenu.of(console.inputCommand())) {
case ID -> {
console.printCustomerDeleteByID();
UUID customerId = console.inputUUID();

if (!customerController.checkCustomerId(customerId)) {
console.printErrorMessage(customerId + "찾을 고객이 존재하지 않습니다.");
return;
}
if (customerController.deleteById(customerId) == 0) {
console.printErrorMessage(customerId + " 삭제하려는 고객이 저장되어있지 않아 삭제할 수 없습니다.");
return;
}
Comment on lines +107 to +114

Choose a reason for hiding this comment

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

두 로직이 같은 결과를 나타내고 있어서 함께 있을 필요가 없을것 같습니다.

그리고 해당 동작은 service 계층의 deleteById 메소드에서 수행하는게 좋을것 같습니다.

  1. 고객이 존재하는지 먼저 확인 -> 존재하지 않으면 exception
  2. 삭제

Choose a reason for hiding this comment

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

서비스쪽 다시 보고 오니 deleteById 메소드에 이미 체크를 수행하고 있네요.
view단에서 체크하는 로직은 제거해주세요~

console.printCompleteMessage();
}
case ALL -> {
console.printCustomerDeleteByAll();
customerController.deleteAll();
}
default -> {
IllegalStateException e = new IllegalStateException("프로그램 삭제 명령어 오류");
log.error("프로그램 삭제 명령어 오류", e);
throw e;
}
Comment on lines +121 to +125

Choose a reason for hiding this comment

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

여기서 로깅을 한번 한 후 다시 exception throw하면 ConsoleApplication에서 또 해당 예외를 catch해서 로그가 두번 찍히지 않을까요?

이전 PR 리뷰 피드백이 잘 이뤄지지 않았네요.
#775 (comment)

그리고 exception을 생성하는 모든 곳에서 메시지에 정확한 예외 원인을 담아주셔야합니다. (어떤 입력값이 예외를 발생시켰는지)

}
}
}
148 changes: 148 additions & 0 deletions src/main/java/com/prgrms/springbootbasic/ConsoleVoucher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.prgrms.springbootbasic;

import com.prgrms.springbootbasic.controller.voucher.VoucherController;
import com.prgrms.springbootbasic.dto.voucher.request.VoucherCreateRequest;
import com.prgrms.springbootbasic.dto.voucher.request.VoucherUpdateRequest;
import com.prgrms.springbootbasic.dto.voucher.response.VoucherListResponse;
import com.prgrms.springbootbasic.dto.voucher.response.VoucherResponse;
import com.prgrms.springbootbasic.enums.voucher.VoucherDeleteMenu;
import com.prgrms.springbootbasic.enums.voucher.VoucherMenu;
import com.prgrms.springbootbasic.enums.voucher.VoucherSelectMenu;
import com.prgrms.springbootbasic.enums.voucher.VoucherType;
import com.prgrms.springbootbasic.view.Console;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class ConsoleVoucher {

Choose a reason for hiding this comment

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

ConsoleCustomer와 중복되는 리뷰는 생략했습니다.


private final VoucherController voucherController;
private final Console console;

public void menu() {
console.printVoucherMenu();

switch (VoucherMenu.of(console.inputCommand())) {

Choose a reason for hiding this comment

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

변수로 빼주세요! (가독성)

case CREATE -> createVoucher();
case UPDATE -> updateVoucher();
case SELECT -> selectVoucher();
case DELETE -> deleteVoucher();
}
}


//생성(Create)
private void createVoucher() {
console.printVoucherCreateTypeMenu();
VoucherType type = VoucherType.of(console.inputCommand());

console.printVoucherCreateDiscountMenu();
VoucherCreateRequest createRequest = console.inputVoucherCreateMessage(type);

voucherController.create(createRequest);
console.printCompleteMessage();
}

//변경(Update)
private void updateVoucher() {
console.printVoucherUpdateMenu();
console.printVoucherUpdateById();
UUID voucherId = console.inputUUID();
VoucherUpdateRequest updateRequest = console.inputVoucherUpdateMessage(voucherId);

voucherController.update(updateRequest);
System.out.println("변경 후 금액 : " + updateRequest.getDiscount());
console.printCompleteMessage();
Comment on lines +58 to +59

Choose a reason for hiding this comment

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

출력 책임은 console 객체에!!
객체지향을 항상 생각해주세요~~

}


//읽기(Read) - 모든 바우처를 조회하려면 All,타입별로 조회를 하려면 Type, ID로 조회하려면 ID, 생성일별로 조회하려면 CreateAt을 입력
private void selectVoucher() {
console.printVoucherSelectMenu();
//선택 - Id, Type, CreateAt, All
switch (VoucherSelectMenu.of(console.inputCommand())) {
case ID -> {
console.printVoucherSelectById();
UUID voucherId = console.inputUUID();

if (!voucherController.checkVoucherId(voucherId)) {
console.printErrorMessage("해당 ID를 가진 Voucher를 찾을 수 없습니다.");
} else {
VoucherResponse voucherResponse = voucherController.findById(voucherId);
System.out.println("해당 바우처의 ID: " + voucherResponse.getVoucherId());
System.out.println("해당 바우처의 금액: " + voucherResponse.getDiscount());
System.out.println("해당 바우처의 타입: " + voucherResponse.getType());
System.out.println("해당 바우처의 생성일:" + voucherResponse.getCreateAt());
}
}
//바우처 타입
case TYPE -> {
console.printVoucherSelectByType();
VoucherType voucherType = VoucherType.of(console.inputCommand());
VoucherListResponse vouchersByType = voucherController.findByType(voucherType);
if (!vouchersByType.getVoucherResponseList().isEmpty()) {
console.printVoucherSelectByTypeList(vouchersByType);
} else {
console.printErrorMessage("해당 타입의 바우처가 존재하지 않습니다.");
}
}
//생성일 순으로 조회
case CREATEDAT -> {
VoucherListResponse voucherListResponse = voucherController.findByCreatedAt();
if (!voucherListResponse.getVoucherResponseList().isEmpty()) {
console.printVoucherSelectByCreateAt(voucherListResponse);
} else {
console.printErrorMessage("현재 저장된 바우처가 존재하지 않습니다.");
}
if (!voucherListResponse.getVoucherResponseList().isEmpty()) {
console.printVoucherSelectBYAll(voucherListResponse);
} else {

}

Comment on lines +103 to +106

Choose a reason for hiding this comment

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

코드 삭제 까먹으신것 같아요~

}
//모든 리스트 조회
case ALL -> {
VoucherListResponse voucherListResponse = voucherController.findAllList();
if (!voucherListResponse.getVoucherResponseList().isEmpty()) {
console.printVoucherSelectBYAll(voucherListResponse);
} else {
console.printErrorMessage("현재 저장된 바우처가 없습니다.");
}
}
default -> console.printErrorMessage("잘못된 voucherSelectMenu를 선택하셨습니다. 다시 확인해주세요.");
}
}

//삭제(DELET)- id, all
private void deleteVoucher() {
console.printVoucherDeleteMenu();
//선택 - id, all
switch (VoucherDeleteMenu.of(console.inputCommand())) {
case ID -> {
console.printVoucherDeleteById();
UUID voucherId = console.inputUUID();

if (voucherController.deleteById(voucherId) == 0) {
console.printErrorMessage(voucherId + " 삭제하려는 바우처가 저장되어있지 않아 삭제할 수 없습니다.");
return;
}
console.printCompleteMessage();
}
case ALL -> {
console.printVoucherDeleteAll();
voucherController.deleteAll();
console.printCompleteMessage();
}
default -> {
IllegalStateException e = new IllegalStateException("프로그램 삭제 명령어 오류");
log.error("프로그램 삭제 명령어 오류", e);
throw e;
}
}
}
Comment on lines +121 to +147

Choose a reason for hiding this comment

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

여기도 customer 쪽 리뷰 참고해서 리팩토링해주세요~

}