Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2d851cf
git ignore에 maven 관련 내용 추가, 강의 코드 추가
UJHa Aug 17, 2021
e10cad4
feat:미션2 콘솔 앱 구현
UJHa Aug 17, 2021
5898f08
fix:create,list 기능을 함수로 분리
UJHa Aug 17, 2021
99a878d
feat:findById 구현
UJHa Aug 17, 2021
215a432
feat:W3D3 컴포넌트 스캔 강의 내용까지 진행
UJHa Aug 18, 2021
0567649
fix:order,voucher로 패키지 분리 작업
UJHa Aug 18, 2021
66f4dc2
feat:강의 내용 따라하기
UJHa Aug 18, 2021
ff07df1
feat:VoucherRepository 저장 방식 변경(List > Map), FileVourcherRepository를 …
UJHa Aug 18, 2021
2eb3c88
feat:미션2 File 추가/조회 기능 구현
UJHa Aug 20, 2021
027209c
feat:강의내용 따라하기(Environment profile)
UJHa Aug 20, 2021
c0de96e
feat:강의내용 따라하기(YAML)
UJHa Aug 20, 2021
68b0fbc
feat:강의내용 따라하기(Resource, Profile)
UJHa Aug 21, 2021
9e3c980
feat:maven설정파일 추가
UJHa Aug 21, 2021
1a895e5
fix:Domain로직에서 VoucherRepository 수정하지 않도록 변경
UJHa Aug 21, 2021
be5206f
fix:Domain로직에서 Spring 관련 코드 노출하지 않도록 VoucherUtils 추가
UJHa Aug 21, 2021
de31b20
fix:사용자 입력 에러 값 처리, create 커맨드에 대한 안내 메세지 추가
UJHa Aug 22, 2021
c5a855f
feat:create 커맨드 실패 시의 에러 안내 메세지 추가
UJHa Aug 22, 2021
77c587a
fix:VoucherUtils > CommanadUtils로 클래스 이름 변경
UJHa Aug 22, 2021
393941e
fix:Input,Output을 메인 로직에서 분리
UJHa Aug 23, 2021
b6640bc
fix:클래스의 용도에 맞는 패키지로 이동
UJHa Aug 23, 2021
8861894
fix:command를 string 비교 대신에 enum으로 생성하도록 변경
UJHa Aug 23, 2021
053da99
fix:Voucher를 타입별 생성하도록 구조 변경
UJHa Aug 23, 2021
092f76d
feat:미션3 블랙리스트 조회 기능 구현
UJHa Aug 24, 2021
1cb7060
feat:미션3 yaml 파일에서 profile 지정해서 동작하도록 변경
UJHa Aug 24, 2021
ab1242a
feat:강의내용 따라하기(logging, SpringBoot)
UJHa Aug 26, 2021
20e3c79
feat:미션4 SpringBoot 애플리케이션 설정+코드 정리
UJHa Aug 26, 2021
1d2816d
feat:미션4 입력 에러 시 로그 파일에 기록 되도록 추가+jar 실행파일 추가
UJHa Aug 26, 2021
c80ad03
fix:customers 커맨드 시 type 일부 출력하는 내용 수정
UJHa Aug 26, 2021
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
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### maven ###
mvnw
mvnw.cmd
.mvn
Binary file added CommandApplication.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions customer_blacklist.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
normal,ea7bda51-f029-43f6-bcb2-d95afd77f23d,엄진환
black,0042406f-f5ff-4b4a-b062-02fa6fc9eaf7,AAA
normal,b7603e9e-dc0d-4376-8e7a-7bd4586954a6,BBB
normal,ce26496d-c3eb-44ed-acbd-0e5a908b2b4a,CCC
black,0042406f-f5ff-4b4a-b062-01fa6fc9eaf7,DDD
37 changes: 37 additions & 0 deletions logs/access-2021-08-26.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
18:04:05.296 [main] INFO o.p.k.a.KdtSpringDemoApplication - Starting KdtSpringDemoApplication using Java 16.0.2 on DESKTOP-8KCHBP3 with PID 3312 (C:\Users\Qup\Documents\GitHub\w3-SpringBoot\target\classes started by Qup in C:\Users\Qup\Documents\GitHub\w3-SpringBoot)
18:04:05.298 [main] DEBUG o.p.k.a.KdtSpringDemoApplication - Running with Spring Boot v2.5.4, Spring v5.3.9
18:04:05.298 [main] INFO o.p.k.a.KdtSpringDemoApplication - The following profiles are active: dev
18:04:05.823 [main] DEBUG o.p.k.order.OrderProperties - version -> v1.0
18:04:05.823 [main] DEBUG o.p.k.order.OrderProperties - minimumOrderAmount -> 1
18:04:05.823 [main] DEBUG o.p.k.order.OrderProperties - supportVendors -> [a, b, c, d]
18:04:05.823 [main] DEBUG o.p.k.order.OrderProperties - description -> line 1 hello world
line 2 xxxx
line 3
18:04:05.909 [main] INFO o.p.k.a.KdtSpringDemoApplication - Started KdtSpringDemoApplication in 1.124 seconds (JVM running for 4.021)
18:11:16.195 [main] INFO o.p.k.a.KdtSpringDemoApplication - Starting KdtSpringDemoApplication using Java 16.0.2 on DESKTOP-8KCHBP3 with PID 22428 (C:\Users\Qup\Documents\GitHub\w3-SpringBoot\target\classes started by Qup in C:\Users\Qup\Documents\GitHub\w3-SpringBoot)
18:11:16.198 [main] DEBUG o.p.k.a.KdtSpringDemoApplication - Running with Spring Boot v2.5.4, Spring v5.3.9
18:11:16.199 [main] INFO o.p.k.a.KdtSpringDemoApplication - The following profiles are active: dev
18:11:16.768 [main] DEBUG o.p.k.order.OrderProperties - version -> v1.0
18:11:16.768 [main] DEBUG o.p.k.order.OrderProperties - minimumOrderAmount -> 1
18:11:16.769 [main] DEBUG o.p.k.order.OrderProperties - supportVendors -> [a, b, c, d]
18:11:16.769 [main] DEBUG o.p.k.order.OrderProperties - description -> line 1 hello world
line 2 xxxx
line 3
18:11:16.856 [main] INFO o.p.k.a.KdtSpringDemoApplication - Started KdtSpringDemoApplication in 1.13 seconds (JVM running for 2.362)
18:21:51.419 [main] INFO o.p.k.a.KdtSpringDemoApplication - Starting KdtSpringDemoApplication using Java 16.0.2 on DESKTOP-8KCHBP3 with PID 20888 (C:\Users\Qup\Documents\GitHub\w3-SpringBoot\target\classes started by Qup in C:\Users\Qup\Documents\GitHub\w3-SpringBoot)
18:21:51.422 [main] DEBUG o.p.k.a.KdtSpringDemoApplication - Running with Spring Boot v2.5.4, Spring v5.3.9
18:21:51.422 [main] INFO o.p.k.a.KdtSpringDemoApplication - The following profiles are active: dev
18:21:52.015 [main] DEBUG o.p.k.order.OrderProperties - version -> v1.0
18:21:52.015 [main] DEBUG o.p.k.order.OrderProperties - minimumOrderAmount -> 1
18:21:52.015 [main] DEBUG o.p.k.order.OrderProperties - supportVendors -> [a, b, c, d]
18:21:52.016 [main] DEBUG o.p.k.order.OrderProperties - description -> line 1 hello world
line 2 xxxx
line 3
18:21:52.099 [main] INFO o.p.k.a.KdtSpringDemoApplication - Started KdtSpringDemoApplication in 1.147 seconds (JVM running for 2.116)
18:21:52.102 [main] WARN o.p.k.a.KdtSpringDemoApplication - logger name -> org.prgrms.kdtspringdemo.KdtSpringDemoApplication
18:21:52.103 [main] ERROR o.p.k.a.KdtSpringDemoApplication - version -> v1.0
18:21:52.104 [main] ERROR o.p.k.a.KdtSpringDemoApplication - minimumOrderAmount -> 1
18:21:52.104 [main] INFO o.p.k.a.KdtSpringDemoApplication - supportVendors -> [a, b, c, d]
18:21:52.104 [main] DEBUG o.p.k.a.KdtSpringDemoApplication - description -> line 1 hello world
line 2 xxxx
line 3
1 change: 1 addition & 0 deletions logs/access-2021-08-27.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01:00:29.550 [main] ERROR o.p.kdtspringdemo.console.Console - Invalid command type. Your input -> asdf
47 changes: 47 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.prgrms.kdtspringdemo</groupId>
<artifactId>w3-SpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>w3-SpringBoot</name>
<description>w3-SpringBoot</description>
<properties>
<java.version>16</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
5 changes: 5 additions & 0 deletions src/main/java/org/prgrms/kdtspringdemo/CommandType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.prgrms.kdtspringdemo;

