-
Notifications
You must be signed in to change notification settings - Fork 170
[4기 - 박세연] SpringBoot Part2 Weekly Mission 제출합니다. #777
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
Changes from all commits
61ad3c6
21a8a67
f1a7a71
03456cb
685e7db
d7c6407
30c2ff5
30b77b0
4b977a2
2d01fdf
59ff2d2
9b020b2
1be3ab2
21652c0
1a2c307
b69816e
a0d1d8b
7dac4e6
9e55e66
269c9fb
ea61bc3
169600b
6232845
581db86
9981e62
1e2b909
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 |
|---|---|---|
| @@ -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. 심화 | ||
| - [ ] 지갑 생성 | ||
| - [ ] 고객이 바우처 조회 기능 | ||
| - [ ] 고객이 보유한 바우처 제거 기능 | ||
| - [ ] 특정 바우처를 보유한 고객 조회 기능 | ||
|
|
||
|
|
||
|
|
| 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) { | ||
| 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) { | ||
|
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. 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
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. 메서드 안에 너무 많은 책임이 있는것같습니다. Request생성, 요청, 결과출력까지 너무 수정에 취약합니다. 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. 확실히 책임이 많긴 하네요. 그래서 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
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. switch로도 한 번 바꿔보시는거 추천드립니다. 가독성 더 좋은걸로 선택하시는것도 괜찮아보여요 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. 예전 우테코 프리코스에서 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
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. Response를 공유해서 쓰는건 비효율적입니다. 추후 Create와 Update가 각각 다른 값을 반환하는데 Response가 값이 같으면 요청하는쪽에서 혼란이 올 수 있습니다. 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. 처음에는 ResponseEntity처럼 공통된 값을 반환하는 것을 생각했는데 오히려 혼란이 올 수 있다는 생각을 못했네요. 수정하겠습니다! |
||
| } | ||
| } | ||
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.
가능하면 ! 조건에 부정을 두지 않는 것이 가독성에 좋습니다. isRunning = true 로 하고, false 일 때 반환하는것이 좋을거 같아요.
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.
좋은 의견 감사합니다!