Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
61ad3c6
refactor: VoucherController의 동작 역할 분리
parksey Jul 2, 2023
21a8a67
refactor: voucher 생성 및 예외처리 책임 변경
parksey Jul 2, 2023
f1a7a71
test: voucher에 대한 테스트 코드 변경
parksey Jul 2, 2023
03456cb
feat: 전체 데이터 조회 반환하는 데이터 형식 및 parsing방법 변경
parksey Jul 2, 2023
685e7db
docs: 2주차 미션 기능명세서 작성
parksey Jul 4, 2023
d7c6407
feat: db관련 의존성 추가
parksey Jul 4, 2023
30c2ff5
feat: 스키마 및 설정 추가
parksey Jul 5, 2023
30b77b0
fix: VoucherRepository insert 반환값 변경
parksey Jul 5, 2023
4b977a2
test: JdbcVoucherRepository 테스트 코드 추가
parksey Jul 5, 2023
2d01fdf
feat: Jdbc를 통한 Voucher dao 구현 (CRUD), Voucher Repo 통합 테스트 추가
parksey Jul 6, 2023
59ff2d2
test: Customer 테스트 코드 추가
parksey Jul 6, 2023
9b020b2
feat: Customer예외 처리 기능 추가
parksey Jul 6, 2023
1be3ab2
feat: Customer와 Voucher메뉴 선택 분기 추가
parksey Jul 7, 2023
21652c0
refactor: SystemWriter 클래스의 공통 기능 분리
parksey Jul 7, 2023
1a2c307
refactor: PrintMessage enum클래스의 클래스명 변경 -> PrintMessageType
parksey Jul 7, 2023
b69816e
feat: 사용자 요청에 따른 dto 및 기능 추가
parksey Jul 7, 2023
a0d1d8b
feat: 사용자 입력에 따른 VoucherManageController 기능 추가
parksey Jul 7, 2023
7dac4e6
feat: 동작에 따른 customerservice 기능 추가
parksey Jul 7, 2023
9e55e66
feat: CustomerRepository에 대한 테스트 코드 작성
parksey Jul 8, 2023
269c9fb
fix: VoucherRepository 존재하는 pk에 대한 중복 insert 예외 처리 추가
parksey Jul 8, 2023
ea61bc3
test: Customer 업데이트 테스트 코드 추가
parksey Jul 8, 2023
169600b
docs: 기능 명세서 심화 기능 추가
parksey Jul 8, 2023
6232845
feat: Customer 동작에 따른 CRUD service 기능 추가
parksey Jul 8, 2023
581db86
refactor: 불필요한 this연산자 제거 및 controller 반환값 추가
parksey Jul 8, 2023
9981e62
feat: Util 클래스 public 생성자 생성시 error throw 하도록 변환
parksey Jul 8, 2023
1e2b909
fix: 회원 생성시 날짜 오류 수정 및 Manage의 exit만 종료하게 변경
parksey Jul 8, 2023
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
86 changes: 86 additions & 0 deletions docs/2주차 기능명세서.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 2주차 기능 명세서

## [요구사항]

---

### 1.입력
> CLI (Command linke inteface)한 환경에서 실행되도록 한다.

[ 프로그램 실행 구문 ]
```
=== Manage Program ===
Type customer to select customer menu.
Type voucher to select customer menu.
Type exit to exit the program.
```

[ voucher 실행 구문 ]
```
=== Voucher Manage ===
Type exit to exit the program.
Type create to create a new voucher.
Type list to list all vouchers.
```

[ customer 실행 구문 ]
```
=== Customer Manage ===
Type exit to exit the program.
Type create to create a new customer.
Type list to list all customers.
```

### 입력 예외 추가 기능
- 입력시 `양쪽 공백`은 `삭제`
- `대소문자 상관없이` 동일한 메뉴 이름이면 사용가능

### 2. 회원
> `create`와 `list` 커맨드를 통해 회원를 생성 및 조회할 수 있다.

- `create`: 회원 생성
- `list`: 회원 조회
- customers 테이블 정의 및 추가
- CustomerRepository 추가 및 `JdbcTemplate`을 사용해서 구현
- CRUD 모든 기능 추가


## 3. 바우처
- `JdbcTemplate`을 사용해서 구현
- CRUD 모든 기능 추가

## 4. 바우처 지갑 (심화)
- 특정 고객에게 바우처를 할당할 수 있습니다.
- 고객이 어떤 바우처를 보유하고 있는지 조회할 수 있어야 합니다.
- 고객이 보유한 바우처를 제거할 수 있어야 합니다.
- 특정 바우처를 보유한 고객을 조회할 수 있어야 합니다.

<br>

## 기능

---

### 1. 입력
- [x] 회원과 바우처 선택하는 기능

### 2. 바우처
- [x] JdbcTemplate를 사용하여 Repostiroy 관리
- [x] CRUD 기능

