Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
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>

33 changes: 29 additions & 4 deletions src/main/java/org/prgrms/kdtspringdemo/AppController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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;
Expand All @@ -18,25 +21,47 @@ public class AppController implements CommandLineRunner {
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,42 @@
package org.prgrms.kdtspringdemo.customer;

import org.prgrms.kdtspringdemo.customer.controller.CustomerController;
import org.prgrms.kdtspringdemo.voucher.controller.VoucherController;
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.domain.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
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 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() {
List<Customer> customerList = customerService.findAll();
customerList.stream().forEach(customer -> outputConsole.printCustomer(customer));
}
public void printAllBlackListCustomer() throws IOException {
List<Customer> customerList = customerService.getBlackListCustomers();
customerList.stream().forEach(customer -> outputConsole.printCustomer(customer));
}

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

import org.prgrms.kdtspringdemo.customer.domain.Customer;
import org.prgrms.kdtspringdemo.customer.domain.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.customer.domain.dto.CustomerViewDto;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
import org.prgrms.kdtspringdemo.wallet.service.WalletService;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
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.stream().forEach(customer -> customerViewDtos.add(new CustomerViewDto(customer)));
List<Customer> noneHaveWalletCustomers = customerService.findNoneHaveWalletCustomer();

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

return "customer";
}

@PostMapping("/create")
public String createCustomer(@ModelAttribute CustomerRequestDto customerRequestDto) {
Customer 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
@@ -0,0 +1,27 @@
package org.prgrms.kdtspringdemo.customer.domain.dto;

public class CustomerRequestDto {
private String name;
private boolean isBlack;

public CustomerRequestDto(String name, boolean isBlack) {
this.name = name;
this.isBlack = isBlack;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isBlack() {
return isBlack;
}

public void setBlack(boolean black) {
isBlack = black;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.prgrms.kdtspringdemo.customer.domain.dto;

import org.prgrms.kdtspringdemo.customer.domain.Customer;

import java.util.UUID;

public class CustomerViewDto {
private UUID customerId;
private String name;
private boolean isBlack;

public CustomerViewDto(UUID customerId, String name, boolean isBlack) {
this.customerId = customerId;
this.name = name;
this.isBlack = isBlack;
}

public CustomerViewDto(Customer customer) {
this.customerId = customer.getCustomerId();
this.name = customer.getName();
this.isBlack = customer.isBlack();
}

@Override
public String toString() {
return "customerId =" + customerId +
" / name ='" + name + '\'' +
" / isBlack =" + isBlack;
}

public UUID getCustomerId() {
return customerId;
}

public void setCustomerId(UUID customerId) {
this.customerId = customerId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isBlack() {
return isBlack;
}

public void setBlack(boolean black) {
isBlack = black;
}
}
Loading