public enum CommandType {
CREATE, LIST, CUSTOMERS, BLACKS, EXIT, ERROR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.prgrms.kdtspringdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class KdtSpringDemoApplication {
public static void main(String[] args) {
SpringApplication.run(KdtSpringDemoApplication.class, args);
}

}
45 changes: 45 additions & 0 deletions src/main/java/org/prgrms/kdtspringdemo/VoucherType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.prgrms.kdtspringdemo;

import org.prgrms.kdtspringdemo.voucher.FixedAmountVoucher;
import org.prgrms.kdtspringdemo.voucher.PercentDiscountVoucher;
import org.prgrms.kdtspringdemo.voucher.Voucher;

import java.util.Arrays;
import java.util.Optional;
import java.util.UUID;

public enum VoucherType {
FIXED_AMOUNT("F"), PERCENT_DISCOUNT("P");

private final String inputCommand;

VoucherType(String p) {
this.inputCommand = p;
}

public static boolean isInVoucherType(String command) {
long count = Arrays.stream(VoucherType.values())
.filter(voucherType -> voucherType.inputCommand.equals(command))
.count();
return count != 0;
}

private static VoucherType findByCommand(String command) {
return Arrays.stream(VoucherType.values())
.filter(voucherType -> voucherType.inputCommand.equals(command))
.findAny()
.orElseThrow(IllegalArgumentException::new);

Choose a reason for hiding this comment

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

잘못 입력했을때 예외를 던지는 것 말고 친절하게 다시 command를 작성할 수 있도록 바꿔볼까요?

}

public static Optional<Voucher> getVoucher(String inputCommand, long value) {

Choose a reason for hiding this comment

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

음..비즈니스 로직상 getVoucher 라는 naming 보다는 createVoucher 가 나을 것 같고
그러면 새로 new 하는 로직이니, Optional이지 않아도 됩니다.

Optional<Voucher> voucher = Optional.empty();

switch (findByCommand(inputCommand)) {
case FIXED_AMOUNT -> voucher = Optional.of(new FixedAmountVoucher(UUID.randomUUID(), value));
case PERCENT_DISCOUNT -> voucher = Optional.of(new PercentDiscountVoucher(UUID.randomUUID(), value));
}
return voucher;
}

;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prgrms.kdtspringdemo.application;

import org.prgrms.kdtspringdemo.console.Console;
import org.prgrms.kdtspringdemo.console.CustomerOperator;
import org.prgrms.kdtspringdemo.console.VoucherOperator;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommandLineApplication implements ApplicationRunner {
private final VoucherOperator voucherOperator;

Choose a reason for hiding this comment

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

여기서 구현체로 타입을 선언하는 것이 아니라 다형성을 위해 인터페이스 타입으로 선언합니다.


public CommandLineApplication(VoucherOperator voucherOperator) {
this.voucherOperator = voucherOperator;
}

@Override
public void run(ApplicationArguments args) throws Exception {
new ConsoleApp(new Console(), voucherOperator, new CustomerOperator());
}
}
27 changes: 27 additions & 0 deletions src/main/java/org/prgrms/kdtspringdemo/application/ConsoleApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.prgrms.kdtspringdemo.application;

import org.prgrms.kdtspringdemo.CommandType;
import org.prgrms.kdtspringdemo.console.Console;
import org.prgrms.kdtspringdemo.console.CustomerOperator;
import org.prgrms.kdtspringdemo.console.VoucherOperator;

public class ConsoleApp {
public ConsoleApp(Console console, VoucherOperator voucherOperator, CustomerOperator customerOperator) {
console.printStartAppInfo();

while (true) {
CommandType command = console.getInputCommand();
switch (command) {
case CREATE -> {
console.printCreateTypes();
String[] createCommand = console.getCreateLine().split(" ");
voucherOperator.create(createCommand);
}
case CUSTOMERS -> customerOperator.printAll();
case BLACKS -> customerOperator.printBlacklist();
case LIST -> voucherOperator.printAll();
case EXIT -> System.exit(0);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.prgrms.kdtspringdemo.configuration;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
@ComponentScan(basePackages = {
"org.prgrms.kdtspringdemo.order",
"org.prgrms.kdtspringdemo.voucher",
"org.prgrms.kdtspringdemo.customer",
"org.prgrms.kdtspringdemo.configuration"
})
@PropertySource(value = "application.yaml", factory = YamlPropertiesFactory.class)
@EnableConfigurationProperties
public class AppConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prgrms.kdtspringdemo.configuration;

import org.springframework.context.annotation.Configuration;

@Configuration
public class AwsConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prgrms.kdtspringdemo.configuration;

import org.springframework.context.annotation.Configuration;

@Configuration
public class GcpConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prgrms.kdtspringdemo.configuration;

import org.springframework.context.annotation.Configuration;

@Configuration
public class SecurityConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.prgrms.kdtspringdemo.configuration;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;

import java.io.IOException;

public class YamlPropertiesFactory implements PropertySourceFactory {
@Override
public PropertySource<?> createPropertySource(String s, EncodedResource encodedResource) throws IOException {
var yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
yamlPropertiesFactoryBean.setResources(encodedResource.getResource());

var properties = yamlPropertiesFactoryBean.getObject();
return new PropertiesPropertySource(encodedResource.getResource().getFilename(), properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.prgrms.kdtspringdemo.console;

public interface CommandOperator {
public void create(String[] splitList);

public void printAll();
}
72 changes: 72 additions & 0 deletions src/main/java/org/prgrms/kdtspringdemo/console/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.prgrms.kdtspringdemo.console;

import org.prgrms.kdtspringdemo.CommandType;
import org.prgrms.kdtspringdemo.io.*;
import org.prgrms.kdtspringdemo.order.OrderProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.MessageFormat;
import java.util.Scanner;

public class Console implements Input, Output {
private final static Logger logger = LoggerFactory.getLogger(Console.class);
private Scanner input;

public Console() {
this.input = new Scanner(System.in);
}

@Override
public void printStartAppInfo() {
System.out.println("=== Voucher Program ===");
printCommandList();
}

@Override
public void printCommandList() {
System.out.println("""
Type exit to exit the program.
Type create to create a new voucher.
Type list to list all vouchers.
Type customers to list all customers
Type blacks to list all blacklist customers""");
}

@Override
public void printCommandError(String command) {
System.out.println(MessageFormat.format("[ERROR]Invalid command type \nYour input : {0}", command));
printCommandList();
System.out.println("=================");
}

@Override
public void printCreateTypes() {
System.out.println("""
input voucher info
<vouhcerType> <data>
voucherType
\tP : FixedAmountVoucher
\tF : PercentDiscountVoucher
data is long value
ex) P 10""");
}

@Override
public CommandType getInputCommand() {
;
String command = input.nextLine();
try {
return CommandType.valueOf(command.toUpperCase());
} catch (IllegalArgumentException e) {
logger.error(MessageFormat.format("Invalid command type. Your input -> {0}", command));
printCommandError(command);
return CommandType.ERROR;
}
}

@Override
public String getCreateLine() {
return input.nextLine();
}
}
Loading