### 3. 회원
- [x] 회원 CRUD 기능
- [x] 회원 추가
- [x] 회원 삭제
- [x] 회원 업데이트
- [x] 회원 조회
- [x] JdbcTemplate를 사용하여 Repository 관리

### 4. 심화
- [ ] 지갑 생성
- [ ] 고객이 바우처 조회 기능
- [ ] 고객이 보유한 바우처 제거 기능
- [ ] 특정 바우처를 보유한 고객 조회 기능



3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Type list to list all vouchers.
- 파일을 읽을 수 있고 리스트 조회 가능


### 3. 기타 요구사항

### 기타 요구사항
- `YAML`프러퍼티를 만들고 어떤 설정을 만들 수 있을지
- 실행가능한 `jar`파일을 생성
- `logback`을 통한 에러 파일로 기록
Expand Down
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,39 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/weekly/weekly/VoucherManageApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.weekly.weekly.voucher.controller.VoucherController;

@SpringBootApplication
public class VoucherManageApplication {

public static void main(String[] args) {

ApplicationContext context = SpringApplication.run(VoucherManageApplication.class, args);
context.getBean(VoucherController.class).start();
context.getBean(VoucherManagementController.class).start();
}

}
164 changes: 164 additions & 0 deletions src/main/java/org/weekly/weekly/VoucherManagementController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package org.weekly.weekly;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.weekly.weekly.customer.controller.CustomerController;
import org.weekly.weekly.customer.dto.request.CustomerCreationRequest;
import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest;
import org.weekly.weekly.customer.dto.response.CustomerResponse;
import org.weekly.weekly.customer.dto.response.CustomersResponse;
import org.weekly.weekly.ui.CommandLineApplication;
import org.weekly.weekly.util.CustomerMenu;
import org.weekly.weekly.util.ManageMenu;
import org.weekly.weekly.util.PrintMessageType;
import org.weekly.weekly.util.VoucherMenu;
import org.weekly.weekly.voucher.controller.VoucherController;
import org.weekly.weekly.voucher.dto.Response;
import org.weekly.weekly.voucher.dto.request.VoucherCreationRequest;

import java.util.List;

