Skip to content

[5기 박유진] SpringBoot Part3 Weekly Mission 제출합니다 #960

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

Open
wants to merge 44 commits into
base: eugene225
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b0f2acc
feat : customerId, voucherId로 고객이 가진 바우처 삭제 + 테스트
eugene225 Oct 26, 2023
f84b657
feat : voucher를 가진 고객id 목록 받기 + 테스트
eugene225 Oct 26, 2023
ecf7a48
feat : wallet mode 이넘 설정 및 전체 이넘 설정
eugene225 Oct 26, 2023
a3b39e5
feat : walletFunction 이넘 정리 + controller 연결
eugene225 Oct 26, 2023
62b9e80
refactor : view 정리
eugene225 Oct 26, 2023
4b94adb
feat : voucherId, customerId로 고객 지갑에 바우처 추가
eugene225 Oct 27, 2023
6a61ecb
refactor : view 정리
eugene225 Oct 27, 2023
3410061
refactor : import정리
eugene225 Oct 30, 2023
92318a7
refactor : wallet 도메인 수정
eugene225 Oct 30, 2023
ef30bd9
feat : wallet_customer_voucher 매핑 DB 생성
eugene225 Oct 31, 2023
79336a8
feat : voucher 관리 페이지 및 webcontroller 구성
eugene225 Nov 1, 2023
cedf9d5
feat : wallet 페이지 구성 및 controller 연결
eugene225 Nov 2, 2023
ee2afcc
feat : Wallet deleteById 구현
eugene225 Nov 2, 2023
ce1318d
feat : Voucher deleteById 기능 추가 및 컨트롤러 연결
eugene225 Nov 2, 2023
0480bd0
feat : wallet에 부여되지 않은 voucher 목록 반환 기능 추가
eugene225 Nov 2, 2023
404d696
feat : voucher edit 기능 추가 및 컨트롤러 연결
eugene225 Nov 2, 2023
595c5aa
feat : voucher policy별 조회기능 추가
eugene225 Nov 2, 2023
b53b640
feat : voucher 정보 view dto 생성
eugene225 Nov 2, 2023
0f3a065
feat : customer 생성 삭제 기능 컨트롤러 연결
eugene225 Nov 2, 2023
e46b47d
feat : 지갑을 가지지 않은 사용자 처리
eugene225 Nov 2, 2023
7b914b4
refactor : import정리
eugene225 Oct 30, 2023
90a2c45
refactor : wallet 도메인 수정
eugene225 Oct 30, 2023
7c2237d
feat : wallet_customer_voucher 매핑 DB 생성
eugene225 Oct 31, 2023
d7fddd6
feat : voucher 관리 페이지 및 webcontroller 구성
eugene225 Nov 1, 2023
b31e9fd
feat : wallet 페이지 구성 및 controller 연결
eugene225 Nov 2, 2023
103a7ff
feat : Wallet deleteById 구현
eugene225 Nov 2, 2023
1319c53
feat : Voucher deleteById 기능 추가 및 컨트롤러 연결
eugene225 Nov 2, 2023
a9f3e58
feat : wallet에 부여되지 않은 voucher 목록 반환 기능 추가
eugene225 Nov 2, 2023
7042e36
feat : voucher edit 기능 추가 및 컨트롤러 연결
eugene225 Nov 2, 2023
cc0cb03
feat : voucher policy별 조회기능 추가
eugene225 Nov 2, 2023
a4ac945
feat : voucher 정보 view dto 생성
eugene225 Nov 2, 2023
1ecaf12
feat : customer 생성 삭제 기능 컨트롤러 연결
eugene225 Nov 2, 2023
2b69413
feat : 지갑을 가지지 않은 사용자 처리
eugene225 Nov 2, 2023
63c7378
feat : rest api 바우처 전체조회
eugene225 Nov 2, 2023
4978d05
feat : rest API CRUD 기능구현
eugene225 Nov 3, 2023
58dac4f
refactor : 코드 라인 정리
eugene225 Nov 6, 2023
c9258f5
feat : commandLineRunner에 'dev' 프로파일 설정
eugene225 Nov 15, 2023
a14d001
refactor : dto 패키지 위치 변경
eugene225 Nov 15, 2023
e20a305
refactor : wallet controller - domain 분리
eugene225 Nov 15, 2023
78d31fc
refactor : wallet api 수정
eugene225 Nov 15, 2023
c5b3a06
refactor : controller - domain 분리
eugene225 Nov 16, 2023
2004ee6
refactor : voucher domain, controller 분리
eugene225 Nov 17, 2023
4eec30a
refactor : customer dto 사용해 domain, controller 분리
eugene225 Nov 17, 2023
78f070c
refactor : voucher findBy 메서드 통합
eugene225 Nov 17, 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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>

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


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

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -68,3 +79,4 @@
</build>