@Component
public class VoucherManagementController {
private final Logger logger = LoggerFactory.getLogger(VoucherManagementController.class);
private final CommandLineApplication commandLineApplication;
private final VoucherController voucherController;
private final CustomerController customerController;

public VoucherManagementController(CommandLineApplication commandLineApplication, VoucherController voucherController, CustomerController customerController) {
this.commandLineApplication = commandLineApplication;
this.voucherController = voucherController;
this.customerController = customerController;
}

public void start() {
boolean isExit = false;

while(!isExit) {

Choose a reason for hiding this comment

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

가능하면 ! 조건에 부정을 두지 않는 것이 가독성에 좋습니다. isRunning = true 로 하고, false 일 때 반환하는것이 좋을거 같아요.

Copy link
Author

Choose a reason for hiding this comment

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

좋은 의견 감사합니다!

try {
ManageMenu manageMenu = commandLineApplication.readManageMenu();
isExit = processManageMenuSelection(manageMenu);
} catch (RuntimeException runtimeException) {
commandLineApplication.printErrorMsg(runtimeException.getMessage());
}
}
}

private boolean processManageMenuSelection(ManageMenu manageMenu) {
if (ManageMenu.EXIT.equals(manageMenu)) {
return true;
}

if (ManageMenu.VOUCHER.equals(manageMenu)) {
VoucherMenu voucherMenu = commandLineApplication.readVoucherMenu();
processVoucherMenuSelection(voucherMenu);
return false;
}

if (ManageMenu.CUSTOMER.equals(manageMenu)){
CustomerMenu customerMenu = commandLineApplication.readCustomerMenu();
processCustomerMenuSelection(customerMenu);
return false;
}

return true;
}

private boolean processVoucherMenuSelection(VoucherMenu selectMenu) {

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.

console 기능에서 customer에 대한 기능이 추가될 때 못 바꾼 것 같습니다 바로 고칠게요!

if (VoucherMenu.CREATE.equals(selectMenu)) {
handleVoucherCreation();
return false;
}

if (VoucherMenu.LIST.equals(selectMenu)) {
handleVoucherSearch();
return false;
}


return true;
}

private void handleVoucherCreation() {
VoucherCreationRequest voucherCreationRequest = commandLineApplication.createVoucherFromInput();
Response response = voucherController.createVoucher(voucherCreationRequest);
logger.info("{}{}", PrintMessageType.CREATE_VOUCHER_SUCCESS.getMessage(),response.getResult());
commandLineApplication.printResult(response);
}

private void handleVoucherSearch() {
Response response = voucherController.getVouchers();
logger.info("{}{}", PrintMessageType.FIND_ALL_VOUCHER_SUCCESS.getMessage(), response.getResult());
commandLineApplication.printResult(response);
}
Comment on lines +83 to +94
Copy link

Choose a reason for hiding this comment

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

메서드 안에 너무 많은 책임이 있는것같습니다. Request생성, 요청, 결과출력까지 너무 수정에 취약합니다.

Copy link
Author

Choose a reason for hiding this comment

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

확실히 책임이 많긴 하네요. 그래서 handle이라는 메서드 명을 줘서 전반적인 처리를 하는 것처럼 보이게 하긴 했지만 어떻게 해결을 해야할지 애매하네요,,


private boolean processCustomerMenuSelection(CustomerMenu selectMenu) {
if (CustomerMenu.CREATE.equals(selectMenu)) {
handleCustomerCreation();
return false;
}

if (CustomerMenu.DELETE.equals(selectMenu)) {
handleCustomerDelete();
return false;
}

if (CustomerMenu.DELETE_ALL.equals(selectMenu)) {
handleCustomerDeleteAll();
return false;
}

if (CustomerMenu.FIND_ALL.equals(selectMenu)) {
handleCustomerFindAll();
return false;
}

if (CustomerMenu.FIND_DETAIL.equals(selectMenu)) {
handleFindDetail();
return false;
}

if (CustomerMenu.UPDATE.equals(selectMenu)) {
handleUpdateCustomer();
return false;
}
Comment on lines +97 to +125
Copy link

Choose a reason for hiding this comment

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

switch로도 한 번 바꿔보시는거 추천드립니다. 가독성 더 좋은걸로 선택하시는것도 괜찮아보여요

Copy link
Author

Choose a reason for hiding this comment

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

예전 우테코 프리코스에서 else를 사용하지 말라는 그런 조건이 있어서 유지하고 있었는데, 굳이 꼭 그럴 필요는 없이 가독성이 더 좋은 것을 선택해 보겠습니다!


return true;
}

private void handleCustomerCreation() {
CustomerCreationRequest customerCreation = commandLineApplication.createCustomerFromInput();
CustomerResponse customerDto = customerController.createCustomer(customerCreation);
commandLineApplication.printResult(customerDto);
}

private void handleCustomerDelete() {
CustomerUpdateRequest customerUpdateRequest = commandLineApplication.customerDetailFromInput();
customerController.deleteCustomer(customerUpdateRequest);
commandLineApplication.printDeleteMessage();
}

private void handleCustomerDeleteAll() {
customerController.deleteAllCustomer();
commandLineApplication.printDeleteMessage();
}

private void handleCustomerFindAll() {
CustomersResponse customerResponses = customerController.findAllCustomer();
commandLineApplication.printResult(customerResponses);
}

private void handleFindDetail() {
CustomerUpdateRequest customerUpdateRequest = commandLineApplication.customerDetailFromInput();
CustomerResponse customerResponse = customerController.findDetailCustomer(customerUpdateRequest);
commandLineApplication.printResult(customerResponse);
}

private void handleUpdateCustomer() {
CustomerUpdateRequest customerUpdateRequest = commandLineApplication.customerUpdateRequest();
CustomerResponse customerResponse = customerController.updateCustomer(customerUpdateRequest);
commandLineApplication.printResult(customerResponse);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.weekly.weekly.customer.controller;

import org.springframework.stereotype.Controller;
import org.weekly.weekly.customer.dto.request.CustomerCreationRequest;
import org.weekly.weekly.customer.dto.request.CustomerUpdateRequest;
import org.weekly.weekly.customer.dto.response.CustomerResponse;
import org.weekly.weekly.customer.dto.response.CustomersResponse;
import org.weekly.weekly.customer.service.CustomerService;

import java.util.List;

@Controller
public class CustomerController {

private final CustomerService customerService;

public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}

public CustomerResponse createCustomer(CustomerCreationRequest creationRequest) {
return customerService.createCustomer(creationRequest);
}

public void deleteCustomer(CustomerUpdateRequest updateRequest) {
customerService.deleteCustomer(updateRequest);
}

public void deleteAllCustomer() {
customerService.deleteAllCustomers();
}

public CustomerResponse findDetailCustomer(CustomerUpdateRequest updateRequest) {
return customerService.findDetailCustomer(updateRequest);
}

public CustomersResponse findAllCustomer() {
return customerService.findAllCustomer();
}

public CustomerResponse updateCustomer(CustomerUpdateRequest updateRequest) {
return customerService.updateCustomer(updateRequest);
Comment on lines +33 to +42
Copy link

Choose a reason for hiding this comment

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

Response를 공유해서 쓰는건 비효율적입니다. 추후 Create와 Update가 각각 다른 값을 반환하는데 Response가 값이 같으면 요청하는쪽에서 혼란이 올 수 있습니다.

Copy link
Author

Choose a reason for hiding this comment

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

처음에는 ResponseEntity처럼 공통된 값을 반환하는 것을 생각했는데 오히려 혼란이 올 수 있다는 생각을 못했네요. 수정하겠습니다!

}
}
Loading