</project>

35 changes: 31 additions & 4 deletions src/main/java/org/prgrms/kdtspringdemo/AppController.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
package org.prgrms.kdtspringdemo;

import org.prgrms.kdtspringdemo.customer.CustomerFunction;
import org.prgrms.kdtspringdemo.customer.controller.CustomerController;
import org.prgrms.kdtspringdemo.view.InputConsole;
import org.prgrms.kdtspringdemo.view.OutputConsole;
import org.prgrms.kdtspringdemo.voucher.VoucherFunction;
import org.prgrms.kdtspringdemo.voucher.controller.VoucherController;
import org.prgrms.kdtspringdemo.wallet.WalletFunction;
import org.prgrms.kdtspringdemo.wallet.controller.WalletController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;

import java.io.IOException;

@Controller
@Profile("dev")
public class AppController implements CommandLineRunner {
private final InputConsole inputConsole;
private final OutputConsole outputConsole;
private final VoucherController voucherController;
private final CustomerController customerController;
private final WalletController walletController;
private final Logger logger = LoggerFactory.getLogger(KdtSpringDemoApplication.class);

public AppController(InputConsole inputConsole, OutputConsole outputConsole, VoucherController voucherController, CustomerController customerController) {
public AppController(InputConsole inputConsole, OutputConsole outputConsole, VoucherController voucherController, CustomerController customerController, WalletController walletController) {
this.inputConsole = inputConsole;
this.outputConsole = outputConsole;
this.voucherController = voucherController;
this.customerController = customerController;
this.walletController = walletController;
}

@Override
public void run(String... args) throws IOException {
try {
while (true) {
outputConsole.start();
outputConsole.startProgram();
String fun = inputConsole.getString();
try {
VoucherFunction.findByCode(fun).execute(voucherController);
// Mode 선택
ProgramFunction mode = ProgramFunction.findByCode(fun);
mode.execute(outputConsole);
switch (mode) {
case VOUCHER:
fun = inputConsole.getString(); //voucher 실행
VoucherFunction.findByCode(fun).execute(voucherController);
break;
case CUSTOMER:
fun = inputConsole.getString();
CustomerFunction.findByCode(fun).execute(customerController);
break;
case WALLET:
fun = inputConsole.getString();
WalletFunction.findByCode(fun).execute(walletController);
break;
case EXIT:
ProgramFunction.findByCode(fun).execute(outputConsole);
System.exit(0);
break;
}
} catch (Exception e) {
System.out.println(e.getMessage());
logger.error(e.getMessage());
}
}
} catch (Exception e) {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/org/prgrms/kdtspringdemo/ProgramFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.prgrms.kdtspringdemo;

import org.prgrms.kdtspringdemo.view.OutputConsole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

public enum ProgramFunction {
VOUCHER("voucher", "바우처 모드", OutputConsole::startVoucherMode),
CUSTOMER("customer", "고객 모드", OutputConsole::startCustomerMode),
WALLET("wallet", "지갑 모드", OutputConsole::startWalletMode),
EXIT("exit", "프로그램을 종료합니다.", OutputConsole::printProgramEnd);
private final String fun;
private final String description;
private final Consumer<OutputConsole> outputConsoleConsumer;
private final static Logger logger = LoggerFactory.getLogger(ProgramFunction.class);

ProgramFunction(String fun, String description, Consumer<OutputConsole> outputConsoleConsumer) {
this.fun = fun;
this.description = description;
this.outputConsoleConsumer = outputConsoleConsumer;
}

public static ProgramFunction findByCode(String fun) {
String lowerFun = fun.toLowerCase();
return Arrays.stream(values())
.filter(option -> option.fun.equals(lowerFun))
.findFirst()
.orElseThrow(() -> {
logger.error("해당 명령어가 존재하지 않습니다.");
return new NoSuchElementException("해당 명령어가 존재하지 않습니다.");
});
}

public void execute(OutputConsole outputConsole) {
this.outputConsoleConsumer.accept(outputConsole);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.prgrms.kdtspringdemo.customer;

import org.prgrms.kdtspringdemo.customer.controller.CustomerController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

public enum CustomerFunction {
CREATE("create", "고객 등록", CustomerController::insert),
LIST_ALL_CUSTOMERS("list", "고객 목록", CustomerController::printAllCustomers),
EXIT("exit", "voucher mode 종료", CustomerController::endCustomerMode);

private final String fun;
private final String description;
private final Consumer<CustomerController> customerControllerConsumer;
private final static Logger logger = LoggerFactory.getLogger(CustomerFunction.class);

CustomerFunction(String fun, String description, Consumer<CustomerController> customerControllerConsumer) {
this.fun = fun;
this.description = description;
this.customerControllerConsumer = customerControllerConsumer;
}

public static CustomerFunction findByCode(String fun) {
String lowerFun = fun.toLowerCase();
return Arrays.stream(values())
.filter(option -> option.fun.equals(lowerFun))
.findFirst()
.orElseThrow(() -> {
logger.error("해당 명령어가 존재하지 않습니다.");
return new NoSuchElementException("해당 명령어가 존재하지 않습니다.");
});
}

public void execute(CustomerController customerController) {
this.customerControllerConsumer.accept(customerController);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.prgrms.kdtspringdemo.customer.controller;

import org.prgrms.kdtspringdemo.customer.domain.Customer;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
import org.prgrms.kdtspringdemo.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.dto.CustomerViewDto;
import org.prgrms.kdtspringdemo.view.InputConsole;
import org.prgrms.kdtspringdemo.view.OutputConsole;
import org.prgrms.kdtspringdemo.wallet.service.WalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

import java.io.IOException;
Expand All @@ -12,14 +17,43 @@
@Controller
public class CustomerController {
private final CustomerService customerService;
private final WalletService walletService;
private final InputConsole inputConsole = new InputConsole();
private final OutputConsole outputConsole = new OutputConsole();
private final Logger logger = LoggerFactory.getLogger(CustomerController.class);

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

public void printAllBlackListCustomer() throws IOException {
List<Customer> customerList = customerService.getBlackListCustomers();
customerList.stream().forEach(customer -> outputConsole.printCustomer(customer));
public void insert() {
try {
UUID customerId = UUID.randomUUID();
outputConsole.getCustomerName();
String name = inputConsole.getString();
outputConsole.getCustomerIsBlack();
boolean isBlack = Boolean.parseBoolean(inputConsole.getString());

customerService.insert(new CustomerRequestDto(name, isBlack));
walletService.create(customerId); // 고객 생성 시 지갑 자동 생성
} catch (IOException e) {
logger.error(e.getMessage());
} catch (IllegalArgumentException e) {
logger.error("유효한 UUID 값이 아닙니다.");
}
}

public void printAllCustomers() {
customerService.getCustomerViewDtoLists().forEach(outputConsole::printCustomer);
}

public void printAllBlackListCustomer() {
List<CustomerViewDto> customerList = customerService.getBlackListCustomers();
customerList.forEach(outputConsole::printCustomer);
}

public void endCustomerMode() {
outputConsole.printCustomerModeEnd();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.prgrms.kdtspringdemo.customer.controller;

import org.prgrms.kdtspringdemo.customer.domain.Customer;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
import org.prgrms.kdtspringdemo.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.dto.CustomerViewDto;
import org.prgrms.kdtspringdemo.wallet.service.WalletService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("/customers")
public class CustomerWebController {
private final CustomerService customerService;
private final WalletService walletService;

public CustomerWebController(CustomerService customerService, WalletService walletService) {
this.customerService = customerService;
this.walletService = walletService;
}

@GetMapping
public String getAllCustomers(Model model) {
List<Customer> customerList = customerService.findAll();
List<CustomerViewDto> customerViewDtos = new ArrayList<>();
customerList.forEach(customer -> customerViewDtos.add(new CustomerViewDto(customer)));
List<CustomerViewDto> noneHaveWalletCustomers = customerService.findNoneHaveWalletCustomer();

model.addAttribute("customerList", customerViewDtos);
model.addAttribute("customers", noneHaveWalletCustomers);

return "customer";
}

@PostMapping("/create")
public String createCustomer(@ModelAttribute CustomerRequestDto customerRequestDto) {
CustomerViewDto customer = customerService.insert(customerRequestDto);
if (customer != null) walletService.create(customer.getCustomerId());
return "redirect:/customers";
}

@GetMapping("/{customerId}/createWallet")
public String createWalletForCustomer(@PathVariable UUID customerId) {
walletService.create(customerId);
return "redirect:/customers";
}

@GetMapping("/{customerId}/delete")
public String deleteVoucher(@PathVariable UUID customerId) {
customerService.deleteById(customerId);
return "redirect:/customers";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public String getName() {
public boolean isBlack() {
return isBlack;
}

@Override
public String toString() {
return "=======================\n"+
"customerId : " + customerId + "\n" +
"customer name : " + name + "\n" +
"isBlack : " + isBlack + "\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface CustomerRepository {
Optional<List<Customer>> getAllBlackList() throws IOException;
Customer insert(Customer customer);
void deleteAll();
void deleteById(UUID customerId);
List<Customer> findAll();
List<Customer> findNotHaveWalletCustomers();
List<Customer> getAllBlackList();
}
Loading