From d8206b484a28260e97d423d03ba780dacebfafff Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 13 Oct 2023 16:30:44 +0900 Subject: [PATCH 001/134] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- voucher-management-system/.gitignore | 37 +++ voucher-management-system/build.gradle | 25 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 63721 bytes .../gradle/wrapper/gradle-wrapper.properties | 7 + voucher-management-system/gradlew | 249 ++++++++++++++++++ voucher-management-system/gradlew.bat | 92 +++++++ voucher-management-system/settings.gradle | 1 + .../VoucherManagementSystemApplication.java | 13 + .../src/main/resources/application.properties | 1 + ...ucherManagementSystemApplicationTests.java | 13 + 10 files changed, 438 insertions(+) create mode 100644 voucher-management-system/.gitignore create mode 100644 voucher-management-system/build.gradle create mode 100644 voucher-management-system/gradle/wrapper/gradle-wrapper.jar create mode 100644 voucher-management-system/gradle/wrapper/gradle-wrapper.properties create mode 100755 voucher-management-system/gradlew create mode 100644 voucher-management-system/gradlew.bat create mode 100644 voucher-management-system/settings.gradle create mode 100644 voucher-management-system/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java create mode 100644 voucher-management-system/src/main/resources/application.properties create mode 100644 voucher-management-system/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java diff --git a/voucher-management-system/.gitignore b/voucher-management-system/.gitignore new file mode 100644 index 0000000000..c2065bc262 --- /dev/null +++ b/voucher-management-system/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/voucher-management-system/build.gradle b/voucher-management-system/build.gradle new file mode 100644 index 0000000000..407928b63f --- /dev/null +++ b/voucher-management-system/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.4' + id 'io.spring.dependency-management' version '1.1.3' +} + +group = 'team.marco' +version = '0.0.1-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/voucher-management-system/gradle/wrapper/gradle-wrapper.jar b/voucher-management-system/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..7f93135c49b765f8051ef9d0a6055ff8e46073d8 GIT binary patch literal 63721 zcmb5Wb9gP!wgnp7wrv|bwr$&XvSZt}Z6`anZSUAlc9NHKf9JdJ;NJVr`=eI(_pMp0 zy1VAAG3FfAOI`{X1O)&90s;U4K;XLp008~hCjbEC_fbYfS%6kTR+JtXK>nW$ZR+`W ze|#J8f4A@M|F5BpfUJb5h>|j$jOe}0oE!`Zf6fM>CR?!y@zU(cL8NsKk`a z6tx5mAkdjD;J=LcJ;;Aw8p!v#ouk>mUDZF@ zK>yvw%+bKu+T{Nk@LZ;zkYy0HBKw06_IWcMHo*0HKpTsEFZhn5qCHH9j z)|XpN&{`!0a>Vl+PmdQc)Yg4A(AG-z!+@Q#eHr&g<9D?7E)_aEB?s_rx>UE9TUq|? z;(ggJt>9l?C|zoO@5)tu?EV0x_7T17q4fF-q3{yZ^ipUbKcRZ4Qftd!xO(#UGhb2y>?*@{xq%`(-`2T^vc=#< zx!+@4pRdk&*1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lg+cX)NfazRu z5D)~HA^(u%w^cz+@2@_#S|u>GpB+j4KzQ^&Wcl9f z&hG#bCA(Yk0D&t&aJE^xME^&E-&xGHhXn%}psEIj641H+Nl-}boj;)Zt*t(4wZ5DN z@GXF$bL=&pBq-#vkTkh>7hl%K5|3 z{`Vn9b$iR-SoGENp}bn4;fR3>9sA%X2@1L3aE9yTra;Wb#_`xWwLSLdfu+PAu+o3| zGVnpzPr=ch{uuoHjtw7+_!L_2;knQ!DuDl0R`|%jr+}jFzXtrHIKc323?JO{l&;VF z*L1+}JU7%QJOg|5|Tc|D8fN zJORAg=_vsy{ak|o);@)Yh8Lkcg@$FG3k@ep36BRa^>~UmnRPziS>Z=`Jb2x*Q#`%A zU*i3&Vg?TluO@X0O;r2Jl6LKLUOVhSqg1*qOt^|8*c7 zo(298@+r$k_wQNGHv{|$tW(T8L+4_`FQ{kEW5Jgg{yf7ey4ss_(SNKfz(N9lx&a;< je(UuV8hP?p&}TPdm1I$XmG#(RzlD&B2izSj9sl%y5~4qc literal 0 HcmV?d00001 diff --git a/voucher-management-system/gradle/wrapper/gradle-wrapper.properties b/voucher-management-system/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..ac72c34e8a --- /dev/null +++ b/voucher-management-system/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/voucher-management-system/gradlew b/voucher-management-system/gradlew new file mode 100755 index 0000000000..0adc8e1a53 --- /dev/null +++ b/voucher-management-system/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/voucher-management-system/gradlew.bat b/voucher-management-system/gradlew.bat new file mode 100644 index 0000000000..6689b85bee --- /dev/null +++ b/voucher-management-system/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/voucher-management-system/settings.gradle b/voucher-management-system/settings.gradle new file mode 100644 index 0000000000..d6396d13ef --- /dev/null +++ b/voucher-management-system/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'voucher-management-system' diff --git a/voucher-management-system/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/voucher-management-system/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java new file mode 100644 index 0000000000..8574685175 --- /dev/null +++ b/voucher-management-system/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -0,0 +1,13 @@ +package team.marco.vouchermanagementsystem; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class VoucherManagementSystemApplication { + + public static void main(String[] args) { + SpringApplication.run(VoucherManagementSystemApplication.class, args); + } + +} diff --git a/voucher-management-system/src/main/resources/application.properties b/voucher-management-system/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/voucher-management-system/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/voucher-management-system/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java b/voucher-management-system/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java new file mode 100644 index 0000000000..22e09505f3 --- /dev/null +++ b/voucher-management-system/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java @@ -0,0 +1,13 @@ +package team.marco.vouchermanagementsystem; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class VoucherManagementSystemApplicationTests { + + @Test + void contextLoads() { + } + +} From 7a43a1468794c57399a2278d348231c1761ac763 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 13 Oct 2023 16:45:09 +0900 Subject: [PATCH 002/134] =?UTF-8?q?chore:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=EC=A1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes .../.gitignore => .gitignore | 0 .../build.gradle => build.gradle | 0 .../gradle => gradle}/wrapper/gradle-wrapper.jar | Bin .../wrapper/gradle-wrapper.properties | 0 voucher-management-system/gradlew => gradlew | 0 .../gradlew.bat => gradlew.bat | 0 .../settings.gradle => settings.gradle | 0 .../VoucherManagementSystemApplication.java | 0 .../main/resources/application.properties | 0 .../VoucherManagementSystemApplicationTests.java | 0 11 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store rename voucher-management-system/.gitignore => .gitignore (100%) rename voucher-management-system/build.gradle => build.gradle (100%) rename {voucher-management-system/gradle => gradle}/wrapper/gradle-wrapper.jar (100%) rename {voucher-management-system/gradle => gradle}/wrapper/gradle-wrapper.properties (100%) rename voucher-management-system/gradlew => gradlew (100%) rename voucher-management-system/gradlew.bat => gradlew.bat (100%) rename voucher-management-system/settings.gradle => settings.gradle (100%) rename {voucher-management-system/src => src}/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java (100%) rename {voucher-management-system/src => src}/main/resources/application.properties (100%) rename {voucher-management-system/src => src}/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java (100%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b5a41f1c2698c185f9260e7a520f5ddf7fc20d94 GIT binary patch literal 6148 zcmeHK+e!m55Ixft?M1MUz6kpT1^-}MT2N3B{Q=#!EQQrVZSi&A{Re-+@AFB|B(dzK z?W>5)EXhf-XEKu$*lYmEXfwM2`T*K2ij5AdJ*Mxq>{ug=bcv#KToub{RxC62bwabh zuYm4d3j^d>U>)t>knaXx&fG$}KRj}CJY$I!=5?P&9{HRg!-o6<>{tDA5D`iz>==ULEQA`7t9^I#dmAe8ETO4-Aw)^!bCOSY&1C|~+LKE*w^sW-F7!qy{ z;@$Z^4gAuhcZayhoF_z&eom9=~ Date: Fri, 13 Oct 2023 16:48:40 +0900 Subject: [PATCH 003/134] =?UTF-8?q?docs:=20gitignore=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 224 +++++++++++++++++++++++++++++++++++++++++++++-------- HELP.md | 20 +++++ 3 files changed, 210 insertions(+), 34 deletions(-) delete mode 100644 .DS_Store create mode 100644 HELP.md diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index b5a41f1c2698c185f9260e7a520f5ddf7fc20d94..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK+e!m55Ixft?M1MUz6kpT1^-}MT2N3B{Q=#!EQQrVZSi&A{Re-+@AFB|B(dzK z?W>5)EXhf-XEKu$*lYmEXfwM2`T*K2ij5AdJ*Mxq>{ug=bcv#KToub{RxC62bwabh zuYm4d3j^d>U>)t>knaXx&fG$}KRj}CJY$I!=5?P&9{HRg!-o6<>{tDA5D`iz>==ULEQA`7t9^I#dmAe8ETO4-Aw)^!bCOSY&1C|~+LKE*w^sW-F7!qy{ z;@$Z^4gAuhcZayhoF_z&eom9=~ Date: Fri, 13 Oct 2023 17:34:39 +0900 Subject: [PATCH 004/134] =?UTF-8?q?feat:=20=EB=AA=85=EB=A0=B9=EC=96=B4=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/Console.java | 38 +++++++++++++++++++ .../VoucherApplication.java | 25 ++++++++++++ .../VoucherManagementSystemApplication.java | 8 ++-- 3 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/Console.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/Console.java b/src/main/java/team/marco/vouchermanagementsystem/Console.java new file mode 100644 index 0000000000..cb9140f8d9 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/Console.java @@ -0,0 +1,38 @@ +package team.marco.vouchermanagementsystem; + +import org.springframework.stereotype.Component; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +@Component +public class Console { + private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + + public void printCommandManual() { + System.out.println(""" + === Voucher Program === + Type exit to exit the program. + Type create to create a new voucher. + Type list to list all vouchers. + """); + } + + public String readString() { + System.out.print("> "); + String input = readLine(); + System.out.println(); + + return input; + } + + private String readLine() { + try { + return reader.readLine(); + } catch (IOException e) { + throw new RuntimeException("입력을 읽어올 수 없습니다."); + } + } + +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java new file mode 100644 index 0000000000..f52165d5ef --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -0,0 +1,25 @@ +package team.marco.vouchermanagementsystem; + +import org.springframework.stereotype.Component; + +@Component +public class VoucherApplication { + private final Console console; + + public VoucherApplication(Console console) { + this.console = console; + } + + public void run() { + while (true) { + console.printCommandManual(); + String input = console.readString(); + + if(input.equals("exit")) { + System.out.println("종료 되었습니다."); + + return; + } + } + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 8574685175..38c7f447a6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -2,12 +2,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; @SpringBootApplication public class VoucherManagementSystemApplication { - public static void main(String[] args) { - SpringApplication.run(VoucherManagementSystemApplication.class, args); - } + ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); + VoucherApplication application = context.getBean(VoucherApplication.class); + application.run(); + } } From b8b7a702dcad32bf851eaedd4a5db580f68fa451 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Fri, 13 Oct 2023 18:18:20 +0900 Subject: [PATCH 005/134] =?UTF-8?q?style:=20IO=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/team/marco/vouchermanagementsystem/Console.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/Console.java b/src/main/java/team/marco/vouchermanagementsystem/Console.java index cb9140f8d9..0be2aff722 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/Console.java @@ -31,7 +31,7 @@ private String readLine() { try { return reader.readLine(); } catch (IOException e) { - throw new RuntimeException("입력을 읽어올 수 없습니다."); + throw new RuntimeException("unreadable input"); } } From 3c89d6992c91103c45ac8835446c8f34765827c6 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Fri, 13 Oct 2023 18:19:21 +0900 Subject: [PATCH 006/134] =?UTF-8?q?feat:=20=EB=AA=85=EB=A0=B9=EC=96=B4=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/CommandType.java | 18 ++++++++++ .../VoucherApplication.java | 35 ++++++++++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/CommandType.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java new file mode 100644 index 0000000000..e7ab46c899 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java @@ -0,0 +1,18 @@ +package team.marco.vouchermanagementsystem; + +import java.util.Arrays; + +public enum CommandType { + CREATE, LIST, EXIT; + + public static CommandType getCommandType(String input) { + return Arrays.stream(CommandType.values()) + .filter(commandType -> commandType.isMatch(input)) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } + + private boolean isMatch(String input) { + return this.name().toLowerCase().equals(input); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index f52165d5ef..b66a693e70 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -11,15 +11,40 @@ public VoucherApplication(Console console) { } public void run() { - while (true) { - console.printCommandManual(); - String input = console.readString(); + console.printCommandManual(); + String input = console.readString(); - if(input.equals("exit")) { - System.out.println("종료 되었습니다."); + try { + CommandType commandType = CommandType.getCommandType(input); + runCommand(commandType); + } catch (IllegalArgumentException e) { + System.out.printf("'%s' is invalid command%n%n", input); + run(); + } + } + + public void runCommand(CommandType commandType) { + switch (commandType) { + case CREATE -> createVoucher(); + case LIST -> getVoucherList(); + case EXIT -> { + close(); return; } } + + run(); + } + + private void createVoucher() { + } + + private void getVoucherList() { + } + + private void close() { + // TODO: 데이터 저장 기능 + System.out.println("exit program..."); } } From 956c63e49abf822ab6c0938bba71db72c8591f5d Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 00:17:48 +0900 Subject: [PATCH 007/134] =?UTF-8?q?feat:=20VoucherService=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/CommandType.java | 3 ++- .../VoucherApplication.java | 27 ++++++++++++++++--- .../VoucherService.java | 10 +++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/VoucherService.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java index e7ab46c899..1472970169 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java @@ -1,5 +1,6 @@ package team.marco.vouchermanagementsystem; +import java.text.MessageFormat; import java.util.Arrays; public enum CommandType { @@ -9,7 +10,7 @@ public static CommandType getCommandType(String input) { return Arrays.stream(CommandType.values()) .filter(commandType -> commandType.isMatch(input)) .findFirst() - .orElseThrow(IllegalArgumentException::new); + .orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("{0} is invalid command", input))); } private boolean isMatch(String input) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index b66a693e70..1fe2e139a5 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -3,11 +3,13 @@ import org.springframework.stereotype.Component; @Component -public class VoucherApplication { +public class VoucherApplication { private final Console console; + private final VoucherService voucherService; - public VoucherApplication(Console console) { + public VoucherApplication(Console console, VoucherService service) { this.console = console; + this.voucherService = service; } public void run() { @@ -19,8 +21,9 @@ public void run() { runCommand(commandType); } catch (IllegalArgumentException e) { System.out.printf("'%s' is invalid command%n%n", input); - run(); } + + run(); } public void runCommand(CommandType commandType) { @@ -38,6 +41,24 @@ public void runCommand(CommandType commandType) { } private void createVoucher() { + console.printVoucherTypes(); + int selected = console.readInt(); + + switch (selected) { + case 0 -> createFixedAmountVoucher(); + case 1 -> createPercentDiscountVoucher(); + default -> { throw new RuntimeException("올바르지 않은 입력입니다."); } + } + } + + private void createPercentDiscountVoucher() { + int percent = console.readInt("할인율을 입력해 주세요."); + voucherService.createPercentDiscountVoucher(percent); + } + + private void createFixedAmountVoucher() { + int amount = console.readInt("할인 금액을 입력해 주세요."); + voucherService.createFixedAmountVoucher(amount); } private void getVoucherList() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java new file mode 100644 index 0000000000..d43af4396d --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java @@ -0,0 +1,10 @@ +package team.marco.vouchermanagementsystem; + +import org.springframework.stereotype.Service; + +@Service +public class VoucherService { + + public void createFixedAmountVoucher(int amount) {} + public void createPercentDiscountVoucher(int percent) {} +} From a90c920d1f66712c2478a5fb9abb22231fac4e57 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 00:19:54 +0900 Subject: [PATCH 008/134] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20Console=EC=97=90=20=EB=AA=A8=EC=95=84?= =?UTF-8?q?=EC=84=9C=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/Console.java | 27 +++++++++++++++++++ .../VoucherApplication.java | 4 +-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/Console.java b/src/main/java/team/marco/vouchermanagementsystem/Console.java index 0be2aff722..0f8d5ce261 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/Console.java @@ -27,6 +27,19 @@ public String readString() { return input; } + public int readInt() { + try { + return Integer.parseInt(readString()); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("숫자만 입력하실 수 있습니다."); + } + } + + public int readInt(String prompt) { + System.out.println(prompt + "\n"); + return readInt(); + } + private String readLine() { try { return reader.readLine(); @@ -35,4 +48,18 @@ private String readLine() { } } + public void printVoucherTypes() { + System.out.println(""" + Type 0 to create fixed amount voucher. + Type 1 to create percent discount voucher. + """); + } + + public void printError(Exception e) { + if(e instanceof NumberFormatException) { + System.out.println("숫자를 입력해 주세요."); + } else { + System.out.println(e.getMessage()); + } + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 1fe2e139a5..10a5cae573 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -19,8 +19,8 @@ public void run() { try { CommandType commandType = CommandType.getCommandType(input); runCommand(commandType); - } catch (IllegalArgumentException e) { - System.out.printf("'%s' is invalid command%n%n", input); + } catch (Exception e) { + console.printError(e); } run(); From eab04ca6e6d2a1920dcaa979679501951b08a3a4 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 00:56:14 +0900 Subject: [PATCH 009/134] =?UTF-8?q?feat:=20Voucher=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/FixedAmountVoucher.java | 13 +++++++++++++ .../PercentDiscountVoucher.java | 13 +++++++++++++ .../team/marco/vouchermanagementsystem/Voucher.java | 4 ++++ 3 files changed, 30 insertions(+) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/Voucher.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java new file mode 100644 index 0000000000..67705a86d1 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java @@ -0,0 +1,13 @@ +package team.marco.vouchermanagementsystem; + +import java.util.UUID; + +public class FixedAmountVoucher implements Voucher { + private final UUID id; + private final int amount; + + public FixedAmountVoucher(int amount) { + this.id = UUID.randomUUID(); + this.amount = amount; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java new file mode 100644 index 0000000000..a5b6f46e68 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java @@ -0,0 +1,13 @@ +package team.marco.vouchermanagementsystem; + +import java.util.UUID; + +public class PercentDiscountVoucher implements Voucher { + private final UUID id; + private final int amount; + + public PercentDiscountVoucher(int amount) { + this.id = UUID.randomUUID(); + this.amount = amount; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/Voucher.java new file mode 100644 index 0000000000..142abfb5a3 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/Voucher.java @@ -0,0 +1,4 @@ +package team.marco.vouchermanagementsystem; + +public interface Voucher { +} From 7b618f71a7146ab986707076dba9374cf5785729 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 00:58:10 +0900 Subject: [PATCH 010/134] =?UTF-8?q?feat:=20VoucherService=EC=97=90=20Vouch?= =?UTF-8?q?er=20=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MemoryVoucherRepository.java | 18 ++++++++++++++++++ .../VoucherRepository.java | 9 +++++++++ .../VoucherService.java | 16 ++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java new file mode 100644 index 0000000000..8134eb8bc4 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java @@ -0,0 +1,18 @@ +package team.marco.vouchermanagementsystem; + +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public class MemoryVoucherRepository implements VoucherRepository { + @Override + public void save(Voucher voucher) { + + } + + @Override + public List findAll() { + return null; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java new file mode 100644 index 0000000000..87656516f8 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java @@ -0,0 +1,9 @@ +package team.marco.vouchermanagementsystem; + +import java.util.List; + +public interface VoucherRepository { + void save(Voucher voucher); + + List findAll(); +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java index d43af4396d..031667dd6d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java @@ -4,7 +4,19 @@ @Service public class VoucherService { + private final VoucherRepository voucherRepository; - public void createFixedAmountVoucher(int amount) {} - public void createPercentDiscountVoucher(int percent) {} + public VoucherService(VoucherRepository voucherRepository) { + this.voucherRepository = voucherRepository; + } + + public void createFixedAmountVoucher(int amount) { + Voucher voucher = new FixedAmountVoucher(amount); + voucherRepository.save(voucher); + } + + public void createPercentDiscountVoucher(int percent) { + Voucher voucher = new PercentDiscountVoucher(percent); + voucherRepository.save(voucher); + } } From 1f39be204b546a57108e513dd870ad0e0ac9661e Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 01:02:52 +0900 Subject: [PATCH 011/134] =?UTF-8?q?fix:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=EC=9D=B4=20=EC=A2=85=EB=A3=8C=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marco/vouchermanagementsystem/VoucherApplication.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 10a5cae573..43342e00c9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -21,9 +21,8 @@ public void run() { runCommand(commandType); } catch (Exception e) { console.printError(e); + run(); } - - run(); } public void runCommand(CommandType commandType) { @@ -47,7 +46,7 @@ private void createVoucher() { switch (selected) { case 0 -> createFixedAmountVoucher(); case 1 -> createPercentDiscountVoucher(); - default -> { throw new RuntimeException("올바르지 않은 입력입니다."); } + default -> throw new RuntimeException("올바르지 않은 입력입니다."); } } From b0a2ceffeb2c6f157e57d7599a84849941bbd9af Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 01:11:17 +0900 Subject: [PATCH 012/134] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=EC=A1=B0=20=EC=84=B8=EB=B6=84=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team/marco/vouchermanagementsystem/Voucher.java | 4 ---- .../marco/vouchermanagementsystem/VoucherApplication.java | 2 ++ .../{ => model}/FixedAmountVoucher.java | 4 +++- .../{ => model}/PercentDiscountVoucher.java | 4 +++- .../team/marco/vouchermanagementsystem/model/Voucher.java | 4 ++++ .../{ => repository}/MemoryVoucherRepository.java | 3 ++- .../{ => repository}/VoucherRepository.java | 4 +++- .../{ => service}/VoucherService.java | 6 +++++- .../marco/vouchermanagementsystem/{ => util}/Console.java | 2 +- 9 files changed, 23 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/Voucher.java rename src/main/java/team/marco/vouchermanagementsystem/{ => model}/FixedAmountVoucher.java (70%) rename src/main/java/team/marco/vouchermanagementsystem/{ => model}/PercentDiscountVoucher.java (70%) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java rename src/main/java/team/marco/vouchermanagementsystem/{ => repository}/MemoryVoucherRepository.java (72%) rename src/main/java/team/marco/vouchermanagementsystem/{ => repository}/VoucherRepository.java (52%) rename src/main/java/team/marco/vouchermanagementsystem/{ => service}/VoucherService.java (65%) rename src/main/java/team/marco/vouchermanagementsystem/{ => util}/Console.java (97%) diff --git a/src/main/java/team/marco/vouchermanagementsystem/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/Voucher.java deleted file mode 100644 index 142abfb5a3..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/Voucher.java +++ /dev/null @@ -1,4 +0,0 @@ -package team.marco.vouchermanagementsystem; - -public interface Voucher { -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 43342e00c9..b0393507b1 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -1,6 +1,8 @@ package team.marco.vouchermanagementsystem; import org.springframework.stereotype.Component; +import team.marco.vouchermanagementsystem.service.VoucherService; +import team.marco.vouchermanagementsystem.util.Console; @Component public class VoucherApplication { diff --git a/src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java similarity index 70% rename from src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index 67705a86d1..a3e5a929c9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -1,4 +1,6 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.model; + +import team.marco.vouchermanagementsystem.model.Voucher; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java similarity index 70% rename from src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index a5b6f46e68..fc0d5d1ce8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -1,4 +1,6 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.model; + +import team.marco.vouchermanagementsystem.model.Voucher; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java new file mode 100644 index 0000000000..d437dfed01 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java @@ -0,0 +1,4 @@ +package team.marco.vouchermanagementsystem.model; + +public interface Voucher { +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java similarity index 72% rename from src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 8134eb8bc4..0c130ea1e7 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -1,6 +1,7 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.repository; import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.model.Voucher; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java similarity index 52% rename from src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java index 87656516f8..d348a69749 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java @@ -1,4 +1,6 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.repository; + +import team.marco.vouchermanagementsystem.model.Voucher; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java similarity index 65% rename from src/main/java/team/marco/vouchermanagementsystem/VoucherService.java rename to src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index 031667dd6d..ca1ba8bf7a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,6 +1,10 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.service; import org.springframework.stereotype.Service; +import team.marco.vouchermanagementsystem.repository.VoucherRepository; +import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.Voucher; @Service public class VoucherService { diff --git a/src/main/java/team/marco/vouchermanagementsystem/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java similarity index 97% rename from src/main/java/team/marco/vouchermanagementsystem/Console.java rename to src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 0f8d5ce261..9cf924748e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.util; import org.springframework.stereotype.Component; From a04242b2ec7a0cd7a7144896c532133fc1531db6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 01:33:54 +0900 Subject: [PATCH 013/134] =?UTF-8?q?feat:=20=EB=B0=94=EC=9A=B0=EC=B2=98=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/FixedAmountVoucher.java | 5 +++++ .../model/PercentDiscountVoucher.java | 5 +++++ .../marco/vouchermanagementsystem/model/Voucher.java | 3 +++ .../repository/MemoryVoucherRepository.java | 9 +++++++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index a3e5a929c9..bd78f9588d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -12,4 +12,9 @@ public FixedAmountVoucher(int amount) { this.id = UUID.randomUUID(); this.amount = amount; } + + @Override + public UUID getId() { + return id; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index fc0d5d1ce8..47814a4b8d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -12,4 +12,9 @@ public PercentDiscountVoucher(int amount) { this.id = UUID.randomUUID(); this.amount = amount; } + + @Override + public UUID getId() { + return id; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java index d437dfed01..0748b9865a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java @@ -1,4 +1,7 @@ package team.marco.vouchermanagementsystem.model; +import java.util.UUID; + public interface Voucher { + UUID getId(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 0c130ea1e7..73b4db8efa 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -3,17 +3,22 @@ import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.Voucher; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.UUID; @Repository public class MemoryVoucherRepository implements VoucherRepository { + Map voucherMap = new HashMap<>(); + @Override public void save(Voucher voucher) { - + voucherMap.put(voucher.getId(), voucher); } @Override public List findAll() { - return null; + return voucherMap.values().stream().toList(); } } From 3afd2b407af9e7abdd9f5a3e25df1edf1e2c7b6e Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 01:54:03 +0900 Subject: [PATCH 014/134] =?UTF-8?q?feat:=20=EC=BF=A0=ED=8F=B0=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/VoucherApplication.java | 5 +++++ .../model/FixedAmountVoucher.java | 6 ++++++ .../model/PercentDiscountVoucher.java | 12 +++++++++--- .../marco/vouchermanagementsystem/model/Voucher.java | 1 + .../service/VoucherService.java | 8 ++++++++ .../marco/vouchermanagementsystem/util/Console.java | 4 ++++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index b0393507b1..9d2c3dc4d7 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -4,8 +4,11 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; +import java.util.stream.Collectors; + @Component public class VoucherApplication { + private static final String INFO_DELIMINATOR = "\n"; private final Console console; private final VoucherService voucherService; @@ -63,6 +66,8 @@ private void createFixedAmountVoucher() { } private void getVoucherList() { + String vouchersInfo = String.join(INFO_DELIMINATOR, voucherService.getVouchersInfo()); + console.print(vouchersInfo); } private void close() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index bd78f9588d..536308cfdf 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -2,6 +2,7 @@ import team.marco.vouchermanagementsystem.model.Voucher; +import java.text.MessageFormat; import java.util.UUID; public class FixedAmountVoucher implements Voucher { @@ -17,4 +18,9 @@ public FixedAmountVoucher(int amount) { public UUID getId() { return id; } + + @Override + public String getInfo() { + return MessageFormat.format("{0}원 할인 쿠폰", amount); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index 47814a4b8d..be89249c3e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -2,19 +2,25 @@ import team.marco.vouchermanagementsystem.model.Voucher; +import java.text.MessageFormat; import java.util.UUID; public class PercentDiscountVoucher implements Voucher { private final UUID id; - private final int amount; + private final int percent; - public PercentDiscountVoucher(int amount) { + public PercentDiscountVoucher(int percent) { this.id = UUID.randomUUID(); - this.amount = amount; + this.percent = percent; } @Override public UUID getId() { return id; } + + @Override + public String getInfo() { + return MessageFormat.format("{0}% 할인 쿠폰", percent); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java index 0748b9865a..95b87352a6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java @@ -4,4 +4,5 @@ public interface Voucher { UUID getId(); + String getInfo(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index ca1ba8bf7a..ff500a86b5 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -6,6 +6,8 @@ import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; import team.marco.vouchermanagementsystem.model.Voucher; +import java.util.List; + @Service public class VoucherService { private final VoucherRepository voucherRepository; @@ -23,4 +25,10 @@ public void createPercentDiscountVoucher(int percent) { Voucher voucher = new PercentDiscountVoucher(percent); voucherRepository.save(voucher); } + + public List getVouchersInfo() { + return voucherRepository.findAll().stream() + .map(Voucher::getInfo) + .toList(); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 9cf924748e..18cda28912 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -62,4 +62,8 @@ public void printError(Exception e) { System.out.println(e.getMessage()); } } + + public void print(Object object) { + System.out.println(object); + } } From 4753b4dbf7f805533d92e5df3b91d533cf7f2ef0 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 02:11:20 +0900 Subject: [PATCH 015/134] =?UTF-8?q?feat:=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=ED=95=9C=EA=B8=80=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/CommandType.java | 2 +- .../VoucherApplication.java | 6 ++--- .../vouchermanagementsystem/util/Console.java | 24 +++++++++---------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java index 1472970169..9c97c02827 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java @@ -10,7 +10,7 @@ public static CommandType getCommandType(String input) { return Arrays.stream(CommandType.values()) .filter(commandType -> commandType.isMatch(input)) .findFirst() - .orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("{0} is invalid command", input))); + .orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("{0}: 사용할 수 없는 명령어입니다.", input))); } private boolean isMatch(String input) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 9d2c3dc4d7..c300c192eb 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -4,11 +4,9 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; -import java.util.stream.Collectors; - @Component public class VoucherApplication { - private static final String INFO_DELIMINATOR = "\n"; + private static final String INFO_DELIMINATOR = "\n"; private final Console console; private final VoucherService voucherService; @@ -72,6 +70,6 @@ private void getVoucherList() { private void close() { // TODO: 데이터 저장 기능 - System.out.println("exit program..."); + System.out.println("프로그램이 종료되었습니다."); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 18cda28912..6cec3648e8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -12,10 +12,10 @@ public class Console { public void printCommandManual() { System.out.println(""" - === Voucher Program === - Type exit to exit the program. - Type create to create a new voucher. - Type list to list all vouchers. + === 쿠폰 관리 프로그램 === + exit: 프로그램 종료 + create: 쿠폰 생성 + list: 쿠폰 목록 조회 """); } @@ -28,11 +28,7 @@ public String readString() { } public int readInt() { - try { - return Integer.parseInt(readString()); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("숫자만 입력하실 수 있습니다."); - } + return Integer.parseInt(readString()); } public int readInt(String prompt) { @@ -50,20 +46,22 @@ private String readLine() { public void printVoucherTypes() { System.out.println(""" - Type 0 to create fixed amount voucher. - Type 1 to create percent discount voucher. + 0: 고정 금액 할인 쿠폰 + 1: % 할인 쿠폰 """); } public void printError(Exception e) { if(e instanceof NumberFormatException) { - System.out.println("숫자를 입력해 주세요."); + print("숫자를 입력해 주세요."); } else { - System.out.println(e.getMessage()); + print(e.getMessage()); } + } public void print(Object object) { System.out.println(object); + System.out.println(); } } From 27ec9d12a4fe19aa526a2bc920a0197683384e76 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 02:35:40 +0900 Subject: [PATCH 016/134] =?UTF-8?q?style:=20Console=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=B6=9C=EB=A0=A5=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ################ # <타입> : <제목> 의 형식으로 제목을 아래 공백줄에 작성 # 제목은 50자 이내 / 변경사항이 "무엇"인지 명확히 작성 / 끝에 마침표 금지 # 예) feat : 로그인 기능 추가 # 바로 아래 공백은 지우지 마세요 (제목과 본문의 분리를 위함) ################ # 본문(구체적인 내용)을 아랫줄에 작성 # 여러 줄의 메시지를 작성할 땐 "-"로 구분 (한 줄은 72자 이내) ################ # 꼬릿말(footer)을 아랫줄에 작성 (현재 커밋과 관련된 이슈 번호 추가 등) # 예) Close #7 ################ # feat : 새로운 기능 추가 # fix : 버그 수정 # docs : 문서 수정 # test : 테스트 코드 추가 # refact : 코드 리팩토링 # style : 코드 의미에 영향을 주지 않는 변경사항 # chore : 빌드 부분 혹은 패키지 매니저 수정사항 ################ --- .../team/marco/vouchermanagementsystem/VoucherApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index c300c192eb..ec756be1ee 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -70,6 +70,6 @@ private void getVoucherList() { private void close() { // TODO: 데이터 저장 기능 - System.out.println("프로그램이 종료되었습니다."); + console.print("프로그램이 종료되었습니다."); } } From e26fa4af4c6dd59ca8b12a6ed52d19d2235a104d Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 02:38:33 +0900 Subject: [PATCH 017/134] =?UTF-8?q?feat:=20=EC=BF=A0=ED=8F=B0=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ################ # <타입> : <제목> 의 형식으로 제목을 아래 공백줄에 작성 # 제목은 50자 이내 / 변경사항이 "무엇"인지 명확히 작성 / 끝에 마침표 금지 # 예) feat : 로그인 기능 추가 # 바로 아래 공백은 지우지 마세요 (제목과 본문의 분리를 위함) ################ # 본문(구체적인 내용)을 아랫줄에 작성 # 여러 줄의 메시지를 작성할 땐 "-"로 구분 (한 줄은 72자 이내) ################ # 꼬릿말(footer)을 아랫줄에 작성 (현재 커밋과 관련된 이슈 번호 추가 등) # 예) Close #7 ################ # feat : 새로운 기능 추가 # fix : 버그 수정 # docs : 문서 수정 # test : 테스트 코드 추가 # refact : 코드 리팩토링 # style : 코드 의미에 영향을 주지 않는 변경사항 # chore : 빌드 부분 혹은 패키지 매니저 수정사항 ################ --- .../model/FixedAmountVoucher.java | 11 +++++++---- .../model/PercentDiscountVoucher.java | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index 536308cfdf..5646cf595e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -1,15 +1,18 @@ package team.marco.vouchermanagementsystem.model; -import team.marco.vouchermanagementsystem.model.Voucher; - -import java.text.MessageFormat; import java.util.UUID; +import static java.text.MessageFormat.format; + public class FixedAmountVoucher implements Voucher { private final UUID id; private final int amount; public FixedAmountVoucher(int amount) { + if (amount <= 0) { + throw new IllegalArgumentException(format("{0}: 할인 금액은 0 보다 커야 합니다.", amount)); + } + this.id = UUID.randomUUID(); this.amount = amount; } @@ -21,6 +24,6 @@ public UUID getId() { @Override public String getInfo() { - return MessageFormat.format("{0}원 할인 쿠폰", amount); + return format("{0}원 할인 쿠폰", amount); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index be89249c3e..787524a2a2 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -1,19 +1,31 @@ package team.marco.vouchermanagementsystem.model; -import team.marco.vouchermanagementsystem.model.Voucher; - import java.text.MessageFormat; import java.util.UUID; +import static java.text.MessageFormat.*; + public class PercentDiscountVoucher implements Voucher { private final UUID id; private final int percent; public PercentDiscountVoucher(int percent) { + checkValidation(percent); + this.id = UUID.randomUUID(); this.percent = percent; } + private void checkValidation(int percent) { + if (percent <= 0) { + throw new IllegalArgumentException(format("{0}: 할인율은 0% 이하일 수 없습니다.", percent)); + } + + if (percent > 100) { + throw new IllegalArgumentException(format("{0}: 할인율은 100%를 초과할 수 없습니다.", percent)); + } + } + @Override public UUID getId() { return id; @@ -21,6 +33,6 @@ public UUID getId() { @Override public String getInfo() { - return MessageFormat.format("{0}% 할인 쿠폰", percent); + return format("{0}% 할인 쿠폰", percent); } } From e19a919564798f514e93d3ab219b917516ce129f Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 15:05:28 +0900 Subject: [PATCH 018/134] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 13 +++++++++++++ .../VoucherManagementSystemApplication.java | 7 +++++++ .../model/FixedAmountVoucher.java | 7 +++++++ .../model/PercentDiscountVoucher.java | 6 ++++++ .../service/VoucherService.java | 2 ++ src/main/resources/logback.xml | 18 ++++++++++++++++++ 6 files changed, 53 insertions(+) create mode 100644 src/main/resources/logback.xml diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index ec756be1ee..57f3190b56 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -1,12 +1,16 @@ package team.marco.vouchermanagementsystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; @Component public class VoucherApplication { + private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); private static final String INFO_DELIMINATOR = "\n"; + private final Console console; private final VoucherService voucherService; @@ -43,6 +47,8 @@ public void runCommand(CommandType commandType) { } private void createVoucher() { + logger.info("Call createVoucher()"); + console.printVoucherTypes(); int selected = console.readInt(); @@ -54,21 +60,28 @@ private void createVoucher() { } private void createPercentDiscountVoucher() { + logger.info("Call createPercentDiscountVoucher()"); + int percent = console.readInt("할인율을 입력해 주세요."); voucherService.createPercentDiscountVoucher(percent); } private void createFixedAmountVoucher() { + logger.info("Call createFixedAmountVoucher()"); + int amount = console.readInt("할인 금액을 입력해 주세요."); voucherService.createFixedAmountVoucher(amount); } private void getVoucherList() { + logger.info("Call getVoucherList()"); + String vouchersInfo = String.join(INFO_DELIMINATOR, voucherService.getVouchersInfo()); console.print(vouchersInfo); } private void close() { + logger.info("Call close()"); // TODO: 데이터 저장 기능 console.print("프로그램이 종료되었습니다."); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 38c7f447a6..b997dd8047 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -1,15 +1,22 @@ package team.marco.vouchermanagementsystem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; @SpringBootApplication public class VoucherManagementSystemApplication { + private static final Logger logger = LoggerFactory.getLogger(VoucherManagementSystemApplication.class);; public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); + logger.info("Program start"); + VoucherApplication application = context.getBean(VoucherApplication.class); application.run(); + + logger.info("Program exit"); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index 5646cf595e..a7a131e1d7 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -1,10 +1,15 @@ package team.marco.vouchermanagementsystem.model; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import team.marco.vouchermanagementsystem.service.VoucherService; + import java.util.UUID; import static java.text.MessageFormat.format; public class FixedAmountVoucher implements Voucher { + private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); private final UUID id; private final int amount; @@ -15,6 +20,8 @@ public FixedAmountVoucher(int amount) { this.id = UUID.randomUUID(); this.amount = amount; + + logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", id, amount); } @Override diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index 787524a2a2..11463c0d1d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -1,11 +1,15 @@ package team.marco.vouchermanagementsystem.model; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.MessageFormat; import java.util.UUID; import static java.text.MessageFormat.*; public class PercentDiscountVoucher implements Voucher { + private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); private final UUID id; private final int percent; @@ -14,6 +18,8 @@ public PercentDiscountVoucher(int percent) { this.id = UUID.randomUUID(); this.percent = percent; + + logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", id, percent); } private void checkValidation(int percent) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index ff500a86b5..ba80bf67d7 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,5 +1,7 @@ package team.marco.vouchermanagementsystem.service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import team.marco.vouchermanagementsystem.repository.VoucherRepository; import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000000..d7351a64ce --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + logs/access.log + + logs/access-%d{yyyy-MM-dd}.log + + + ${LOG_PATTERN} + + + + + + + \ No newline at end of file From e3e601d344a8d0597ddc0da458107e86ba3e9cde Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 15:46:40 +0900 Subject: [PATCH 019/134] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 12 ++++++++--- .../vouchermanagementsystem/util/Console.java | 5 +++++ src/main/resources/logback.xml | 20 ++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 57f3190b56..b5755ed0a0 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -21,15 +21,21 @@ public VoucherApplication(Console console, VoucherService service) { public void run() { console.printCommandManual(); - String input = console.readString(); try { + String input = console.readString(); CommandType commandType = CommandType.getCommandType(input); runCommand(commandType); - } catch (Exception e) { - console.printError(e); + } catch (IllegalArgumentException iae) { + console.printError(iae); run(); + } catch (Exception e) { + logger.error(e.toString()); + console.print("프로그램에 에러가 발생했습니다."); + close(); } + + } public void runCommand(CommandType commandType) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 6cec3648e8..ee2a27516f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -5,6 +5,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Objects; @Component public class Console { @@ -24,6 +25,10 @@ public String readString() { String input = readLine(); System.out.println(); + if (Objects.isNull(input)) { + throw new RuntimeException("입력 과정에서 오류가 발생했습니다."); + } + return input; } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index d7351a64ce..5e1e2260eb 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -12,7 +12,21 @@ - - + + logs/error.log + + logs/error-%d{yyyy-MM-dd}.log + + + ${LOG_PATTERN} + + + + + + + + + - \ No newline at end of file + From e23928d0ae220f88e65e73b0c5bde2df81ce5a6a Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 16:06:50 +0900 Subject: [PATCH 020/134] =?UTF-8?q?refactor:=20run()=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EC=99=80=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EB=B6=80=EB=B6=84=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index b5755ed0a0..9435042ace 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -20,36 +20,35 @@ public VoucherApplication(Console console, VoucherService service) { } public void run() { - console.printCommandManual(); - try { - String input = console.readString(); - CommandType commandType = CommandType.getCommandType(input); - runCommand(commandType); - } catch (IllegalArgumentException iae) { - console.printError(iae); - run(); + runCommand(); } catch (Exception e) { logger.error(e.toString()); console.print("프로그램에 에러가 발생했습니다."); - close(); } - + close(); } - public void runCommand(CommandType commandType) { - switch (commandType) { - case CREATE -> createVoucher(); - case LIST -> getVoucherList(); - case EXIT -> { - close(); + public void runCommand() { + console.printCommandManual(); + String input = console.readString(); + + try { + CommandType commandType = CommandType.getCommandType(input); - return; + switch (commandType) { + case CREATE -> createVoucher(); + case LIST -> getVoucherList(); + case EXIT -> { + return; + } } + } catch (IllegalArgumentException e) { + console.printError(e); } - run(); + runCommand(); } private void createVoucher() { From 1096094ec1a237649f200ad91b930460a4157494 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 19:00:43 +0900 Subject: [PATCH 021/134] =?UTF-8?q?chore:=20jackson=20dependency=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 407928b63f..ead04db56f 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' } tasks.named('test') { From 0ff015ee189efa5a1309d279b3a0ea62e6c284a8 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 19:01:25 +0900 Subject: [PATCH 022/134] =?UTF-8?q?feat:=20console=20log=20appender=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 5e1e2260eb..8849762ac0 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -2,6 +2,12 @@ + + + ${LOG_PATTERN} + + + logs/access.log From be5b4b4404c8a39b649c2ebaa8367322fad7867d Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 19:02:16 +0900 Subject: [PATCH 023/134] =?UTF-8?q?feat:=20FileManager=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/FileManager.java | 11 +++ .../util/JSONFileManager.java | 68 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java b/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java new file mode 100644 index 0000000000..ed96841c50 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java @@ -0,0 +1,11 @@ +package team.marco.vouchermanagementsystem.util; + +import java.util.List; + +public interface FileManager { + List load(); + + void save(T data); + + void close(); +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java b/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java new file mode 100644 index 0000000000..2254a87e54 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java @@ -0,0 +1,68 @@ +package team.marco.vouchermanagementsystem.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.SequenceWriter; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.List; + +public class JSONFileManager implements FileManager { + private final File file; + private final ObjectMapper objectMapper; + private final ObjectReader objectReader; + private SequenceWriter sequenceWriter; + + private String path = "./src/main/resources/data.json"; + + public JSONFileManager(Class type) { + file = new File(path); + objectMapper = new ObjectMapper(); + objectReader = objectMapper.readerForListOf(type); + } + + @Override + public List load() { + if (!file.exists()) { + return Collections.emptyList(); + } + + try { + List loadedData = objectReader.readValue(Files.readString(Paths.get(path))); + FileWriter fileWriter = new FileWriter(file, false); + + sequenceWriter = objectMapper.writer().writeValuesAsArray(fileWriter); + + for (T t : loadedData) { + sequenceWriter.write(t); + } + + return loadedData; + } catch (IOException e) { + throw new RuntimeException("파일을 불러오는 과정에서 오류가 발생했습니다."); + } + } + + @Override + public void save(T data) { + try { + sequenceWriter.write(data); + } catch (IOException e) { + throw new RuntimeException("파일을 생성할 수 없습니다. (%s)".formatted(path)); + } + } + + @Override + public void close() { + try { + sequenceWriter.close(); + } catch (IOException e) { + throw new RuntimeException("파일을 저장하는 과정에서 오류가 발생했습니다."); + } + } +} From 3ce8d1ab5264d342495385142bd64b38381e5f94 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 19:06:43 +0900 Subject: [PATCH 024/134] =?UTF-8?q?feat:=20VoucherType=20Enum=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voucher 필드 게터 추가 --- .../model/FixedAmountVoucher.java | 16 +++++++++++++++- .../model/PercentDiscountVoucher.java | 18 ++++++++++++++++-- .../vouchermanagementsystem/model/Voucher.java | 5 +++++ .../model/VoucherType.java | 5 +++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index a7a131e1d7..665296cd30 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -2,7 +2,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import team.marco.vouchermanagementsystem.service.VoucherService; import java.util.UUID; @@ -24,6 +23,11 @@ public FixedAmountVoucher(int amount) { logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", id, amount); } + public FixedAmountVoucher(UUID id, int amount) { + this.id = id; + this.amount = amount; + } + @Override public UUID getId() { return id; @@ -33,4 +37,14 @@ public UUID getId() { public String getInfo() { return format("{0}원 할인 쿠폰", amount); } + + @Override + public int getData() { + return amount; + } + + @Override + public VoucherType getType() { + return VoucherType.FIXED; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index 11463c0d1d..3eb65d8283 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -3,10 +3,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.MessageFormat; import java.util.UUID; -import static java.text.MessageFormat.*; +import static java.text.MessageFormat.format; public class PercentDiscountVoucher implements Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); @@ -22,6 +21,11 @@ public PercentDiscountVoucher(int percent) { logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", id, percent); } + public PercentDiscountVoucher(UUID id, int percent) { + this.id = id; + this.percent = percent; + } + private void checkValidation(int percent) { if (percent <= 0) { throw new IllegalArgumentException(format("{0}: 할인율은 0% 이하일 수 없습니다.", percent)); @@ -41,4 +45,14 @@ public UUID getId() { public String getInfo() { return format("{0}% 할인 쿠폰", percent); } + + @Override + public int getData() { + return percent; + } + + @Override + public VoucherType getType() { + return VoucherType.PERCENT; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java index 95b87352a6..f3b35e8f47 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java @@ -4,5 +4,10 @@ public interface Voucher { UUID getId(); + String getInfo(); + + int getData(); + + VoucherType getType(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java b/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java new file mode 100644 index 0000000000..8178c2971d --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java @@ -0,0 +1,5 @@ +package team.marco.vouchermanagementsystem.model; + +public enum VoucherType { + FIXED, PERCENT +} From 989ac9ea69ba324aa61acb2bf0baae7c5d9e01b9 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Wed, 18 Oct 2023 19:08:53 +0900 Subject: [PATCH 025/134] =?UTF-8?q?feat:=20voucher=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=A5=BC=20=ED=8C=8C=EC=9D=BC=EC=97=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EA=B3=A0=20=EB=B6=88=EB=9F=AC=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 1 - .../dto/JSONVoucherDTO.java | 38 ++++++++++++++ .../repository/JSONFileVoucherRepository.java | 52 +++++++++++++++++++ src/main/resources/sample_data.json | 1 + 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java create mode 100644 src/main/resources/sample_data.json diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 9435042ace..2cc006457d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -87,7 +87,6 @@ private void getVoucherList() { private void close() { logger.info("Call close()"); - // TODO: 데이터 저장 기능 console.print("프로그램이 종료되었습니다."); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java b/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java new file mode 100644 index 0000000000..611fbe1394 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java @@ -0,0 +1,38 @@ +package team.marco.vouchermanagementsystem.dto; + +import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.VoucherType; + +import java.util.UUID; + +public class JSONVoucherDTO { + private VoucherType type; + private UUID id; + private int data; + + private JSONVoucherDTO() { + // for object mapper deserializing + } + + private JSONVoucherDTO(VoucherType type, UUID id, int data) { + this.type = type; + this.id = id; + this.data = data; + } + + public static JSONVoucherDTO convert(Voucher voucher) { + return new JSONVoucherDTO(voucher.getType(), voucher.getId(), voucher.getData()); + } + + public VoucherType getType() { + return type; + } + + public UUID getId() { + return id; + } + + public int getData() { + return data; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java new file mode 100644 index 0000000000..f09de7d579 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -0,0 +1,52 @@ +package team.marco.vouchermanagementsystem.repository; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.dto.JSONVoucherDTO; +import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.util.FileManager; +import team.marco.vouchermanagementsystem.util.JSONFileManager; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +@Repository +@Primary +public class JSONFileVoucherRepository implements VoucherRepository, DisposableBean { + FileManager fileManager = new JSONFileManager<>(JSONVoucherDTO.class); + Map voucherMap = new HashMap<>(); + + public JSONFileVoucherRepository() { + List loadedDTO = fileManager.load(); + + loadedDTO.forEach(dto -> { + Voucher voucher = switch (dto.getType()) { + case FIXED -> new FixedAmountVoucher(dto.getId(), dto.getData()); + case PERCENT -> new PercentDiscountVoucher(dto.getId(), dto.getData()); + }; + + voucherMap.put(voucher.getId(), voucher); + }); + } + + @Override + public void save(Voucher voucher) { + voucherMap.put(voucher.getId(), voucher); + fileManager.save(JSONVoucherDTO.convert(voucher)); + } + + @Override + public List findAll() { + return voucherMap.values().stream().toList(); + } + + @Override + public void destroy() { + fileManager.close(); + } +} diff --git a/src/main/resources/sample_data.json b/src/main/resources/sample_data.json new file mode 100644 index 0000000000..12010512f2 --- /dev/null +++ b/src/main/resources/sample_data.json @@ -0,0 +1 @@ +[{"type":"FIXED","id":"461b8847-578d-43c7-8472-d9374bbac41a","data":1000000},{"type":"PERCENT","id":"7bd6cc26-5c3b-4579-ad3b-834f2b6f075c","data":50},{"type":"FIXED","id":"c0f9c0f3-b974-41e8-a517-df7c3b8cd08b","data":100},{"type":"PERCENT","id":"75145684-5602-40a2-b279-096d94dc6063","data":22},{"type":"FIXED","id":"da9aa8de-162f-46c7-b23b-2e37ee0569aa","data":7777},{"type":"PERCENT","id":"4d3cb1bc-02f5-4d67-b274-60526d87fac1","data":90}] \ No newline at end of file From a20536339b57b6899022219cc39c81aa2cf0b62c Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 18 Oct 2023 23:26:59 +0900 Subject: [PATCH 026/134] =?UTF-8?q?feat:=20=EB=B8=94=EB=9E=99=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/CommandType.java | 2 +- .../VoucherApplication.java | 9 +++ .../vouchermanagementsystem/model/User.java | 25 +++++++++ .../repository/BlacklistRepository.java | 55 +++++++++++++++++++ .../service/VoucherService.java | 14 ++++- .../vouchermanagementsystem/util/Console.java | 1 + src/main/resources/blacklist.csv | 0 src/main/resources/data.json | 0 8 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/User.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java create mode 100644 src/main/resources/blacklist.csv create mode 100644 src/main/resources/data.json diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java index 9c97c02827..0ab75dd621 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java @@ -4,7 +4,7 @@ import java.util.Arrays; public enum CommandType { - CREATE, LIST, EXIT; + CREATE, LIST, EXIT, BLACKLIST; public static CommandType getCommandType(String input) { return Arrays.stream(CommandType.values()) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 2cc006457d..06efeb86d9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -40,17 +40,26 @@ public void runCommand() { switch (commandType) { case CREATE -> createVoucher(); case LIST -> getVoucherList(); + case BLACKLIST -> getBlacklistUsers(); case EXIT -> { return; } } } catch (IllegalArgumentException e) { console.printError(e); + e.printStackTrace(); } runCommand(); } + private void getBlacklistUsers() { + logger.info("Call getBlackListUsers()"); + + String blacklistUsers = String.join(INFO_DELIMINATOR, voucherService.getBlacklistUsers()); + console.print(blacklistUsers); + } + private void createVoucher() { logger.info("Call createVoucher()"); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/User.java b/src/main/java/team/marco/vouchermanagementsystem/model/User.java new file mode 100644 index 0000000000..ac78e9f716 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/model/User.java @@ -0,0 +1,25 @@ +package team.marco.vouchermanagementsystem.model; + +import java.util.UUID; + +import static java.text.MessageFormat.format; + +public class User { + private UUID id; + private String name; + + public User(UUID id, String name) { + this.id = id; + this.name = name; + } + + public User(String name) { + this.id = UUID.randomUUID(); + this.name = name; + } + + public String getInfo() { + + return format("id: {0}, 고객명: {1} ", id, name); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java new file mode 100644 index 0000000000..6fff6dcbb8 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -0,0 +1,55 @@ +package team.marco.vouchermanagementsystem.repository; + +import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.model.User; + +import java.awt.print.Book; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.*; + +@Repository +public class BlacklistRepository { + private static final String PATH = "src/main/resources/blacklist.csv"; + private List blacklist = new ArrayList<>(); + + public BlacklistRepository() { + blacklist = load(); + } + + private BufferedWriter getWriter() { + try { + return Files.newBufferedWriter(Paths.get(PATH), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING); + } catch (IOException e) { throw new RuntimeException("파일 쓰기 실패"); } + } + + private BufferedReader getReader() { + try { + return Files.newBufferedReader(Paths.get(PATH), StandardCharsets.UTF_8); + } catch (IOException e) { throw new RuntimeException("파일 읽기 실패"); } + } + + private List load() { + List loaded = new ArrayList<>(); + + try (BufferedReader reader = getReader()) { + reader.readLine(); + reader.lines() + .map(s -> s.split("[;,]")) + .forEach(data -> { + loaded.add(new User(UUID.fromString(data[0]), data[1])); + }); + } catch (IOException e) { throw new RuntimeException("데이터를 가져올 수 없습니다." + e.getMessage()); } + return loaded; + + } + + public List findAll() { + return blacklist; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index ba80bf67d7..512efdb881 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,8 +1,8 @@ package team.marco.vouchermanagementsystem.service; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.repository.BlacklistRepository; import team.marco.vouchermanagementsystem.repository.VoucherRepository; import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; @@ -13,9 +13,11 @@ @Service public class VoucherService { private final VoucherRepository voucherRepository; + private final BlacklistRepository blacklistRepository; - public VoucherService(VoucherRepository voucherRepository) { + public VoucherService(VoucherRepository voucherRepository, BlacklistRepository blacklistRepository) { this.voucherRepository = voucherRepository; + this.blacklistRepository = blacklistRepository; } public void createFixedAmountVoucher(int amount) { @@ -33,4 +35,10 @@ public List getVouchersInfo() { .map(Voucher::getInfo) .toList(); } + + public List getBlacklistUsers() { + return blacklistRepository.findAll().stream() + .map(User::getInfo) + .toList(); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index ee2a27516f..5e7e6e41b9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -17,6 +17,7 @@ public void printCommandManual() { exit: 프로그램 종료 create: 쿠폰 생성 list: 쿠폰 목록 조회 + blacklist: 블랙 리스트 유저 조회 """); } diff --git a/src/main/resources/blacklist.csv b/src/main/resources/blacklist.csv new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/main/resources/data.json b/src/main/resources/data.json new file mode 100644 index 0000000000..e69de29bb2 From bacd5bec075f3985a7cc2cc6751cafcb53a7c5e6 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 01:05:10 +0900 Subject: [PATCH 027/134] =?UTF-8?q?refactor:=20JSONFileManager=EB=A5=BC=20?= =?UTF-8?q?Repository=EC=99=80=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/JSONVoucherDTO.java | 38 ----------- .../repository/JSONFileVoucherRepository.java | 48 ++++++++----- .../repository/LoadedJSONVoucher.java | 42 ++++++++++++ .../util/FileManager.java | 11 --- .../util/JSONFileManager.java | 68 ------------------- src/main/resources/sample_data.json | 2 +- 6 files changed, 74 insertions(+), 135 deletions(-) delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java b/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java deleted file mode 100644 index 611fbe1394..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/dto/JSONVoucherDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -package team.marco.vouchermanagementsystem.dto; - -import team.marco.vouchermanagementsystem.model.Voucher; -import team.marco.vouchermanagementsystem.model.VoucherType; - -import java.util.UUID; - -public class JSONVoucherDTO { - private VoucherType type; - private UUID id; - private int data; - - private JSONVoucherDTO() { - // for object mapper deserializing - } - - private JSONVoucherDTO(VoucherType type, UUID id, int data) { - this.type = type; - this.id = id; - this.data = data; - } - - public static JSONVoucherDTO convert(Voucher voucher) { - return new JSONVoucherDTO(voucher.getType(), voucher.getId(), voucher.getData()); - } - - public VoucherType getType() { - return type; - } - - public UUID getId() { - return id; - } - - public int getData() { - return data; - } -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index f09de7d579..337c944cfe 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -1,15 +1,14 @@ package team.marco.vouchermanagementsystem.repository; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; import org.springframework.beans.factory.DisposableBean; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.dto.JSONVoucherDTO; -import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; import team.marco.vouchermanagementsystem.model.Voucher; -import team.marco.vouchermanagementsystem.util.FileManager; -import team.marco.vouchermanagementsystem.util.JSONFileManager; +import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -18,26 +17,37 @@ @Repository @Primary public class JSONFileVoucherRepository implements VoucherRepository, DisposableBean { - FileManager fileManager = new JSONFileManager<>(JSONVoucherDTO.class); - Map voucherMap = new HashMap<>(); + private String path = "./src/main/resources/data.json"; + private final Map voucherMap; + private final ObjectMapper objectMapper; + private final File file; public JSONFileVoucherRepository() { - List loadedDTO = fileManager.load(); + objectMapper = new ObjectMapper(); + file = new File(path); + voucherMap = load(); + } + + private Map load() { + ObjectReader objectReader = objectMapper.readerForListOf(LoadedJSONVoucher.class); + List loadedList; + + try { + loadedList = objectReader.readValue(file); + } catch (IOException e) { + throw new RuntimeException("파일을 불러오는 과정에서 오류가 발생했습니다."); + } + + Map convertedMap = new HashMap<>(); - loadedDTO.forEach(dto -> { - Voucher voucher = switch (dto.getType()) { - case FIXED -> new FixedAmountVoucher(dto.getId(), dto.getData()); - case PERCENT -> new PercentDiscountVoucher(dto.getId(), dto.getData()); - }; + loadedList.forEach(data -> convertedMap.put(data.getId(), data.convertToVoucher())); - voucherMap.put(voucher.getId(), voucher); - }); + return convertedMap; } @Override public void save(Voucher voucher) { voucherMap.put(voucher.getId(), voucher); - fileManager.save(JSONVoucherDTO.convert(voucher)); } @Override @@ -47,6 +57,10 @@ public List findAll() { @Override public void destroy() { - fileManager.close(); + try { + objectMapper.writeValue(file, voucherMap.values()); + } catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java new file mode 100644 index 0000000000..7a31a10df1 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java @@ -0,0 +1,42 @@ +package team.marco.vouchermanagementsystem.repository; + +import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.VoucherType; + +import java.util.UUID; + +public class LoadedJSONVoucher { + private VoucherType type; + private UUID id; + private int data; + private String info; + + private LoadedJSONVoucher() { + // for object mapper deserializing + } + + public Voucher convertToVoucher() { + return switch (getType()) { + case FIXED -> new FixedAmountVoucher(getId(), getData()); + case PERCENT -> new PercentDiscountVoucher(getId(), getData()); + }; + } + + public VoucherType getType() { + return type; + } + + public UUID getId() { + return id; + } + + public int getData() { + return data; + } + + public String getInfo() { + return info; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java b/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java deleted file mode 100644 index ed96841c50..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/util/FileManager.java +++ /dev/null @@ -1,11 +0,0 @@ -package team.marco.vouchermanagementsystem.util; - -import java.util.List; - -public interface FileManager { - List load(); - - void save(T data); - - void close(); -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java b/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java deleted file mode 100644 index 2254a87e54..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/util/JSONFileManager.java +++ /dev/null @@ -1,68 +0,0 @@ -package team.marco.vouchermanagementsystem.util; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.databind.SequenceWriter; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.List; - -public class JSONFileManager implements FileManager { - private final File file; - private final ObjectMapper objectMapper; - private final ObjectReader objectReader; - private SequenceWriter sequenceWriter; - - private String path = "./src/main/resources/data.json"; - - public JSONFileManager(Class type) { - file = new File(path); - objectMapper = new ObjectMapper(); - objectReader = objectMapper.readerForListOf(type); - } - - @Override - public List load() { - if (!file.exists()) { - return Collections.emptyList(); - } - - try { - List loadedData = objectReader.readValue(Files.readString(Paths.get(path))); - FileWriter fileWriter = new FileWriter(file, false); - - sequenceWriter = objectMapper.writer().writeValuesAsArray(fileWriter); - - for (T t : loadedData) { - sequenceWriter.write(t); - } - - return loadedData; - } catch (IOException e) { - throw new RuntimeException("파일을 불러오는 과정에서 오류가 발생했습니다."); - } - } - - @Override - public void save(T data) { - try { - sequenceWriter.write(data); - } catch (IOException e) { - throw new RuntimeException("파일을 생성할 수 없습니다. (%s)".formatted(path)); - } - } - - @Override - public void close() { - try { - sequenceWriter.close(); - } catch (IOException e) { - throw new RuntimeException("파일을 저장하는 과정에서 오류가 발생했습니다."); - } - } -} diff --git a/src/main/resources/sample_data.json b/src/main/resources/sample_data.json index 12010512f2..a1e251e6d6 100644 --- a/src/main/resources/sample_data.json +++ b/src/main/resources/sample_data.json @@ -1 +1 @@ -[{"type":"FIXED","id":"461b8847-578d-43c7-8472-d9374bbac41a","data":1000000},{"type":"PERCENT","id":"7bd6cc26-5c3b-4579-ad3b-834f2b6f075c","data":50},{"type":"FIXED","id":"c0f9c0f3-b974-41e8-a517-df7c3b8cd08b","data":100},{"type":"PERCENT","id":"75145684-5602-40a2-b279-096d94dc6063","data":22},{"type":"FIXED","id":"da9aa8de-162f-46c7-b23b-2e37ee0569aa","data":7777},{"type":"PERCENT","id":"4d3cb1bc-02f5-4d67-b274-60526d87fac1","data":90}] \ No newline at end of file +[{"id":"861dbf02-3989-467c-b0a5-7c8b56640688","type":"FIXED","data":1000,"info":"1,000원 할인 쿠폰"},{"id":"9f749266-b875-431b-b728-d17ef34ca1ee","type":"PERCENT","data":10,"info":"10% 할인 쿠폰"}] From 620f34b8c7f4ba0d3e0844cdc242243dd37d8ca2 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 19 Oct 2023 02:06:26 +0900 Subject: [PATCH 028/134] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=84=A4=EC=A0=95=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 1 - .../VoucherManagementSystemApplication.java | 2 +- .../repository/BlacklistRepository.java | 30 +++++-------------- .../repository/JSONFileVoucherRepository.java | 8 ++--- .../repository/MemoryVoucherRepository.java | 2 ++ src/main/resources/application.properties | 1 - src/main/resources/application.yml | 16 ++++++++++ src/main/resources/blacklist.csv | 3 ++ src/main/resources/data.json | 0 src/main/resources/voucher_data.json | 1 + 10 files changed, 34 insertions(+), 30 deletions(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml delete mode 100644 src/main/resources/data.json create mode 100644 src/main/resources/voucher_data.json diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 06efeb86d9..481f4ac9c8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -47,7 +47,6 @@ public void runCommand() { } } catch (IllegalArgumentException e) { console.printError(e); - e.printStackTrace(); } runCommand(); diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index b997dd8047..92b35c27b1 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -12,7 +12,7 @@ public class VoucherManagementSystemApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); - logger.info("Program start"); + logger.info("Program start " + context.getEnvironment().getActiveProfiles()[0]); VoucherApplication application = context.getBean(VoucherApplication.class); application.run(); diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 6fff6dcbb8..383f34cc0a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -1,49 +1,33 @@ package team.marco.vouchermanagementsystem.repository; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.User; -import java.awt.print.Book; import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; import java.util.*; @Repository public class BlacklistRepository { - private static final String PATH = "src/main/resources/blacklist.csv"; - private List blacklist = new ArrayList<>(); + private final List blacklist; - public BlacklistRepository() { - blacklist = load(); - } - - private BufferedWriter getWriter() { - try { - return Files.newBufferedWriter(Paths.get(PATH), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING); - } catch (IOException e) { throw new RuntimeException("파일 쓰기 실패"); } - } - private BufferedReader getReader() { - try { - return Files.newBufferedReader(Paths.get(PATH), StandardCharsets.UTF_8); - } catch (IOException e) { throw new RuntimeException("파일 읽기 실패"); } + public BlacklistRepository(@Value("${file.path.blacklist}") String path) { + blacklist = load(path); } - private List load() { + private List load(String path) { List loaded = new ArrayList<>(); - try (BufferedReader reader = getReader()) { + try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8);) { reader.readLine(); reader.lines() .map(s -> s.split("[;,]")) - .forEach(data -> { - loaded.add(new User(UUID.fromString(data[0]), data[1])); - }); + .forEach(data -> loaded.add(new User(UUID.fromString(data[0]), data[1]))); } catch (IOException e) { throw new RuntimeException("데이터를 가져올 수 없습니다." + e.getMessage()); } return loaded; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index 337c944cfe..14f74e3bfd 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -3,7 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import org.springframework.beans.factory.DisposableBean; -import org.springframework.context.annotation.Primary; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.Voucher; @@ -14,15 +15,14 @@ import java.util.Map; import java.util.UUID; +@Profile("dev") @Repository -@Primary public class JSONFileVoucherRepository implements VoucherRepository, DisposableBean { - private String path = "./src/main/resources/data.json"; private final Map voucherMap; private final ObjectMapper objectMapper; private final File file; - public JSONFileVoucherRepository() { + public JSONFileVoucherRepository(@Value("${file.path.voucher_data}") String path) { objectMapper = new ObjectMapper(); file = new File(path); voucherMap = load(); diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 73b4db8efa..adf86635df 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -1,5 +1,6 @@ package team.marco.vouchermanagementsystem.repository; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.Voucher; @@ -8,6 +9,7 @@ import java.util.Map; import java.util.UUID; +@Profile({"local", "debug"}) @Repository public class MemoryVoucherRepository implements VoucherRepository { Map voucherMap = new HashMap<>(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000000..f4eb546efe --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,16 @@ +file: + path: + blacklist: "src/main/resources/blacklist.csv" + voucher_data: "src/main/resources/voucher_data.json" +--- +spring: + profiles: + active: "dev" +--- +spring: + profiles: + active: "local" +--- +spring: + profiles: + active: "debug" \ No newline at end of file diff --git a/src/main/resources/blacklist.csv b/src/main/resources/blacklist.csv index e69de29bb2..9f7628e0af 100644 --- a/src/main/resources/blacklist.csv +++ b/src/main/resources/blacklist.csv @@ -0,0 +1,3 @@ +id,name +461b8847-578d-43c7-8472-d9374bbac41a,정의진 +461b8847-578d-43c7-8472-d9374bbac42b,김현우 \ No newline at end of file diff --git a/src/main/resources/data.json b/src/main/resources/data.json deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/main/resources/voucher_data.json b/src/main/resources/voucher_data.json new file mode 100644 index 0000000000..60f7546529 --- /dev/null +++ b/src/main/resources/voucher_data.json @@ -0,0 +1 @@ +[{"id":"adc56b89-a8ff-416e-b5b3-6f1c06b0e2e4","data":50,"info":"50% 할인 쿠폰","type":"PERCENT"},{"id":"722c9d35-a11f-4e07-aa91-ec52054060c4","data":70,"info":"70% 할인 쿠폰","type":"PERCENT"},{"id":"1ceecc21-8588-461b-b5e7-ffc968a32eea","data":1000,"info":"1,000원 할인 쿠폰","type":"FIXED"},{"id":"074f7ab9-51c8-4b8c-8a4d-960755c55d02","data":1000,"info":"1,000원 할인 쿠폰","type":"FIXED"}] \ No newline at end of file From 7d34e5407ac14e2a60f1b87dac28e6abebaf4546 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 19 Oct 2023 15:25:14 +0900 Subject: [PATCH 029/134] =?UTF-8?q?feat:=20=EA=B0=9C=EB=B0=9C=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=A1=9C=EA=B9=85?= =?UTF-8?q?=EC=9D=84=20=EB=8B=A4=EB=A5=B4=EA=B2=8C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback.xml | 20 +++++++++++++++++--- src/main/resources/voucher_data.json | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 8849762ac0..1e4f9986b0 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -32,7 +32,21 @@ - - - + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/voucher_data.json b/src/main/resources/voucher_data.json index 60f7546529..239f38141b 100644 --- a/src/main/resources/voucher_data.json +++ b/src/main/resources/voucher_data.json @@ -1 +1 @@ -[{"id":"adc56b89-a8ff-416e-b5b3-6f1c06b0e2e4","data":50,"info":"50% 할인 쿠폰","type":"PERCENT"},{"id":"722c9d35-a11f-4e07-aa91-ec52054060c4","data":70,"info":"70% 할인 쿠폰","type":"PERCENT"},{"id":"1ceecc21-8588-461b-b5e7-ffc968a32eea","data":1000,"info":"1,000원 할인 쿠폰","type":"FIXED"},{"id":"074f7ab9-51c8-4b8c-8a4d-960755c55d02","data":1000,"info":"1,000원 할인 쿠폰","type":"FIXED"}] \ No newline at end of file +[{"id":"adc56b89-a8ff-416e-b5b3-6f1c06b0e2e4","info":"50% 할인 쿠폰","data":50,"type":"PERCENT"},{"id":"722c9d35-a11f-4e07-aa91-ec52054060c4","info":"70% 할인 쿠폰","data":70,"type":"PERCENT"},{"id":"7823e578-a419-404f-b016-73966505a87e","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"1ceecc21-8588-461b-b5e7-ffc968a32eea","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"31de22a8-bcc4-4e5a-9b57-cb92e0586108","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"074f7ab9-51c8-4b8c-8a4d-960755c55d02","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"}] \ No newline at end of file From f5c1e48d15bfc75904bc8fe343061a9ca0af98f9 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 19 Oct 2023 15:41:04 +0900 Subject: [PATCH 030/134] =?UTF-8?q?fix:=20voucher=5Fdata.json=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=9D=B4=20=EC=A1=B4=EC=9E=AC=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EB=9E=A8=EC=9D=B4=20=EC=A2=85=EB=A3=8C=EB=90=98?= =?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JSONFileVoucherRepository.java | 6 +++++- src/main/resources/voucher_data.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index 14f74e3bfd..3e51ebf692 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -29,6 +29,10 @@ public JSONFileVoucherRepository(@Value("${file.path.voucher_data}") String path } private Map load() { + if(!file.exists()) { + return new HashMap<>(); + } + ObjectReader objectReader = objectMapper.readerForListOf(LoadedJSONVoucher.class); List loadedList; @@ -60,7 +64,7 @@ public void destroy() { try { objectMapper.writeValue(file, voucherMap.values()); } catch (IOException e) { - throw new RuntimeException(e); + throw new RuntimeException("파일을 저장하는 과정에서 오류가 발생했습니다."); } } } diff --git a/src/main/resources/voucher_data.json b/src/main/resources/voucher_data.json index 239f38141b..0637a088a0 100644 --- a/src/main/resources/voucher_data.json +++ b/src/main/resources/voucher_data.json @@ -1 +1 @@ -[{"id":"adc56b89-a8ff-416e-b5b3-6f1c06b0e2e4","info":"50% 할인 쿠폰","data":50,"type":"PERCENT"},{"id":"722c9d35-a11f-4e07-aa91-ec52054060c4","info":"70% 할인 쿠폰","data":70,"type":"PERCENT"},{"id":"7823e578-a419-404f-b016-73966505a87e","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"1ceecc21-8588-461b-b5e7-ffc968a32eea","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"31de22a8-bcc4-4e5a-9b57-cb92e0586108","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"},{"id":"074f7ab9-51c8-4b8c-8a4d-960755c55d02","info":"1,000원 할인 쿠폰","data":1000,"type":"FIXED"}] \ No newline at end of file +[] \ No newline at end of file From db792becb654250686317602c4af14ce7d1a1e60 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 19 Oct 2023 16:23:18 +0900 Subject: [PATCH 031/134] =?UTF-8?q?refactor:=20=EC=BD=98=EC=86=94=EA=B3=BC?= =?UTF-8?q?=20=EC=96=B4=ED=94=8C=EB=A6=AC=EC=BC=80=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 40 ++++++++++------ .../vouchermanagementsystem/util/Console.java | 46 +++++-------------- 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 481f4ac9c8..9a38c75e24 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -6,16 +6,16 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; +import java.io.BufferedReader; + @Component public class VoucherApplication { private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); private static final String INFO_DELIMINATOR = "\n"; - private final Console console; private final VoucherService voucherService; - public VoucherApplication(Console console, VoucherService service) { - this.console = console; + public VoucherApplication(VoucherService service) { this.voucherService = service; } @@ -24,15 +24,21 @@ public void run() { runCommand(); } catch (Exception e) { logger.error(e.toString()); - console.print("프로그램에 에러가 발생했습니다."); + Console.print("프로그램에 에러가 발생했습니다."); } close(); } public void runCommand() { - console.printCommandManual(); - String input = console.readString(); + Console.print(""" + === 쿠폰 관리 프로그램 === + exit: 프로그램 종료 + create: 쿠폰 생성 + list: 쿠폰 목록 조회 + blacklist: 블랙 리스트 유저 조회"""); + + String input = Console.readString(); try { CommandType commandType = CommandType.getCommandType(input); @@ -45,8 +51,10 @@ public void runCommand() { return; } } + } catch (NumberFormatException e) { + Console.print("숫자를 입력해 주세요."); } catch (IllegalArgumentException e) { - console.printError(e); + Console.print(e.getMessage()); } runCommand(); @@ -56,33 +64,35 @@ private void getBlacklistUsers() { logger.info("Call getBlackListUsers()"); String blacklistUsers = String.join(INFO_DELIMINATOR, voucherService.getBlacklistUsers()); - console.print(blacklistUsers); + Console.print(blacklistUsers); } private void createVoucher() { logger.info("Call createVoucher()"); - console.printVoucherTypes(); - int selected = console.readInt(); + Console.print(""" + 0: 고정 금액 할인 쿠폰 + 1: % 할인 쿠폰"""); + int selected = Console.readInt(); switch (selected) { case 0 -> createFixedAmountVoucher(); case 1 -> createPercentDiscountVoucher(); - default -> throw new RuntimeException("올바르지 않은 입력입니다."); + default -> throw new IllegalArgumentException("올바르지 않은 입력입니다."); } } private void createPercentDiscountVoucher() { logger.info("Call createPercentDiscountVoucher()"); - int percent = console.readInt("할인율을 입력해 주세요."); + int percent = Console.readInt("할인율을 입력해 주세요."); voucherService.createPercentDiscountVoucher(percent); } private void createFixedAmountVoucher() { logger.info("Call createFixedAmountVoucher()"); - int amount = console.readInt("할인 금액을 입력해 주세요."); + int amount = Console.readInt("할인 금액을 입력해 주세요."); voucherService.createFixedAmountVoucher(amount); } @@ -90,11 +100,11 @@ private void getVoucherList() { logger.info("Call getVoucherList()"); String vouchersInfo = String.join(INFO_DELIMINATOR, voucherService.getVouchersInfo()); - console.print(vouchersInfo); + Console.print(vouchersInfo); } private void close() { logger.info("Call close()"); - console.print("프로그램이 종료되었습니다."); + Console.print("프로그램이 종료되었습니다."); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 5e7e6e41b9..9957f816da 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -1,27 +1,19 @@ package team.marco.vouchermanagementsystem.util; -import org.springframework.stereotype.Component; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.util.Objects; -@Component -public class Console { - private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); +public final class Console { + private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - public void printCommandManual() { - System.out.println(""" - === 쿠폰 관리 프로그램 === - exit: 프로그램 종료 - create: 쿠폰 생성 - list: 쿠폰 목록 조회 - blacklist: 블랙 리스트 유저 조회 - """); + private Console() { + // Don't let anyone instantiate this class. } - public String readString() { + public static String readString() { System.out.print("> "); String input = readLine(); System.out.println(); @@ -33,40 +25,24 @@ public String readString() { return input; } - public int readInt() { + public static int readInt() { return Integer.parseInt(readString()); } - public int readInt(String prompt) { + public static int readInt(String prompt) { System.out.println(prompt + "\n"); return readInt(); } - private String readLine() { + private static String readLine() { try { return reader.readLine(); } catch (IOException e) { - throw new RuntimeException("unreadable input"); + throw new UncheckedIOException(e); } } - public void printVoucherTypes() { - System.out.println(""" - 0: 고정 금액 할인 쿠폰 - 1: % 할인 쿠폰 - """); - } - - public void printError(Exception e) { - if(e instanceof NumberFormatException) { - print("숫자를 입력해 주세요."); - } else { - print(e.getMessage()); - } - - } - - public void print(Object object) { + public static void print(Object object) { System.out.println(object); System.out.println(); } From f4ffc21bf663a856b59474a90a87687393a7adec Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 16:52:04 +0900 Subject: [PATCH 032/134] =?UTF-8?q?feat:=20=EC=95=A0=ED=94=8C=EB=A6=AC?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=85=98=20=EB=B0=B0=EB=84=88=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 6 +++++- src/main/resources/banner.txt | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/banner.txt diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f4eb546efe..9b12f072f5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,7 @@ +application: + title: "voucher-management-system" + version: "1.0.0" + file: path: blacklist: "src/main/resources/blacklist.csv" @@ -13,4 +17,4 @@ spring: --- spring: profiles: - active: "debug" \ No newline at end of file + active: "debug" diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000000..46f6b39b4a --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,7 @@ + ___ ___ __ _______ __ __ __ __ +| | |.-----.--.--.----.| |--.-----.----. | _ |.-----.-----.| |__|.----.---.-.| |_|__|.-----.-----. +| | || _ | | | __|| | -__| _| | || _ | _ || | || __| _ || _| || _ | | + \_____/ |_____|_____|____||__|__|_____|__| |___|___|| __| __||__|__||____|___._||____|__||_____|__|__| + |__| |__| +${application.title} ${application.version} +Powered by Spring Boot ${spring-boot.version} From 870132ab8491277846fc286372be4e319faec765 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 17:03:46 +0900 Subject: [PATCH 033/134] =?UTF-8?q?feat:=20voucher=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=88=EC=9D=84=20=EB=95=8C=EB=A7=8C=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marco/vouchermanagementsystem/VoucherApplication.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 9a38c75e24..4562ac7d43 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -100,7 +100,12 @@ private void getVoucherList() { logger.info("Call getVoucherList()"); String vouchersInfo = String.join(INFO_DELIMINATOR, voucherService.getVouchersInfo()); - Console.print(vouchersInfo); + + if (!vouchersInfo.isBlank()) { + Console.print(vouchersInfo); + } + + Console.print("조회가 완료되었습니다."); } private void close() { From ca47a68fcb78e2cfb07340b9b65352a0f1755ef4 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 17:28:37 +0900 Subject: [PATCH 034/134] =?UTF-8?q?refactor:=20voucher=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=A0=80=EC=9E=A5=20=ED=98=95=EC=8B=9D=EC=9D=84=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 data 필드로 통합 -> amount, percent 로 분리 --- .../model/FixedAmountVoucher.java | 9 +++---- .../model/PercentDiscountVoucher.java | 9 +++---- .../model/Voucher.java | 2 -- .../repository/LoadedJSONVoucher.java | 19 ++++++++----- src/main/resources/sample_data.json | 27 ++++++++++++++++++- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index 665296cd30..a36944848f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -38,13 +38,12 @@ public String getInfo() { return format("{0}원 할인 쿠폰", amount); } - @Override - public int getData() { - return amount; - } - @Override public VoucherType getType() { return VoucherType.FIXED; } + + public int getAmount() { + return amount; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index 3eb65d8283..f23cb04e39 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -46,13 +46,12 @@ public String getInfo() { return format("{0}% 할인 쿠폰", percent); } - @Override - public int getData() { - return percent; - } - @Override public VoucherType getType() { return VoucherType.PERCENT; } + + public int getPercent() { + return percent; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java index f3b35e8f47..5cbdd9ad07 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java @@ -7,7 +7,5 @@ public interface Voucher { String getInfo(); - int getData(); - VoucherType getType(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java index 7a31a10df1..86f34b16eb 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java @@ -10,8 +10,9 @@ public class LoadedJSONVoucher { private VoucherType type; private UUID id; - private int data; private String info; + private int amount; + private int percent; private LoadedJSONVoucher() { // for object mapper deserializing @@ -19,8 +20,8 @@ private LoadedJSONVoucher() { public Voucher convertToVoucher() { return switch (getType()) { - case FIXED -> new FixedAmountVoucher(getId(), getData()); - case PERCENT -> new PercentDiscountVoucher(getId(), getData()); + case FIXED -> new FixedAmountVoucher(getId(), getAmount()); + case PERCENT -> new PercentDiscountVoucher(getId(), getPercent()); }; } @@ -32,11 +33,15 @@ public UUID getId() { return id; } - public int getData() { - return data; - } - public String getInfo() { return info; } + + public int getAmount() { + return amount; + } + + public int getPercent() { + return percent; + } } diff --git a/src/main/resources/sample_data.json b/src/main/resources/sample_data.json index a1e251e6d6..fff19eb7b1 100644 --- a/src/main/resources/sample_data.json +++ b/src/main/resources/sample_data.json @@ -1 +1,26 @@ -[{"id":"861dbf02-3989-467c-b0a5-7c8b56640688","type":"FIXED","data":1000,"info":"1,000원 할인 쿠폰"},{"id":"9f749266-b875-431b-b728-d17ef34ca1ee","type":"PERCENT","data":10,"info":"10% 할인 쿠폰"}] +[ + { + "id": "369b3d5c-2e5d-48e4-9641-b146cb880030", + "amount": 10000, + "type": "FIXED", + "info": "10,000원 할인 쿠폰" + }, + { + "id": "707787f7-7d16-45fc-82e4-b1c8880e3aaa", + "percent": 20, + "type": "PERCENT", + "info": "20% 할인 쿠폰" + }, + { + "id": "c35fa9d5-953f-4f32-8dbd-3a84ddbd362a", + "amount": 100, + "type": "FIXED", + "info": "100원 할인 쿠폰" + }, + { + "id": "2d0e57b0-f500-4449-9d8c-ed2df6b93074", + "amount": 5000, + "type": "FIXED", + "info": "5,000원 할인 쿠폰" + } +] From 5a0a0265e98a212dee178c64488f88d83a18b378 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 18:05:47 +0900 Subject: [PATCH 035/134] style: reformatting code style --- .../vouchermanagementsystem/CommandType.java | 16 ++++----- .../VoucherApplication.java | 35 +++++++++++-------- .../VoucherManagementSystemApplication.java | 18 +++++----- .../model/FixedAmountVoucher.java | 1 + .../model/PercentDiscountVoucher.java | 5 +-- .../vouchermanagementsystem/model/User.java | 4 +-- .../repository/BlacklistRepository.java | 15 ++++---- .../repository/JSONFileVoucherRepository.java | 3 +- .../repository/LoadedJSONVoucher.java | 10 +++--- .../repository/MemoryVoucherRepository.java | 2 +- .../service/VoucherService.java | 6 ++-- .../vouchermanagementsystem/util/Console.java | 5 ++- src/main/resources/blacklist.csv | 2 +- src/main/resources/logback.xml | 10 +++--- 14 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java index 0ab75dd621..f0daf2b8bb 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/CommandType.java @@ -1,19 +1,15 @@ package team.marco.vouchermanagementsystem; -import java.text.MessageFormat; -import java.util.Arrays; +import static java.text.MessageFormat.format; public enum CommandType { CREATE, LIST, EXIT, BLACKLIST; public static CommandType getCommandType(String input) { - return Arrays.stream(CommandType.values()) - .filter(commandType -> commandType.isMatch(input)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("{0}: 사용할 수 없는 명령어입니다.", input))); - } - - private boolean isMatch(String input) { - return this.name().toLowerCase().equals(input); + try { + return valueOf(input.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException(format("{0}: 사용할 수 없는 명령어입니다.", input)); + } } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 4562ac7d43..e8b5fcc4ba 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -6,11 +6,11 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; -import java.io.BufferedReader; +import java.util.List; @Component public class VoucherApplication { - private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); + private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); private static final String INFO_DELIMINATOR = "\n"; private final VoucherService voucherService; @@ -21,7 +21,7 @@ public VoucherApplication(VoucherService service) { public void run() { try { - runCommand(); + selectCommand(); } catch (Exception e) { logger.error(e.toString()); Console.print("프로그램에 에러가 발생했습니다."); @@ -30,7 +30,7 @@ public void run() { close(); } - public void runCommand() { + public void selectCommand() { Console.print(""" === 쿠폰 관리 프로그램 === exit: 프로그램 종료 @@ -57,14 +57,7 @@ public void runCommand() { Console.print(e.getMessage()); } - runCommand(); - } - - private void getBlacklistUsers() { - logger.info("Call getBlackListUsers()"); - - String blacklistUsers = String.join(INFO_DELIMINATOR, voucherService.getBlacklistUsers()); - Console.print(blacklistUsers); + selectCommand(); } private void createVoucher() { @@ -73,6 +66,7 @@ private void createVoucher() { Console.print(""" 0: 고정 금액 할인 쿠폰 1: % 할인 쿠폰"""); + int selected = Console.readInt(); switch (selected) { @@ -99,10 +93,20 @@ private void createFixedAmountVoucher() { private void getVoucherList() { logger.info("Call getVoucherList()"); - String vouchersInfo = String.join(INFO_DELIMINATOR, voucherService.getVouchersInfo()); + printList(voucherService.getVouchersInfo()); + } + + private void getBlacklistUsers() { + logger.info("Call getBlackListUsers()"); - if (!vouchersInfo.isBlank()) { - Console.print(vouchersInfo); + printList(voucherService.getBlacklistUsers()); + } + + private void printList(List list) { + String joinedString = String.join(INFO_DELIMINATOR, list); + + if (!joinedString.isBlank()) { + Console.print(joinedString); } Console.print("조회가 완료되었습니다."); @@ -110,6 +114,7 @@ private void getVoucherList() { private void close() { logger.info("Call close()"); + Console.print("프로그램이 종료되었습니다."); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 92b35c27b1..72f2960e24 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -5,18 +5,20 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; +import team.marco.vouchermanagementsystem.model.VoucherType; @SpringBootApplication public class VoucherManagementSystemApplication { - private static final Logger logger = LoggerFactory.getLogger(VoucherManagementSystemApplication.class);; - public static void main(String[] args) { - ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); + private static final Logger logger = LoggerFactory.getLogger(VoucherManagementSystemApplication.class); - logger.info("Program start " + context.getEnvironment().getActiveProfiles()[0]); + public static void main(String[] args) { + ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); - VoucherApplication application = context.getBean(VoucherApplication.class); - application.run(); + logger.info("Program start " + context.getEnvironment().getActiveProfiles()[0]); - logger.info("Program exit"); - } + VoucherApplication application = context.getBean(VoucherApplication.class); + application.run(); + + logger.info("Program exit"); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java index a36944848f..e2a8345c5a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java @@ -9,6 +9,7 @@ public class FixedAmountVoucher implements Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); + private final UUID id; private final int amount; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java index f23cb04e39..757327e672 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java @@ -9,11 +9,12 @@ public class PercentDiscountVoucher implements Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); + private final UUID id; private final int percent; public PercentDiscountVoucher(int percent) { - checkValidation(percent); + validate(percent); this.id = UUID.randomUUID(); this.percent = percent; @@ -26,7 +27,7 @@ public PercentDiscountVoucher(UUID id, int percent) { this.percent = percent; } - private void checkValidation(int percent) { + private void validate(int percent) { if (percent <= 0) { throw new IllegalArgumentException(format("{0}: 할인율은 0% 이하일 수 없습니다.", percent)); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/User.java b/src/main/java/team/marco/vouchermanagementsystem/model/User.java index ac78e9f716..b5b31080a4 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/User.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/User.java @@ -5,8 +5,8 @@ import static java.text.MessageFormat.format; public class User { - private UUID id; - private String name; + private final UUID id; + private final String name; public User(UUID id, String name) { this.id = id; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 383f34cc0a..1cca79fbca 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -9,13 +9,14 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; @Repository public class BlacklistRepository { private final List blacklist; - public BlacklistRepository(@Value("${file.path.blacklist}") String path) { blacklist = load(path); } @@ -23,14 +24,16 @@ public BlacklistRepository(@Value("${file.path.blacklist}") String path) { private List load(String path) { List loaded = new ArrayList<>(); - try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8);) { - reader.readLine(); + try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { + reader.readLine(); // skip header reader.lines() .map(s -> s.split("[;,]")) .forEach(data -> loaded.add(new User(UUID.fromString(data[0]), data[1]))); - } catch (IOException e) { throw new RuntimeException("데이터를 가져올 수 없습니다." + e.getMessage()); } - return loaded; + } catch (IOException e) { + throw new RuntimeException("데이터를 가져올 수 없습니다."); + } + return loaded; } public List findAll() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index 3e51ebf692..aa06fb3169 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -25,11 +25,12 @@ public class JSONFileVoucherRepository implements VoucherRepository, DisposableB public JSONFileVoucherRepository(@Value("${file.path.voucher_data}") String path) { objectMapper = new ObjectMapper(); file = new File(path); + voucherMap = load(); } private Map load() { - if(!file.exists()) { + if (!file.exists()) { return new HashMap<>(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java index 86f34b16eb..c9576b81af 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java @@ -8,8 +8,8 @@ import java.util.UUID; public class LoadedJSONVoucher { - private VoucherType type; private UUID id; + private VoucherType type; private String info; private int amount; private int percent; @@ -25,14 +25,14 @@ public Voucher convertToVoucher() { }; } - public VoucherType getType() { - return type; - } - public UUID getId() { return id; } + public VoucherType getType() { + return type; + } + public String getInfo() { return info; } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index adf86635df..592bdcd036 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -12,7 +12,7 @@ @Profile({"local", "debug"}) @Repository public class MemoryVoucherRepository implements VoucherRepository { - Map voucherMap = new HashMap<>(); + private final Map voucherMap = new HashMap<>(); @Override public void save(Voucher voucher) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index 512efdb881..ea794636ff 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,12 +1,12 @@ package team.marco.vouchermanagementsystem.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.model.User; -import team.marco.vouchermanagementsystem.repository.BlacklistRepository; -import team.marco.vouchermanagementsystem.repository.VoucherRepository; import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.User; import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.repository.BlacklistRepository; +import team.marco.vouchermanagementsystem.repository.VoucherRepository; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 9957f816da..2c58c1e50b 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -30,7 +30,7 @@ public static int readInt() { } public static int readInt(String prompt) { - System.out.println(prompt + "\n"); + System.out.println(prompt + System.lineSeparator()); return readInt(); } @@ -43,7 +43,6 @@ private static String readLine() { } public static void print(Object object) { - System.out.println(object); - System.out.println(); + System.out.println(object + System.lineSeparator()); // thanks to SH, IJ } } diff --git a/src/main/resources/blacklist.csv b/src/main/resources/blacklist.csv index 9f7628e0af..3f6a9afedd 100644 --- a/src/main/resources/blacklist.csv +++ b/src/main/resources/blacklist.csv @@ -1,3 +1,3 @@ id,name 461b8847-578d-43c7-8472-d9374bbac41a,정의진 -461b8847-578d-43c7-8472-d9374bbac42b,김현우 \ No newline at end of file +461b8847-578d-43c7-8472-d9374bbac42b,김현우 diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 1e4f9986b0..21c2ecbbc5 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,6 +1,6 @@ - + @@ -28,24 +28,24 @@ - + - + - + - + From 9121c7968f69f8aea500740637ab1b3440be0eb3 Mon Sep 17 00:00:00 2001 From: ASak1104 Date: Thu, 19 Oct 2023 18:12:55 +0900 Subject: [PATCH 036/134] =?UTF-8?q?refactor:=20voucher=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EC=99=80=20blacklist=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 11 ++++++---- .../service/BlacklistService.java | 22 +++++++++++++++++++ .../service/VoucherService.java | 12 +--------- 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index e8b5fcc4ba..b754bf49c9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -3,6 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import team.marco.vouchermanagementsystem.service.BlacklistService; import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; @@ -14,9 +15,11 @@ public class VoucherApplication { private static final String INFO_DELIMINATOR = "\n"; private final VoucherService voucherService; + private final BlacklistService blacklistService; - public VoucherApplication(VoucherService service) { + public VoucherApplication(VoucherService service, BlacklistService blacklistService) { this.voucherService = service; + this.blacklistService = blacklistService; } public void run() { @@ -46,7 +49,7 @@ public void selectCommand() { switch (commandType) { case CREATE -> createVoucher(); case LIST -> getVoucherList(); - case BLACKLIST -> getBlacklistUsers(); + case BLACKLIST -> getBlacklist(); case EXIT -> { return; } @@ -96,10 +99,10 @@ private void getVoucherList() { printList(voucherService.getVouchersInfo()); } - private void getBlacklistUsers() { + private void getBlacklist() { logger.info("Call getBlackListUsers()"); - printList(voucherService.getBlacklistUsers()); + printList(blacklistService.getBlacklist()); } private void printList(List list) { diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java new file mode 100644 index 0000000000..4f4885efff --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java @@ -0,0 +1,22 @@ +package team.marco.vouchermanagementsystem.service; + +import org.springframework.stereotype.Service; +import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.repository.BlacklistRepository; + +import java.util.List; + +@Service +public class BlacklistService { + private final BlacklistRepository blacklistRepository; + + public BlacklistService(BlacklistRepository blacklistRepository) { + this.blacklistRepository = blacklistRepository; + } + + public List getBlacklist() { + return blacklistRepository.findAll().stream() + .map(User::getInfo) + .toList(); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index ea794636ff..95a502301a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -3,9 +3,7 @@ import org.springframework.stereotype.Service; import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.User; import team.marco.vouchermanagementsystem.model.Voucher; -import team.marco.vouchermanagementsystem.repository.BlacklistRepository; import team.marco.vouchermanagementsystem.repository.VoucherRepository; import java.util.List; @@ -13,11 +11,9 @@ @Service public class VoucherService { private final VoucherRepository voucherRepository; - private final BlacklistRepository blacklistRepository; - public VoucherService(VoucherRepository voucherRepository, BlacklistRepository blacklistRepository) { + public VoucherService(VoucherRepository voucherRepository) { this.voucherRepository = voucherRepository; - this.blacklistRepository = blacklistRepository; } public void createFixedAmountVoucher(int amount) { @@ -35,10 +31,4 @@ public List getVouchersInfo() { .map(Voucher::getInfo) .toList(); } - - public List getBlacklistUsers() { - return blacklistRepository.findAll().stream() - .map(User::getInfo) - .toList(); - } } From 0c1a8bf46797b3021d4d13502ee95c883c1a322d Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 21:35:48 +0900 Subject: [PATCH 037/134] =?UTF-8?q?refactor:=20Console=EC=9D=98=20readInt?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=EC=84=9C=20=ED=94=84?= =?UTF-8?q?=EB=A1=AC=ED=94=84=ED=8A=B8=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vouchermanagementsystem/VoucherApplication.java | 8 ++++++-- .../marco/vouchermanagementsystem/util/Console.java | 13 ++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index b754bf49c9..4de4d3ec69 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -82,14 +82,18 @@ private void createVoucher() { private void createPercentDiscountVoucher() { logger.info("Call createPercentDiscountVoucher()"); - int percent = Console.readInt("할인율을 입력해 주세요."); + Console.print("할인율을 입력해 주세요."); + int percent = Console.readInt(); + voucherService.createPercentDiscountVoucher(percent); } private void createFixedAmountVoucher() { logger.info("Call createFixedAmountVoucher()"); - int amount = Console.readInt("할인 금액을 입력해 주세요."); + Console.print("할인 금액을 입력해 주세요."); + int amount = Console.readInt(); + voucherService.createFixedAmountVoucher(amount); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 2c58c1e50b..0b5982f974 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -13,6 +13,10 @@ private Console() { // Don't let anyone instantiate this class. } + public static void print(Object object) { + System.out.println(object + System.lineSeparator()); // thanks to SH, IJ + } + public static String readString() { System.out.print("> "); String input = readLine(); @@ -29,11 +33,6 @@ public static int readInt() { return Integer.parseInt(readString()); } - public static int readInt(String prompt) { - System.out.println(prompt + System.lineSeparator()); - return readInt(); - } - private static String readLine() { try { return reader.readLine(); @@ -41,8 +40,4 @@ private static String readLine() { throw new UncheckedIOException(e); } } - - public static void print(Object object) { - System.out.println(object + System.lineSeparator()); // thanks to SH, IJ - } } From fdc1b1fe215e64b04ff746b2a7cb204c5fdabeea Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 21:42:46 +0900 Subject: [PATCH 038/134] =?UTF-8?q?VoucherApplication=EC=9D=98=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=EA=B8=B0=EB=8A=A5=EC=9D=84=20Console?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 15 ++------------- .../vouchermanagementsystem/util/Console.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 4de4d3ec69..b76ee84747 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -12,7 +12,6 @@ @Component public class VoucherApplication { private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); - private static final String INFO_DELIMINATOR = "\n"; private final VoucherService voucherService; private final BlacklistService blacklistService; @@ -100,23 +99,13 @@ private void createFixedAmountVoucher() { private void getVoucherList() { logger.info("Call getVoucherList()"); - printList(voucherService.getVouchersInfo()); + Console.printList(voucherService.getVouchersInfo()); } private void getBlacklist() { logger.info("Call getBlackListUsers()"); - printList(blacklistService.getBlacklist()); - } - - private void printList(List list) { - String joinedString = String.join(INFO_DELIMINATOR, list); - - if (!joinedString.isBlank()) { - Console.print(joinedString); - } - - Console.print("조회가 완료되었습니다."); + Console.printList(blacklistService.getBlacklist()); } private void close() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java index 0b5982f974..d4215530b7 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/util/Console.java @@ -4,9 +4,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UncheckedIOException; +import java.util.List; import java.util.Objects; public final class Console { + private static final String INFO_DELIMINATOR = "\n"; private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); private Console() { @@ -17,6 +19,16 @@ public static void print(Object object) { System.out.println(object + System.lineSeparator()); // thanks to SH, IJ } + public static void printList(List list) { + String joinedString = String.join(INFO_DELIMINATOR, list); + + if (!joinedString.isBlank()) { + Console.print(joinedString); + } + + Console.print("조회가 완료되었습니다."); + } + public static String readString() { System.out.print("> "); String input = readLine(); From a952d4b8c88944c4a2868df7f818556f7f1d00ed Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 21:52:24 +0900 Subject: [PATCH 039/134] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EB=B0=98=EB=B3=B5=20=EC=8B=A4=ED=96=89=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=EC=9D=84=20=EC=9E=AC=EA=B7=80=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20while=EB=AC=B8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index b76ee84747..93c703a723 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -7,8 +7,6 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; -import java.util.List; - @Component public class VoucherApplication { private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); @@ -16,17 +14,22 @@ public class VoucherApplication { private final VoucherService voucherService; private final BlacklistService blacklistService; + private Boolean isRunning; + public VoucherApplication(VoucherService service, BlacklistService blacklistService) { this.voucherService = service; this.blacklistService = blacklistService; + this.isRunning = true; } public void run() { - try { - selectCommand(); - } catch (Exception e) { - logger.error(e.toString()); - Console.print("프로그램에 에러가 발생했습니다."); + while (isRunning) { + try { + selectCommand(); + } catch (Exception e) { + logger.error(e.toString()); + Console.print("프로그램에 에러가 발생했습니다."); + } } close(); @@ -49,17 +52,13 @@ public void selectCommand() { case CREATE -> createVoucher(); case LIST -> getVoucherList(); case BLACKLIST -> getBlacklist(); - case EXIT -> { - return; - } + case EXIT -> isRunning = false; } } catch (NumberFormatException e) { Console.print("숫자를 입력해 주세요."); } catch (IllegalArgumentException e) { Console.print(e.getMessage()); } - - selectCommand(); } private void createVoucher() { From e7a187f91a00684233111ab9013c9b00a7ad4620 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 22:06:10 +0900 Subject: [PATCH 040/134] =?UTF-8?q?refactor:=20Application=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EB=A1=9C=EC=A7=81=EA=B3=BC=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=EC=9D=84=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherApplication.java | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 93c703a723..3336605774 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -27,12 +27,9 @@ public void run() { try { selectCommand(); } catch (Exception e) { - logger.error(e.toString()); - Console.print("프로그램에 에러가 발생했습니다."); + handleException(e); } } - - close(); } public void selectCommand() { @@ -45,19 +42,12 @@ public void selectCommand() { String input = Console.readString(); - try { - CommandType commandType = CommandType.getCommandType(input); - - switch (commandType) { - case CREATE -> createVoucher(); - case LIST -> getVoucherList(); - case BLACKLIST -> getBlacklist(); - case EXIT -> isRunning = false; - } - } catch (NumberFormatException e) { - Console.print("숫자를 입력해 주세요."); - } catch (IllegalArgumentException e) { - Console.print(e.getMessage()); + CommandType commandType = CommandType.getCommandType(input); + switch (commandType) { + case CREATE -> createVoucher(); + case LIST -> getVoucherList(); + case BLACKLIST -> getBlacklist(); + case EXIT -> isRunning = false; } } @@ -112,4 +102,22 @@ private void close() { Console.print("프로그램이 종료되었습니다."); } + + private void handleException(Exception e) { + if(e instanceof NumberFormatException) { + Console.print("숫자를 입력해 주세요."); + return; + } + + if(e instanceof IllegalArgumentException) { + Console.print(e.getMessage()); + return; + } + + logger.error(e.toString()); + + Console.print("프로그램에 에러가 발생했습니다."); + isRunning = false; + close(); + } } From ff16a1acec09a380602311d42ca20c81ca8d3e94 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 23:16:35 +0900 Subject: [PATCH 041/134] =?UTF-8?q?refactor:=20Voucher=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EC=83=81=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherManagementSystemApplication.java | 1 - .../model/Voucher.java | 11 ------- .../model/VoucherType.java | 5 --- .../{ => voucher}/FixedAmountVoucher.java | 31 ++++++++--------- .../{ => voucher}/PercentDiscountVoucher.java | 33 +++++++++---------- .../model/voucher/Voucher.java | 21 ++++++++++++ .../model/voucher/VoucherType.java | 5 +++ .../repository/JSONFileVoucherRepository.java | 2 +- .../repository/LoadedJSONVoucher.java | 13 +++----- .../repository/MemoryVoucherRepository.java | 2 +- .../repository/VoucherRepository.java | 2 +- .../service/VoucherService.java | 8 ++--- src/main/resources/sample_data.json | 26 ++++----------- 13 files changed, 72 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java rename src/main/java/team/marco/vouchermanagementsystem/model/{ => voucher}/FixedAmountVoucher.java (63%) rename src/main/java/team/marco/vouchermanagementsystem/model/{ => voucher}/PercentDiscountVoucher.java (66%) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 72f2960e24..71aaf2a116 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -5,7 +5,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import team.marco.vouchermanagementsystem.model.VoucherType; @SpringBootApplication public class VoucherManagementSystemApplication { diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java deleted file mode 100644 index 5cbdd9ad07..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Voucher.java +++ /dev/null @@ -1,11 +0,0 @@ -package team.marco.vouchermanagementsystem.model; - -import java.util.UUID; - -public interface Voucher { - UUID getId(); - - String getInfo(); - - VoucherType getType(); -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java b/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java deleted file mode 100644 index 8178c2971d..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/model/VoucherType.java +++ /dev/null @@ -1,5 +0,0 @@ -package team.marco.vouchermanagementsystem.model; - -public enum VoucherType { - FIXED, PERCENT -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java similarity index 63% rename from src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index e2a8345c5a..c560f38df1 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -1,16 +1,18 @@ -package team.marco.vouchermanagementsystem.model; +package team.marco.vouchermanagementsystem.model.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.MessageFormat; import java.util.UUID; import static java.text.MessageFormat.format; +import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.*; -public class FixedAmountVoucher implements Voucher { +public class FixedAmountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); - private final UUID id; + private final VoucherType type = FIXED; private final int amount; public FixedAmountVoucher(int amount) { @@ -18,33 +20,28 @@ public FixedAmountVoucher(int amount) { throw new IllegalArgumentException(format("{0}: 할인 금액은 0 보다 커야 합니다.", amount)); } - this.id = UUID.randomUUID(); this.amount = amount; - logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", id, amount); + logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); } public FixedAmountVoucher(UUID id, int amount) { - this.id = id; - this.amount = amount; - } - - @Override - public UUID getId() { - return id; - } + super(id); - @Override - public String getInfo() { - return format("{0}원 할인 쿠폰", amount); + this.amount = amount; } @Override public VoucherType getType() { - return VoucherType.FIXED; + return type; } public int getAmount() { return amount; } + + @Override + public String toString() { + return MessageFormat.format("FixedAmountVoucher'{'type={0}, amount={1}'}'", type, amount); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java similarity index 66% rename from src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 757327e672..d7c225bfee 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -1,29 +1,31 @@ -package team.marco.vouchermanagementsystem.model; +package team.marco.vouchermanagementsystem.model.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.text.MessageFormat; import java.util.UUID; import static java.text.MessageFormat.format; +import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.*; -public class PercentDiscountVoucher implements Voucher { - private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); +public class PercentDiscountVoucher extends Voucher { + private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); - private final UUID id; + private final VoucherType type = PERCENT; private final int percent; public PercentDiscountVoucher(int percent) { validate(percent); - this.id = UUID.randomUUID(); this.percent = percent; - logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", id, percent); + logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); } public PercentDiscountVoucher(UUID id, int percent) { - this.id = id; + super(id); + this.percent = percent; } @@ -37,22 +39,17 @@ private void validate(int percent) { } } - @Override - public UUID getId() { - return id; - } - - @Override - public String getInfo() { - return format("{0}% 할인 쿠폰", percent); - } - @Override public VoucherType getType() { - return VoucherType.PERCENT; + return type; } public int getPercent() { return percent; } + + @Override + public String toString() { + return MessageFormat.format("PercentDiscountVoucher'{'type={0}, percent={1}'}'", type, percent); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java new file mode 100644 index 0000000000..f9fb613062 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java @@ -0,0 +1,21 @@ +package team.marco.vouchermanagementsystem.model.voucher; + +import java.util.UUID; + +public abstract class Voucher { + private UUID id; + + public Voucher() { + this.id = UUID.randomUUID(); + } + + public Voucher(UUID id) { + this.id = id; + } + + public UUID getId() { + return id; + } + + abstract public VoucherType getType(); +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java new file mode 100644 index 0000000000..110623b418 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java @@ -0,0 +1,5 @@ +package team.marco.vouchermanagementsystem.model.voucher; + +public enum VoucherType { + FIXED, PERCENT +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index aa06fb3169..1f2767ac2b 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; import java.io.File; import java.io.IOException; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java index c9576b81af..3bd996fce2 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java @@ -1,16 +1,15 @@ package team.marco.vouchermanagementsystem.repository; -import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.Voucher; -import team.marco.vouchermanagementsystem.model.VoucherType; +import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.VoucherType; import java.util.UUID; public class LoadedJSONVoucher { private UUID id; private VoucherType type; - private String info; private int amount; private int percent; @@ -33,10 +32,6 @@ public VoucherType getType() { return type; } - public String getInfo() { - return info; - } - public int getAmount() { return amount; } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 592bdcd036..4a0bb0e3b0 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -2,7 +2,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java index d348a69749..9603ca40f2 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java @@ -1,6 +1,6 @@ package team.marco.vouchermanagementsystem.repository; -import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index 95a502301a..a2520e35cc 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,9 +1,9 @@ package team.marco.vouchermanagementsystem.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.model.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; import team.marco.vouchermanagementsystem.repository.VoucherRepository; import java.util.List; @@ -28,7 +28,7 @@ public void createPercentDiscountVoucher(int percent) { public List getVouchersInfo() { return voucherRepository.findAll().stream() - .map(Voucher::getInfo) + .map(Object::toString) .toList(); } } diff --git a/src/main/resources/sample_data.json b/src/main/resources/sample_data.json index fff19eb7b1..c9314c9b13 100644 --- a/src/main/resources/sample_data.json +++ b/src/main/resources/sample_data.json @@ -1,26 +1,12 @@ [ { - "id": "369b3d5c-2e5d-48e4-9641-b146cb880030", - "amount": 10000, - "type": "FIXED", - "info": "10,000원 할인 쿠폰" + "id": "bf095f82-7c2e-446d-9dd4-81a752bc7f8e", + "percent": 50, + "type": "PERCENT" }, { - "id": "707787f7-7d16-45fc-82e4-b1c8880e3aaa", - "percent": 20, - "type": "PERCENT", - "info": "20% 할인 쿠폰" - }, - { - "id": "c35fa9d5-953f-4f32-8dbd-3a84ddbd362a", - "amount": 100, - "type": "FIXED", - "info": "100원 할인 쿠폰" - }, - { - "id": "2d0e57b0-f500-4449-9d8c-ed2df6b93074", - "amount": 5000, - "type": "FIXED", - "info": "5,000원 할인 쿠폰" + "amount": 1000, + "id": "b3f3d7c7-44b5-4d32-a442-d77c29ebac99", + "type": "FIXED" } ] From 9b8d65839e043e8de250c82ae3ddf288483dce40 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 23:25:21 +0900 Subject: [PATCH 042/134] =?UTF-8?q?refactor:=20IOException=EC=9D=84=20Runt?= =?UTF-8?q?imeException=20=EB=8C=80=EC=8B=A0=20UncheckedIOException?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EA=B0=90=EC=8B=B8=EC=84=9C=20=EB=8D=98?= =?UTF-8?q?=EC=A7=80=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marco/vouchermanagementsystem/VoucherApplication.java | 7 ++++++- .../repository/BlacklistRepository.java | 3 ++- .../repository/JSONFileVoucherRepository.java | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java index 3336605774..4417744485 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java @@ -7,6 +7,8 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import team.marco.vouchermanagementsystem.util.Console; +import java.io.UncheckedIOException; + @Component public class VoucherApplication { private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); @@ -116,8 +118,11 @@ private void handleException(Exception e) { logger.error(e.toString()); - Console.print("프로그램에 에러가 발생했습니다."); + String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; + Console.print(errorMessage); + isRunning = false; + close(); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 1cca79fbca..1950970da1 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -6,6 +6,7 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -30,7 +31,7 @@ private List load(String path) { .map(s -> s.split("[;,]")) .forEach(data -> loaded.add(new User(UUID.fromString(data[0]), data[1]))); } catch (IOException e) { - throw new RuntimeException("데이터를 가져올 수 없습니다."); + throw new UncheckedIOException(e); } return loaded; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index 1f2767ac2b..a03dd8d381 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,7 +41,7 @@ private Map load() { try { loadedList = objectReader.readValue(file); } catch (IOException e) { - throw new RuntimeException("파일을 불러오는 과정에서 오류가 발생했습니다."); + throw new UncheckedIOException(e); } Map convertedMap = new HashMap<>(); @@ -65,7 +66,7 @@ public void destroy() { try { objectMapper.writeValue(file, voucherMap.values()); } catch (IOException e) { - throw new RuntimeException("파일을 저장하는 과정에서 오류가 발생했습니다."); + throw new UncheckedIOException(e); } } } From 3fbfc93bc435e1ed381504c1b706f8306b5170a1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 23:38:04 +0900 Subject: [PATCH 043/134] =?UTF-8?q?refactor:=20FixedAmountVoucher=EA=B3=BC?= =?UTF-8?q?=20PercentDiscountVoucher=EC=9D=98=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/voucher/FixedAmountVoucher.java | 16 +++++++++++++--- .../model/voucher/PercentDiscountVoucher.java | 10 ++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index c560f38df1..9dcfd9f47c 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -11,14 +11,14 @@ public class FixedAmountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); + private static final int MIN_AMOUNT = 100; + private static final int MAX_AMOUNT = 100000; private final VoucherType type = FIXED; private final int amount; public FixedAmountVoucher(int amount) { - if (amount <= 0) { - throw new IllegalArgumentException(format("{0}: 할인 금액은 0 보다 커야 합니다.", amount)); - } + validate(amount); this.amount = amount; @@ -31,6 +31,16 @@ public FixedAmountVoucher(UUID id, int amount) { this.amount = amount; } + private void validate(int percent) { + if (percent < MIN_AMOUNT) { + throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 작을 수 없습니다.", amount, MIN_AMOUNT)); + } + + if (percent > MAX_AMOUNT) { + throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 클 수 없습니다.", amount, MAX_AMOUNT)); + } + } + @Override public VoucherType getType() { return type; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index d7c225bfee..8eb88d8316 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -11,6 +11,8 @@ public class PercentDiscountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); + private static final int MIN_PERCENT = 1; + private static final int MAX_PERCENT = 50; private final VoucherType type = PERCENT; private final int percent; @@ -30,12 +32,12 @@ public PercentDiscountVoucher(UUID id, int percent) { } private void validate(int percent) { - if (percent <= 0) { - throw new IllegalArgumentException(format("{0}: 할인율은 0% 이하일 수 없습니다.", percent)); + if (percent < MIN_PERCENT) { + throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 작을 수 없습니다.", percent, MIN_PERCENT)); } - if (percent > 100) { - throw new IllegalArgumentException(format("{0}: 할인율은 100%를 초과할 수 없습니다.", percent)); + if (percent > MAX_PERCENT) { + throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 클 수 없습니다.", percent, MAX_PERCENT)); } } From 13a07aa039d9843036d813d3e0618cb11661af15 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 23:44:05 +0900 Subject: [PATCH 044/134] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20getter=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/voucher/FixedAmountVoucher.java | 4 ---- .../model/voucher/PercentDiscountVoucher.java | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 9dcfd9f47c..7b0dbff850 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -46,10 +46,6 @@ public VoucherType getType() { return type; } - public int getAmount() { - return amount; - } - @Override public String toString() { return MessageFormat.format("FixedAmountVoucher'{'type={0}, amount={1}'}'", type, amount); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 8eb88d8316..1d4151c736 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -46,10 +46,6 @@ public VoucherType getType() { return type; } - public int getPercent() { - return percent; - } - @Override public String toString() { return MessageFormat.format("PercentDiscountVoucher'{'type={0}, percent={1}'}'", type, percent); From 2d662ea8b750ee52206352e3f571b16c0f0b95f1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 22 Oct 2023 23:44:34 +0900 Subject: [PATCH 045/134] =?UTF-8?q?refactor:=20Voucher=20id=EB=A5=BC=20fin?= =?UTF-8?q?al=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../marco/vouchermanagementsystem/model/voucher/Voucher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java index f9fb613062..d89550328b 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java @@ -3,7 +3,7 @@ import java.util.UUID; public abstract class Voucher { - private UUID id; + private final UUID id; public Voucher() { this.id = UUID.randomUUID(); From d2771f09ae1869d0bde59f41cfde07b56e170ff2 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 23 Oct 2023 00:04:37 +0900 Subject: [PATCH 046/134] =?UTF-8?q?refactor:=20BlacklistRespository?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=EC=9E=90=20=EC=83=81=EC=88=98=EB=A1=9C=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BlacklistRepository.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 1950970da1..634188761d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -16,6 +16,7 @@ @Repository public class BlacklistRepository { + private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; private final List blacklist; public BlacklistRepository(@Value("${file.path.blacklist}") String path) { @@ -28,7 +29,7 @@ private List load(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header reader.lines() - .map(s -> s.split("[;,]")) + .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) .forEach(data -> loaded.add(new User(UUID.fromString(data[0]), data[1]))); } catch (IOException e) { throw new UncheckedIOException(e); From 4a623a0dfc02ddc589d03105a767d3560040dcfc Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 23 Oct 2023 00:14:23 +0900 Subject: [PATCH 047/134] =?UTF-8?q?refactor:=20VoucherManagementSystemAppl?= =?UTF-8?q?ication=EC=97=90=EC=84=9C=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EC=8B=9C=EC=9E=91=20=EC=8B=9C=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=90=98=EB=8A=94=20=EB=A1=9C=EA=B7=B8=20=ED=8F=AC=EB=A7=B7=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherManagementSystemApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 71aaf2a116..932b712300 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -13,7 +13,7 @@ public class VoucherManagementSystemApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); - logger.info("Program start " + context.getEnvironment().getActiveProfiles()[0]); + logger.info("Program start {}", context.getEnvironment().getActiveProfiles()); VoucherApplication application = context.getBean(VoucherApplication.class); application.run(); From 462cbb30792757a44171b39c5520d73a57b44189 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 23 Oct 2023 01:23:33 +0900 Subject: [PATCH 048/134] =?UTF-8?q?refactor:=20VoucherApplication=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B6=84=EB=A6=AC=20=ED=9B=84=20=EC=9D=98=EB=AF=B8?= =?UTF-8?q?=EB=A5=BC=20=EB=B6=84=EB=AA=85=ED=9E=88=20=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20VoucherApplication=20->=20ConsoleVoucherAp?= =?UTF-8?q?plication=EB=A1=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherManagementSystemApplication.java | 3 +- .../controller/UserController.java | 22 ++++++++++++++ .../controller/VoucherController.java | 29 ++++++++++++++++++ .../service/BlacklistService.java | 6 ++-- .../service/VoucherService.java | 6 ++-- .../{ => view}/CommandType.java | 2 +- .../ConsoleVoucherApplication.java} | 30 +++++++++---------- .../{ => view}/util/Console.java | 2 +- 8 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java rename src/main/java/team/marco/vouchermanagementsystem/{ => view}/CommandType.java (89%) rename src/main/java/team/marco/vouchermanagementsystem/{VoucherApplication.java => view/ConsoleVoucherApplication.java} (77%) rename src/main/java/team/marco/vouchermanagementsystem/{ => view}/util/Console.java (96%) diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java index 932b712300..7dc0557169 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java @@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; +import team.marco.vouchermanagementsystem.view.ConsoleVoucherApplication; @SpringBootApplication public class VoucherManagementSystemApplication { @@ -15,7 +16,7 @@ public static void main(String[] args) { logger.info("Program start {}", context.getEnvironment().getActiveProfiles()); - VoucherApplication application = context.getBean(VoucherApplication.class); + ConsoleVoucherApplication application = context.getBean(ConsoleVoucherApplication.class); application.run(); logger.info("Program exit"); diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java new file mode 100644 index 0000000000..6093eb924c --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java @@ -0,0 +1,22 @@ +package team.marco.vouchermanagementsystem.controller; + +import org.springframework.stereotype.Controller; +import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.service.BlacklistService; + +import java.util.List; + +@Controller +public class UserController { + private final BlacklistService blacklistService; + + public UserController(BlacklistService blacklistService) { + this.blacklistService = blacklistService; + } + + public List getBlacklistInfo() { + return blacklistService.getBlacklist().stream() + .map(User::getInfo) + .toList(); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java new file mode 100644 index 0000000000..edd9b0b32a --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java @@ -0,0 +1,29 @@ +package team.marco.vouchermanagementsystem.controller; + +import org.springframework.stereotype.Controller; +import team.marco.vouchermanagementsystem.service.VoucherService; + +import java.util.List; + +@Controller +public class VoucherController { + private final VoucherService voucherService; + + public VoucherController(VoucherService voucherService) { + this.voucherService = voucherService; + } + + public void createFixedAmountVoucher(int amount) { + voucherService.createFixedAmountVoucher(amount); + } + + public void createPercentDiscountVoucher(int percent) { + voucherService.createPercentDiscountVoucher(percent); + } + + public List getVouchersInfo() { + return voucherService.getVouchers().stream() + .map(Object::toString) + .toList(); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java index 4f4885efff..995ec7b56c 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java @@ -14,9 +14,7 @@ public BlacklistService(BlacklistRepository blacklistRepository) { this.blacklistRepository = blacklistRepository; } - public List getBlacklist() { - return blacklistRepository.findAll().stream() - .map(User::getInfo) - .toList(); + public List getBlacklist() { + return blacklistRepository.findAll(); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index a2520e35cc..e4ea2295e0 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -26,9 +26,7 @@ public void createPercentDiscountVoucher(int percent) { voucherRepository.save(voucher); } - public List getVouchersInfo() { - return voucherRepository.findAll().stream() - .map(Object::toString) - .toList(); + public List getVouchers() { + return voucherRepository.findAll(); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java similarity index 89% rename from src/main/java/team/marco/vouchermanagementsystem/CommandType.java rename to src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java index f0daf2b8bb..7f1f769481 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.view; import static java.text.MessageFormat.format; diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java similarity index 77% rename from src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java rename to src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java index 4417744485..e33eaf4a61 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java @@ -1,26 +1,26 @@ -package team.marco.vouchermanagementsystem; +package team.marco.vouchermanagementsystem.view; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.vouchermanagementsystem.service.BlacklistService; -import team.marco.vouchermanagementsystem.service.VoucherService; -import team.marco.vouchermanagementsystem.util.Console; +import team.marco.vouchermanagementsystem.controller.UserController; +import team.marco.vouchermanagementsystem.controller.VoucherController; +import team.marco.vouchermanagementsystem.view.util.Console; import java.io.UncheckedIOException; @Component -public class VoucherApplication { - private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); +public class ConsoleVoucherApplication { + private static final Logger logger = LoggerFactory.getLogger(ConsoleVoucherApplication.class); - private final VoucherService voucherService; - private final BlacklistService blacklistService; + private final VoucherController voucherController; + private final UserController userController; private Boolean isRunning; - public VoucherApplication(VoucherService service, BlacklistService blacklistService) { - this.voucherService = service; - this.blacklistService = blacklistService; + public ConsoleVoucherApplication(VoucherController voucherController, UserController userController) { + this.voucherController = voucherController; + this.userController = userController; this.isRunning = true; } @@ -75,7 +75,7 @@ private void createPercentDiscountVoucher() { Console.print("할인율을 입력해 주세요."); int percent = Console.readInt(); - voucherService.createPercentDiscountVoucher(percent); + voucherController.createPercentDiscountVoucher(percent); } private void createFixedAmountVoucher() { @@ -84,19 +84,19 @@ private void createFixedAmountVoucher() { Console.print("할인 금액을 입력해 주세요."); int amount = Console.readInt(); - voucherService.createFixedAmountVoucher(amount); + voucherController.createFixedAmountVoucher(amount); } private void getVoucherList() { logger.info("Call getVoucherList()"); - Console.printList(voucherService.getVouchersInfo()); + Console.printList(voucherController.getVouchersInfo()); } private void getBlacklist() { logger.info("Call getBlackListUsers()"); - Console.printList(blacklistService.getBlacklist()); + Console.printList(userController.getBlacklistInfo()); } private void close() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java similarity index 96% rename from src/main/java/team/marco/vouchermanagementsystem/util/Console.java rename to src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java index d4215530b7..cd8154a2c3 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.util; +package team.marco.vouchermanagementsystem.view.util; import java.io.BufferedReader; import java.io.IOException; From 221b310db539e02cec179b2cba00afb80f5673ac Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 23 Oct 2023 01:31:38 +0900 Subject: [PATCH 049/134] =?UTF-8?q?feat:=20prod=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JSONFileVoucherRepository.java | 2 +- src/main/resources/application.yml | 4 ++++ src/main/resources/logback.xml | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index a03dd8d381..2e51816345 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.UUID; -@Profile("dev") +@Profile({"prod", "dev"}) @Repository public class JSONFileVoucherRepository implements VoucherRepository, DisposableBean { private final Map voucherMap; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9b12f072f5..515b0639ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,6 +7,10 @@ file: blacklist: "src/main/resources/blacklist.csv" voucher_data: "src/main/resources/voucher_data.json" --- +spring: + profiles: + active: "prod" +--- spring: profiles: active: "dev" diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 21c2ecbbc5..84f72f7156 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -28,9 +28,11 @@ - - - + + + + + From 75298f671c0d51c43fea4b1387ee96a281497182 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 02:27:34 +0900 Subject: [PATCH 050/134] =?UTF-8?q?refactor:=20Console=EC=9D=98=20printLis?= =?UTF-8?q?t=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=EC=9D=84=20printString?= =?UTF-8?q?List=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/ConsoleVoucherApplication.java | 4 ++-- .../team/marco/vouchermanagementsystem/view/util/Console.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java index e33eaf4a61..5e4a963971 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java @@ -90,13 +90,13 @@ private void createFixedAmountVoucher() { private void getVoucherList() { logger.info("Call getVoucherList()"); - Console.printList(voucherController.getVouchersInfo()); + Console.printStringList(voucherController.getVouchersInfo()); } private void getBlacklist() { logger.info("Call getBlackListUsers()"); - Console.printList(userController.getBlacklistInfo()); + Console.printStringList(userController.getBlacklistInfo()); } private void close() { diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java b/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java index cd8154a2c3..c46127b345 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java @@ -19,7 +19,7 @@ public static void print(Object object) { System.out.println(object + System.lineSeparator()); // thanks to SH, IJ } - public static void printList(List list) { + public static void printStringList(List list) { String joinedString = String.join(INFO_DELIMINATOR, list); if (!joinedString.isBlank()) { From 634b64dc7bb62e093b371d9bf5f110a00d9c55bb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 02:48:59 +0900 Subject: [PATCH 051/134] =?UTF-8?q?FixedAmountVoucher=20=EC=B5=9C=EB=8C=80?= =?UTF-8?q?=20=ED=95=A0=EC=9D=B8=20=EA=B8=88=EC=95=A1=20100=EB=A7=8C?= =?UTF-8?q?=EC=9B=90=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/voucher/FixedAmountVoucher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 7b0dbff850..05e81b2b2a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -7,12 +7,12 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.*; +import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.FIXED; public class FixedAmountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); private static final int MIN_AMOUNT = 100; - private static final int MAX_AMOUNT = 100000; + private static final int MAX_AMOUNT = 1_000_000; private final VoucherType type = FIXED; private final int amount; From 987b265aef88ebd96630f623fe6107183e20e9ad Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 03:02:48 +0900 Subject: [PATCH 052/134] =?UTF-8?q?refactor:=20BlacklistRepository?= =?UTF-8?q?=EC=9D=98=20List=EC=97=90=20=EB=8F=99=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BlacklistRepository.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 634188761d..04570009a3 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -11,31 +11,28 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.UUID; @Repository public class BlacklistRepository { private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; - private final List blacklist; + private static final List blacklist = Collections.synchronizedList(new ArrayList<>()); public BlacklistRepository(@Value("${file.path.blacklist}") String path) { - blacklist = load(path); + load(path); } - private List load(String path) { - List loaded = new ArrayList<>(); - + private void load(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header reader.lines() .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .forEach(data -> loaded.add(new User(UUID.fromString(data[0]), data[1]))); + .forEach(data -> blacklist.add(new User(UUID.fromString(data[0]), data[1]))); } catch (IOException e) { throw new UncheckedIOException(e); } - - return loaded; } public List findAll() { From 5685033d94021c061412a1d8cf52662c2e041f7e Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 03:12:33 +0900 Subject: [PATCH 053/134] =?UTF-8?q?refactor:=20Repository=EC=97=90?= =?UTF-8?q?=EC=84=9C=20List=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=A0=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0,=20=EB=B6=88=EB=B3=80=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BlacklistRepository.java | 2 +- .../repository/JSONFileVoucherRepository.java | 3 ++- .../repository/MemoryVoucherRepository.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 04570009a3..85b9fdbcc0 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -36,6 +36,6 @@ private void load(String path) { } public List findAll() { - return blacklist; + return Collections.unmodifiableList(blacklist); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java index 2e51816345..2c62b63966 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java @@ -58,7 +58,8 @@ public void save(Voucher voucher) { @Override public List findAll() { - return voucherMap.values().stream().toList(); + return voucherMap.values().stream() + .toList(); } @Override diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 4a0bb0e3b0..632f80727b 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -21,6 +21,7 @@ public void save(Voucher voucher) { @Override public List findAll() { - return voucherMap.values().stream().toList(); + return voucherMap.values().stream() + .toList(); } } From 01ffc2fb81fc2069f231fafcb2dbc72ac45363fd Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 03:21:33 +0900 Subject: [PATCH 054/134] =?UTF-8?q?refactor:=20Json=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD=20JSO?= =?UTF-8?q?N=20->=20Json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...cherRepository.java => JsonFileVoucherRepository.java} | 8 ++++---- .../{LoadedJSONVoucher.java => LoadedJsonVoucher.java} | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/team/marco/vouchermanagementsystem/repository/{JSONFileVoucherRepository.java => JsonFileVoucherRepository.java} (90%) rename src/main/java/team/marco/vouchermanagementsystem/repository/{LoadedJSONVoucher.java => LoadedJsonVoucher.java} (93%) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java similarity index 90% rename from src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java index 2c62b63966..4f4b7519ca 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JSONFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java @@ -18,12 +18,12 @@ @Profile({"prod", "dev"}) @Repository -public class JSONFileVoucherRepository implements VoucherRepository, DisposableBean { +public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { private final Map voucherMap; private final ObjectMapper objectMapper; private final File file; - public JSONFileVoucherRepository(@Value("${file.path.voucher_data}") String path) { + public JsonFileVoucherRepository(@Value("${file.path.voucher_data}") String path) { objectMapper = new ObjectMapper(); file = new File(path); @@ -35,8 +35,8 @@ private Map load() { return new HashMap<>(); } - ObjectReader objectReader = objectMapper.readerForListOf(LoadedJSONVoucher.class); - List loadedList; + ObjectReader objectReader = objectMapper.readerForListOf(LoadedJsonVoucher.class); + List loadedList; try { loadedList = objectReader.readValue(file); diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java similarity index 93% rename from src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java index 3bd996fce2..431025507d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJSONVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java @@ -7,13 +7,13 @@ import java.util.UUID; -public class LoadedJSONVoucher { +public class LoadedJsonVoucher { private UUID id; private VoucherType type; private int amount; private int percent; - private LoadedJSONVoucher() { + private LoadedJsonVoucher() { // for object mapper deserializing } From 3f7e62de98687b9ae858513d85f124081d30f2ee Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 04:20:07 +0900 Subject: [PATCH 055/134] =?UTF-8?q?refactor:=20load=20->=20loadVoucherMap,?= =?UTF-8?q?=20loadedList=20->=20jsonVouchers=EB=A1=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85,=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JsonFileVoucherRepository.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java index 4f4b7519ca..0e014680c8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java @@ -19,7 +19,7 @@ @Profile({"prod", "dev"}) @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { - private final Map voucherMap; + private final Map voucherMap = new HashMap<>(); private final ObjectMapper objectMapper; private final File file; @@ -27,28 +27,24 @@ public JsonFileVoucherRepository(@Value("${file.path.voucher_data}") String path objectMapper = new ObjectMapper(); file = new File(path); - voucherMap = load(); + loadVoucherMap(); } - private Map load() { + private void loadVoucherMap() { if (!file.exists()) { - return new HashMap<>(); + return; } ObjectReader objectReader = objectMapper.readerForListOf(LoadedJsonVoucher.class); - List loadedList; + List jsonVouchers; try { - loadedList = objectReader.readValue(file); + jsonVouchers = objectReader.readValue(file); } catch (IOException e) { throw new UncheckedIOException(e); } - Map convertedMap = new HashMap<>(); - - loadedList.forEach(data -> convertedMap.put(data.getId(), data.convertToVoucher())); - - return convertedMap; + jsonVouchers.forEach(data -> voucherMap.put(data.getId(), data.convertToVoucher())); } @Override From 941078bad5fde1c08ff45fd28ff9d6a0e4f18662 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 04:22:21 +0900 Subject: [PATCH 056/134] =?UTF-8?q?refactor:=20load=20->=20loadBlacklist?= =?UTF-8?q?=EB=A1=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BlacklistRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 85b9fdbcc0..2f7f7f87f5 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -21,10 +21,10 @@ public class BlacklistRepository { private static final List blacklist = Collections.synchronizedList(new ArrayList<>()); public BlacklistRepository(@Value("${file.path.blacklist}") String path) { - load(path); + loadBlacklist(path); } - private void load(String path) { + private void loadBlacklist(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header reader.lines() From 2cdd9c199a5164a0d9eec6af77956b93f437c12e Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 04:29:47 +0900 Subject: [PATCH 057/134] =?UTF-8?q?refactor:=20Voucher=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=EC=B2=B4=EB=93=A4=EC=9D=98=20validation=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B5=9C=EB=8C=80,=20=EC=B5=9C=EC=86=9F=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=ED=95=9C=EB=B2=88=EC=97=90=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/marco/vouchermanagementsystem/model/User.java | 1 - .../model/voucher/FixedAmountVoucher.java | 10 +++------- .../model/voucher/PercentDiscountVoucher.java | 10 +++------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/User.java b/src/main/java/team/marco/vouchermanagementsystem/model/User.java index b5b31080a4..3239a3d366 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/User.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/User.java @@ -19,7 +19,6 @@ public User(String name) { } public String getInfo() { - return format("id: {0}, 고객명: {1} ", id, name); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 05e81b2b2a..2b04eb79e1 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -31,13 +31,9 @@ public FixedAmountVoucher(UUID id, int amount) { this.amount = amount; } - private void validate(int percent) { - if (percent < MIN_AMOUNT) { - throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 작을 수 없습니다.", amount, MIN_AMOUNT)); - } - - if (percent > MAX_AMOUNT) { - throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 클 수 없습니다.", amount, MAX_AMOUNT)); + private void validate(int amount) { + if (amount < MIN_AMOUNT || amount > MAX_AMOUNT) { + throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 작거나 {1}원 보다 클 수 없습니다.", amount, MIN_AMOUNT, MAX_AMOUNT)); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 1d4151c736..84ac8c90fc 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -7,7 +7,7 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.*; +import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.PERCENT; public class PercentDiscountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); @@ -32,12 +32,8 @@ public PercentDiscountVoucher(UUID id, int percent) { } private void validate(int percent) { - if (percent < MIN_PERCENT) { - throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 작을 수 없습니다.", percent, MIN_PERCENT)); - } - - if (percent > MAX_PERCENT) { - throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 클 수 없습니다.", percent, MAX_PERCENT)); + if (percent < MIN_PERCENT || percent > MAX_PERCENT) { + throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 작거나 {2}% 보다 클 수 없습니다.", percent, MIN_PERCENT, MAX_PERCENT)); } } From 771d192c91ea2f96165bf4811739aba4cff3e283 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 24 Oct 2023 04:34:52 +0900 Subject: [PATCH 058/134] =?UTF-8?q?refactor:=20=EA=B8=B0=EC=A1=B4=EC=9D=98?= =?UTF-8?q?=20BlacklistRepository=EB=A5=BC=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=ED=9B=84=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=EC=B2=B4=EB=A1=9C=20CsvBlacklistRepository?= =?UTF-8?q?=EB=A5=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/BlacklistRepository.java | 36 +--------------- .../repository/CsvBlacklistRepository.java | 42 +++++++++++++++++++ .../service/BlacklistService.java | 6 +-- 3 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 2f7f7f87f5..5a4b0eca95 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -1,41 +1,9 @@ package team.marco.vouchermanagementsystem.repository; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.User; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.UUID; -@Repository -public class BlacklistRepository { - private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; - private static final List blacklist = Collections.synchronizedList(new ArrayList<>()); - - public BlacklistRepository(@Value("${file.path.blacklist}") String path) { - loadBlacklist(path); - } - - private void loadBlacklist(String path) { - try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { - reader.readLine(); // skip header - reader.lines() - .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .forEach(data -> blacklist.add(new User(UUID.fromString(data[0]), data[1]))); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - public List findAll() { - return Collections.unmodifiableList(blacklist); - } +public interface BlacklistRepository { + List findAll(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java new file mode 100644 index 0000000000..e0f85d5e82 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java @@ -0,0 +1,42 @@ +package team.marco.vouchermanagementsystem.repository; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.model.User; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +@Repository +public class CsvBlacklistRepository implements BlacklistRepository { + private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; + private static final List blacklist = Collections.synchronizedList(new ArrayList<>()); + + public CsvBlacklistRepository(@Value("${file.path.blacklist}") String path) { + loadBlacklist(path); + } + + private void loadBlacklist(String path) { + try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { + reader.readLine(); // skip header + reader.lines() + .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) + .forEach(data -> blacklist.add(new User(UUID.fromString(data[0]), data[1]))); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + @Override + public List findAll() { + return Collections.unmodifiableList(blacklist); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java index 995ec7b56c..a42db3087e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java @@ -2,15 +2,15 @@ import org.springframework.stereotype.Service; import team.marco.vouchermanagementsystem.model.User; -import team.marco.vouchermanagementsystem.repository.BlacklistRepository; +import team.marco.vouchermanagementsystem.repository.CsvBlacklistRepository; import java.util.List; @Service public class BlacklistService { - private final BlacklistRepository blacklistRepository; + private final CsvBlacklistRepository blacklistRepository; - public BlacklistService(BlacklistRepository blacklistRepository) { + public BlacklistService(CsvBlacklistRepository blacklistRepository) { this.blacklistRepository = blacklistRepository; } From 93920e4cf7056b03ad9f81c37af55d1713ecaf1d Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 26 Oct 2023 13:44:39 +0900 Subject: [PATCH 059/134] =?UTF-8?q?refactor:=20Voucher=20=EC=BA=90?= =?UTF-8?q?=EC=8B=9C=20=EC=9E=90=EB=A3=8C=EA=B5=AC=EC=A1=B0=EB=A5=BC=20Has?= =?UTF-8?q?hMap=20->=20ConcurrentHashMap=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/JsonFileVoucherRepository.java | 4 ++-- .../repository/MemoryVoucherRepository.java | 4 ++-- src/main/resources/voucher_data.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java index 0e014680c8..d8f028562f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java @@ -11,15 +11,15 @@ import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; @Profile({"prod", "dev"}) @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { - private final Map voucherMap = new HashMap<>(); + private final Map voucherMap = new ConcurrentHashMap<>(); private final ObjectMapper objectMapper; private final File file; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java index 632f80727b..d9aca5484e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java @@ -4,15 +4,15 @@ import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; @Profile({"local", "debug"}) @Repository public class MemoryVoucherRepository implements VoucherRepository { - private final Map voucherMap = new HashMap<>(); + private final Map voucherMap = new ConcurrentHashMap<>(); @Override public void save(Voucher voucher) { diff --git a/src/main/resources/voucher_data.json b/src/main/resources/voucher_data.json index 0637a088a0..3055141aa4 100644 --- a/src/main/resources/voucher_data.json +++ b/src/main/resources/voucher_data.json @@ -1 +1 @@ -[] \ No newline at end of file +[{"id":"b4f46542-29f4-49a1-86fd-599aa1e684fb","type":"FIXED"}] \ No newline at end of file From 8aa85af82159a4018645e6fda82ad53af3146f44 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 26 Oct 2023 19:01:54 +0900 Subject: [PATCH 060/134] =?UTF-8?q?refactor:=20repository=EC=97=90?= =?UTF-8?q?=EC=84=9C=20load()=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=9D=98=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=83=80=EC=9E=85=EC=9D=84=20void=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=A1=9C=EB=93=9C=EB=90=9C=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20Map=EC=9D=84=20=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CsvBlacklistRepository.java | 12 ++++++------ .../repository/JsonFileVoucherRepository.java | 13 ++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java index e0f85d5e82..d073960cc9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java @@ -10,7 +10,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; @@ -18,18 +17,19 @@ @Repository public class CsvBlacklistRepository implements BlacklistRepository { private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; - private static final List blacklist = Collections.synchronizedList(new ArrayList<>()); + private final List blacklist; public CsvBlacklistRepository(@Value("${file.path.blacklist}") String path) { - loadBlacklist(path); + blacklist = loadBlacklist(path); } - private void loadBlacklist(String path) { + private List loadBlacklist(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header - reader.lines() + return reader.lines() .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .forEach(data -> blacklist.add(new User(UUID.fromString(data[0]), data[1]))); + .map(data -> new User(UUID.fromString(data[0]), data[1])) + .toList(); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java index d8f028562f..a43fb5aa1e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java @@ -19,7 +19,7 @@ @Profile({"prod", "dev"}) @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { - private final Map voucherMap = new ConcurrentHashMap<>(); + private final Map voucherMap; private final ObjectMapper objectMapper; private final File file; @@ -27,12 +27,13 @@ public JsonFileVoucherRepository(@Value("${file.path.voucher_data}") String path objectMapper = new ObjectMapper(); file = new File(path); - loadVoucherMap(); + voucherMap = loadVoucherMap(); } - private void loadVoucherMap() { + private Map loadVoucherMap() { + Map loadedVouchers = new ConcurrentHashMap<>(); if (!file.exists()) { - return; + return loadedVouchers; } ObjectReader objectReader = objectMapper.readerForListOf(LoadedJsonVoucher.class); @@ -44,7 +45,9 @@ private void loadVoucherMap() { throw new UncheckedIOException(e); } - jsonVouchers.forEach(data -> voucherMap.put(data.getId(), data.convertToVoucher())); + jsonVouchers.forEach(data -> loadedVouchers.put(data.getId(), data.convertToVoucher())); + + return loadedVouchers; } @Override From 1195580ecb648151db39e64047a60f6713742a30 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 02:58:08 +0900 Subject: [PATCH 061/134] =?UTF-8?q?chore:=20gradle=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=97=90=20jdbc=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index ead04db56f..82ce92784a 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,12 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' testImplementation 'org.springframework.boot:spring-boot-starter-test' + + // Jackson implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' + + // Jdbc + implementation group: 'com.mysql', name: 'mysql-connector-j', version: '8.1.0' } tasks.named('test') { From 61f5ade46bc02fa26985ecf433e5c99dbf137181 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 11:25:57 +0900 Subject: [PATCH 062/134] =?UTF-8?q?refactor:=20User=20->=20Customer=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 4 ++-- .../model/{User.java => Customer.java} | 6 +++--- .../repository/BlacklistRepository.java | 4 ++-- .../repository/CsvBlacklistRepository.java | 10 +++++----- .../service/BlacklistService.java | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/team/marco/vouchermanagementsystem/model/{User.java => Customer.java} (79%) diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java index 6093eb924c..264fa850fa 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java @@ -1,7 +1,7 @@ package team.marco.vouchermanagementsystem.controller; import org.springframework.stereotype.Controller; -import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.model.Customer; import team.marco.vouchermanagementsystem.service.BlacklistService; import java.util.List; @@ -16,7 +16,7 @@ public UserController(BlacklistService blacklistService) { public List getBlacklistInfo() { return blacklistService.getBlacklist().stream() - .map(User::getInfo) + .map(Customer::getInfo) .toList(); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/User.java b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java similarity index 79% rename from src/main/java/team/marco/vouchermanagementsystem/model/User.java rename to src/main/java/team/marco/vouchermanagementsystem/model/Customer.java index 3239a3d366..f471876d98 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/User.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java @@ -4,16 +4,16 @@ import static java.text.MessageFormat.format; -public class User { +public class Customer { private final UUID id; private final String name; - public User(UUID id, String name) { + public Customer(UUID id, String name) { this.id = id; this.name = name; } - public User(String name) { + public Customer(String name) { this.id = UUID.randomUUID(); this.name = name; } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java index 5a4b0eca95..0563621c0b 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java @@ -1,9 +1,9 @@ package team.marco.vouchermanagementsystem.repository; -import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.model.Customer; import java.util.List; public interface BlacklistRepository { - List findAll(); + List findAll(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java index d073960cc9..23ecc9ca90 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java @@ -2,7 +2,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.model.Customer; import java.io.BufferedReader; import java.io.IOException; @@ -17,18 +17,18 @@ @Repository public class CsvBlacklistRepository implements BlacklistRepository { private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; - private final List blacklist; + private final List blacklist; public CsvBlacklistRepository(@Value("${file.path.blacklist}") String path) { blacklist = loadBlacklist(path); } - private List loadBlacklist(String path) { + private List loadBlacklist(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header return reader.lines() .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .map(data -> new User(UUID.fromString(data[0]), data[1])) + .map(data -> new Customer(UUID.fromString(data[0]), data[1])) .toList(); } catch (IOException e) { throw new UncheckedIOException(e); @@ -36,7 +36,7 @@ private List loadBlacklist(String path) { } @Override - public List findAll() { + public List findAll() { return Collections.unmodifiableList(blacklist); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java index a42db3087e..7b797062b6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java @@ -1,7 +1,7 @@ package team.marco.vouchermanagementsystem.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.model.User; +import team.marco.vouchermanagementsystem.model.Customer; import team.marco.vouchermanagementsystem.repository.CsvBlacklistRepository; import java.util.List; @@ -14,7 +14,7 @@ public BlacklistService(CsvBlacklistRepository blacklistRepository) { this.blacklistRepository = blacklistRepository; } - public List getBlacklist() { + public List getBlacklist() { return blacklistRepository.findAll(); } } From 1ed28dcc26455a8ae7685a1506bf137a21a03212 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 11:56:51 +0900 Subject: [PATCH 063/134] =?UTF-8?q?feat:=20CustomerRepository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../configuration/JdbcTemplateConfig.java | 43 ++++++++++ .../controller/UserController.java | 5 +- .../model/Customer.java | 27 ++++++- .../repository/BlacklistRepository.java | 9 --- .../custromer/BlacklistRepository.java | 7 ++ .../CsvBlacklistRepository.java | 11 ++- .../custromer/CustomerIdAndName.java | 21 +++++ .../custromer/CustomerRepository.java | 13 +++ .../custromer/JdbcCustomerRepository.java | 79 +++++++++++++++++++ .../service/BlacklistService.java | 6 +- src/main/resources/application.yml | 7 ++ 12 files changed, 207 insertions(+), 22 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java rename src/main/java/team/marco/vouchermanagementsystem/repository/{ => custromer}/CsvBlacklistRepository.java (77%) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java diff --git a/build.gradle b/build.gradle index 82ce92784a..d0dfe1f644 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' testImplementation 'org.springframework.boot:spring-boot-starter-test' // Jackson diff --git a/src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java b/src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java new file mode 100644 index 0000000000..8d2fc379b2 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java @@ -0,0 +1,43 @@ +package team.marco.vouchermanagementsystem.configuration; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DriverManagerDataSource; + +import javax.sql.DataSource; + +@Configuration +public class JdbcTemplateConfig { + private final String username; + private final String password; + private final String driverClassName; + private final String url; + + public JdbcTemplateConfig(@Value("${spring.datasource.username}") String username, + @Value("${spring.datasource.password}") String password, + @Value("${spring.datasource.driver-class-name}") String driverClassName, + @Value("${spring.datasource.url}") String url) { + this.username = username; + this.password = password; + this.driverClassName = driverClassName; + this.url = url; + } + + @Bean + public DataSource dataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setUsername(username); + dataSource.setPassword(password); + dataSource.setDriverClassName(driverClassName); + dataSource.setUrl(url); + + return dataSource; + } + + @Bean + public JdbcTemplate jdbcTemplate(){ + return new JdbcTemplate(dataSource()); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java index 264fa850fa..cc59dfcc42 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java @@ -1,11 +1,12 @@ package team.marco.vouchermanagementsystem.controller; import org.springframework.stereotype.Controller; -import team.marco.vouchermanagementsystem.model.Customer; import team.marco.vouchermanagementsystem.service.BlacklistService; import java.util.List; +import static java.text.MessageFormat.format; + @Controller public class UserController { private final BlacklistService blacklistService; @@ -16,7 +17,7 @@ public UserController(BlacklistService blacklistService) { public List getBlacklistInfo() { return blacklistService.getBlacklist().stream() - .map(Customer::getInfo) + .map(dto -> format("id: {0}, 고객명: {1} ", dto.getId() , dto.getName())) .toList(); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java index f471876d98..fd39e7a8f4 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java @@ -1,5 +1,6 @@ package team.marco.vouchermanagementsystem.model; +import java.time.LocalDateTime; import java.util.UUID; import static java.text.MessageFormat.format; @@ -7,18 +8,40 @@ public class Customer { private final UUID id; private final String name; + private final String email; + private final LocalDateTime createdAt; - public Customer(UUID id, String name) { + public Customer(UUID id, String name, String email, LocalDateTime createdAt) { this.id = id; this.name = name; + this.email = email; + this.createdAt = createdAt; } - public Customer(String name) { + public Customer(String name, String email) { this.id = UUID.randomUUID(); + this.email = email; this.name = name; + this.createdAt = LocalDateTime.now(); } public String getInfo() { return format("id: {0}, 고객명: {1} ", id, name); } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java deleted file mode 100644 index 0563621c0b..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/BlacklistRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package team.marco.vouchermanagementsystem.repository; - -import team.marco.vouchermanagementsystem.model.Customer; - -import java.util.List; - -public interface BlacklistRepository { - List findAll(); -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java new file mode 100644 index 0000000000..c59895fc1b --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java @@ -0,0 +1,7 @@ +package team.marco.vouchermanagementsystem.repository.custromer; + +import java.util.List; + +public interface BlacklistRepository { + List findAll(); +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java similarity index 77% rename from src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java index 23ecc9ca90..02cc97cbd2 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java @@ -1,8 +1,7 @@ -package team.marco.vouchermanagementsystem.repository; +package team.marco.vouchermanagementsystem.repository.custromer; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.Customer; import java.io.BufferedReader; import java.io.IOException; @@ -17,18 +16,18 @@ @Repository public class CsvBlacklistRepository implements BlacklistRepository { private static final String DELIMITER_REGULAR_EXPRESSION = "[;,]"; - private final List blacklist; + private final List blacklist; public CsvBlacklistRepository(@Value("${file.path.blacklist}") String path) { blacklist = loadBlacklist(path); } - private List loadBlacklist(String path) { + private List loadBlacklist(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header return reader.lines() .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .map(data -> new Customer(UUID.fromString(data[0]), data[1])) + .map(data -> new CustomerIdAndName(UUID.fromString(data[0]), data[1])) .toList(); } catch (IOException e) { throw new UncheckedIOException(e); @@ -36,7 +35,7 @@ private List loadBlacklist(String path) { } @Override - public List findAll() { + public List findAll() { return Collections.unmodifiableList(blacklist); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java new file mode 100644 index 0000000000..54eeab3240 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java @@ -0,0 +1,21 @@ +package team.marco.vouchermanagementsystem.repository.custromer; + +import java.util.UUID; + +public class CustomerIdAndName { + private final UUID id; + private final String name; + + public CustomerIdAndName(UUID id, String name) { + this.id = id; + this.name = name; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java new file mode 100644 index 0000000000..07060b6008 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java @@ -0,0 +1,13 @@ +package team.marco.vouchermanagementsystem.repository.custromer; + +import team.marco.vouchermanagementsystem.model.Customer; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface CustomerRepository { + Customer insert(Customer customer); + List findAll(); + Optional findById(UUID customerId); +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java new file mode 100644 index 0000000000..bd04f06968 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java @@ -0,0 +1,79 @@ +package team.marco.vouchermanagementsystem.repository.custromer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.model.Customer; + +import java.nio.ByteBuffer; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.util.*; + +@Repository +public class JdbcCustomerRepository implements CustomerRepository { + private static final Logger logger = LoggerFactory.getLogger(JdbcCustomerRepository.class); + + private static final String SELECT_ALL_SQL = "SELECT * FROM customers"; + private static final String SELECT_BY_ID_SQL = "SELECT * FROM customers WHERE customer_id = UUID_TO_BIN(?)"; + private static final String INSERT_SQL = "INSERT INTO customers(customer_id, name, email, created_at) VALUES (UUID_TO_BIN(?), ?, ?, ?)"; + + private final JdbcTemplate jdbcTemplate; + + public JdbcCustomerRepository(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public Customer insert(Customer customer) { + int update = jdbcTemplate.update(INSERT_SQL, + customer.getId().toString().getBytes(), + customer.getName(), + customer.getEmail(), + customer.getCreatedAt()); + + if(update != 1) { + logger.error("사용자를 추가하는 과정에서 오류가 발생했습니다."); + throw new RuntimeException("사용자를 추가하는 과정에서 오류가 발생했습니다."); + } + + return customer; + } + + @Override + public List findAll() { + List customers = new ArrayList<>(); + jdbcTemplate.query(SELECT_ALL_SQL, (resultSet, rowNum) -> customers.add(resultSetToCustomer(resultSet))); + + return Collections.unmodifiableList(customers); + } + + @Override + public Optional findById(UUID customerId) { + try { + Customer customer = jdbcTemplate.queryForObject(SELECT_BY_ID_SQL, + (resultSet, rowNum) -> resultSetToCustomer(resultSet), customerId); + + return Optional.of(customer); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + + private Customer resultSetToCustomer(ResultSet resultSet) throws SQLException { + UUID customerId = bytesToUUID(resultSet.getBytes("customer_id")); + String customerName = resultSet.getString("name"); + String email = resultSet.getString("email"); + LocalDateTime createdAt = resultSet.getTimestamp("created_at").toLocalDateTime(); + + return new Customer(customerId, customerName, email, createdAt); + } + + private UUID bytesToUUID(byte[] bytes) { + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + return new UUID(byteBuffer.getLong(), byteBuffer.getLong()); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java index 7b797062b6..352fcae239 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java @@ -1,8 +1,8 @@ package team.marco.vouchermanagementsystem.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.model.Customer; -import team.marco.vouchermanagementsystem.repository.CsvBlacklistRepository; +import team.marco.vouchermanagementsystem.repository.custromer.CsvBlacklistRepository; +import team.marco.vouchermanagementsystem.repository.custromer.CustomerIdAndName; import java.util.List; @@ -14,7 +14,7 @@ public BlacklistService(CsvBlacklistRepository blacklistRepository) { this.blacklistRepository = blacklistRepository; } - public List getBlacklist() { + public List getBlacklist() { return blacklistRepository.findAll(); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 515b0639ce..fe5e93e3ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,13 @@ application: title: "voucher-management-system" version: "1.0.0" +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: wtwt + file: path: blacklist: "src/main/resources/blacklist.csv" From e0b39181b04d03cc8a8025e18b47238b8fd6a6f2 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 19:26:29 +0900 Subject: [PATCH 064/134] =?UTF-8?q?test:=20model=20=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=96=B4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/voucher/FixedAmountVoucher.java | 4 + .../model/voucher/PercentDiscountVoucher.java | 9 +- .../model/voucher/FixedAmountVoucherTest.java | 91 +++++++++++++++++++ .../voucher/PercentDiscountVoucherTest.java | 90 ++++++++++++++++++ 4 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java create mode 100644 src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 2b04eb79e1..803fc3025f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -42,6 +42,10 @@ public VoucherType getType() { return type; } + public int getAmount() { + return amount; + } + @Override public String toString() { return MessageFormat.format("FixedAmountVoucher'{'type={0}, amount={1}'}'", type, amount); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 84ac8c90fc..36aef393ca 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -27,12 +27,15 @@ public PercentDiscountVoucher(int percent) { public PercentDiscountVoucher(UUID id, int percent) { super(id); + validate(percent); this.percent = percent; + + logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); } private void validate(int percent) { - if (percent < MIN_PERCENT || percent > MAX_PERCENT) { + if (percent <= MIN_PERCENT || percent >= MAX_PERCENT) { throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 작거나 {2}% 보다 클 수 없습니다.", percent, MIN_PERCENT, MAX_PERCENT)); } } @@ -42,6 +45,10 @@ public VoucherType getType() { return type; } + public int getPercent() { + return percent; + } + @Override public String toString() { return MessageFormat.format("PercentDiscountVoucher'{'type={0}, percent={1}'}'", type, percent); diff --git a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java b/src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java new file mode 100644 index 0000000000..bee33d3607 --- /dev/null +++ b/src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java @@ -0,0 +1,91 @@ +package team.marco.vouchermanagementsystem.model.voucher; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class FixedAmountVoucherTest { + + @Test + void 고정금액_할인쿠폰_생성_성공() { + // 10,000원 할인 쿠폰 생성 + int discountAmount = 10_000; + FixedAmountVoucher voucher = new FixedAmountVoucher(discountAmount); + + // 1. UUID가 자동으로 할당 + assertThat(voucher.getId()).isNotNull(); + // 2. VoucherType은 자동으로 FIXED + assertThat(voucher.getType()).isEqualTo(VoucherType.FIXED); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getAmount()).isEqualTo(discountAmount); + } + + @Test + @DisplayName("UUID 값와 함께 할인 쿠폰 생성 가능") + void 고정비율_할인쿠폰_생성_성공_2() { + // 특정 UUID 값을 가진 10,000원 할인 쿠폰 생성 + UUID voucherId = UUID.randomUUID(); + int discountAmount = 10_000; + FixedAmountVoucher voucher = new FixedAmountVoucher(voucherId, discountAmount); + + // 1. 입력한 UUID로 생성 + assertThat(voucher.getId()).isEqualTo(voucherId); + // 2. VoucherType은 자동으로 FIXED + assertThat(voucher.getType()).isEqualTo(VoucherType.FIXED); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getAmount()).isEqualTo(discountAmount); + } + + @Test + @DisplayName("할인 금액은 100원보다 작을 수 없다.") + void 고정금액_할인쿠폰_생성_실패() { + // 1. 유효하지 않은 할인 금액 + int invalidAmount = 10; + // 2. 유효한 할인 금액 (엣지포인트) + int validAmount = 100; + + // 1. 10원 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new FixedAmountVoucher(invalidAmount); + }); + + // 2. 100원 할인 쿠폰 생성 시 에러 발생 X + assertDoesNotThrow(() -> { new FixedAmountVoucher(validAmount); }); + } + + @Test + @DisplayName("할인 금액은 100만원보다 클 수 없다.") + void 고정금액_할인쿠폰_생성_실패_2() { + // 1. 유효하지 않은 할인 금액 + int invalidAmount = 1_000_010; + // 2. 유효한 할인 금액 (엣지포인트) + int validAmount = 1_000_000; + + // 1. 100,010원 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new FixedAmountVoucher(invalidAmount); + }); + + // 2. 100,000원 할인 쿠폰 생성 시 에러 발생 X + assertDoesNotThrow(() -> { new FixedAmountVoucher(validAmount); }); + } + + @Test + @DisplayName("UUID와 할인 금액으로 쿠폰을 생성하는 경우에도 유효성 검사 실행") + void 고정비율_할인쿠폰_생성_실패_4() { + // UUID + 유효하지 않은 할인 비율 + UUID voucherId = UUID.randomUUID(); + int invalidAmount = -100; + + // 마이너스(-) 금액 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new PercentDiscountVoucher(voucherId, invalidAmount); + }); + } + +} \ No newline at end of file diff --git a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java b/src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java new file mode 100644 index 0000000000..9214785f0f --- /dev/null +++ b/src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java @@ -0,0 +1,90 @@ +package team.marco.vouchermanagementsystem.model.voucher; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class PercentDiscountVoucherTest { + @Test + void 고정비율_할인쿠폰_생성_성공() { + // 20% 할인 쿠폰 생성 + int discountPercent = 20; + PercentDiscountVoucher voucher = new PercentDiscountVoucher(discountPercent); + + // 1. UUID가 자동으로 할당 + assertThat(voucher.getId()).isNotNull(); + // 2. VoucherType은 자동으로 PERCENT + assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getPercent()).isEqualTo(discountPercent); + } + + @Test + @DisplayName("UUID 값와 함께 할인 쿠폰 생성 가능") + void 고정비율_할인쿠폰_생성_성공_2() { + // 특정 UUID 값을 가진 20% 할인 쿠폰 생성 + UUID voucherId = UUID.randomUUID(); + int discountPercent = 20; + PercentDiscountVoucher voucher = new PercentDiscountVoucher(voucherId, discountPercent); + + // 1. 입력한 UUID로 생성 + assertThat(voucher.getId()).isEqualTo(voucherId); + // 2. VoucherType은 자동으로 PERCENT + assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getPercent()).isEqualTo(discountPercent); + } + + @Test + @DisplayName("할인 비율은 0%일 수 없다.") + void 고정비율_할인쿠폰_생성_실패() { + // 유효하지 않은 할인 비율 + int zeroPercent = 0; + + // 0% 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new PercentDiscountVoucher(zeroPercent); + }); + } + + @Test + @DisplayName("할인 비율은 마이너스(-)일 수 없다.") + void 고정비율_할인쿠폰_생성_실패_2() { + // 유효하지 않은 할인 비율 + int minusPercent = -10; + + // -10% 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new PercentDiscountVoucher(minusPercent); + }); + } + + @Test + @DisplayName("할인 비율은 50%를 넘을 수 없다.") + void 고정비율_할인쿠폰_생성_실패_3() { + // 유효하지 않은 할인 비율 + int highPercent = 90; + + // 할인 비율이 50%가 넘는 할인 쿠폰 생성 시 에러 발생 + assertThrows(IllegalArgumentException.class, () -> { + new PercentDiscountVoucher(highPercent); + }); + } + + @Test + @DisplayName("UUID와 할인 비율로 쿠폰을 생성하는 경우에도 유효성 검사 실행") + void 고정비율_할인쿠폰_생성_실패_4() { + // UUID + 유효하지 않은 할인 비율 + UUID voucherId = UUID.randomUUID(); + int highPercent = 90; + + // 할인 비율이 50%가 넘는 할인 쿠폰 생성 시 에러 발생 2 + assertThrows(IllegalArgumentException.class, () -> { + new PercentDiscountVoucher(voucherId, highPercent); + }); + } +} \ No newline at end of file From 7d3cc1201e9915ba5e69c3068b841dc9ce123c20 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 19:26:56 +0900 Subject: [PATCH 065/134] =?UTF-8?q?feat:=20CommandMenu=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/marco/vouchermanagementsystem/view/CommandType.java | 2 +- .../view/ConsoleVoucherApplication.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java index 7f1f769481..2a59a67537 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java @@ -3,7 +3,7 @@ import static java.text.MessageFormat.format; public enum CommandType { - CREATE, LIST, EXIT, BLACKLIST; + CREATE, LIST, BLACKLIST, EXIT; public static CommandType getCommandType(String input) { try { diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java index 5e4a963971..a2a381ce0f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java @@ -37,10 +37,10 @@ public void run() { public void selectCommand() { Console.print(""" === 쿠폰 관리 프로그램 === - exit: 프로그램 종료 create: 쿠폰 생성 list: 쿠폰 목록 조회 - blacklist: 블랙 리스트 유저 조회"""); + blacklist: 블랙 리스트 유저 조회 + exit: 프로그램 종료"""); String input = Console.readString(); From d5cc985ffc55c2d59fabcaed5fc3d5b3141dc0f6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 20:11:47 +0900 Subject: [PATCH 066/134] =?UTF-8?q?test:=20MemoryVoucherRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JsonFileVoucherRepository.java | 5 +- .../{ => voucher}/LoadedJsonVoucher.java | 2 +- .../MemoryVoucherRepository.java | 5 +- .../{ => voucher}/VoucherRepository.java | 4 +- .../service/VoucherService.java | 2 +- .../voucher/MemoryVoucherRepositoryTest.java | 52 +++++++++++++++++++ 6 files changed, 62 insertions(+), 8 deletions(-) rename src/main/java/team/marco/vouchermanagementsystem/repository/{ => voucher}/JsonFileVoucherRepository.java (94%) rename src/main/java/team/marco/vouchermanagementsystem/repository/{ => voucher}/LoadedJsonVoucher.java (94%) rename src/main/java/team/marco/vouchermanagementsystem/repository/{ => voucher}/MemoryVoucherRepository.java (83%) rename src/main/java/team/marco/vouchermanagementsystem/repository/{ => voucher}/VoucherRepository.java (62%) create mode 100644 src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java similarity index 94% rename from src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java index a43fb5aa1e..4da12b521c 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository; +package team.marco.vouchermanagementsystem.repository.voucher; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; @@ -51,8 +51,9 @@ private Map loadVoucherMap() { } @Override - public void save(Voucher voucher) { + public Voucher save(Voucher voucher) { voucherMap.put(voucher.getId(), voucher); + return voucher; } @Override diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java similarity index 94% rename from src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java index 431025507d..04c1a63d43 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/LoadedJsonVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository; +package team.marco.vouchermanagementsystem.repository.voucher; import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java similarity index 83% rename from src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java index d9aca5484e..b3bea29682 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository; +package team.marco.vouchermanagementsystem.repository.voucher; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; @@ -15,8 +15,9 @@ public class MemoryVoucherRepository implements VoucherRepository { private final Map voucherMap = new ConcurrentHashMap<>(); @Override - public void save(Voucher voucher) { + public Voucher save(Voucher voucher) { voucherMap.put(voucher.getId(), voucher); + return voucher; } @Override diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java similarity index 62% rename from src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java rename to src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java index 9603ca40f2..8d81ffcc73 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/VoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java @@ -1,11 +1,11 @@ -package team.marco.vouchermanagementsystem.repository; +package team.marco.vouchermanagementsystem.repository.voucher; import team.marco.vouchermanagementsystem.model.voucher.Voucher; import java.util.List; public interface VoucherRepository { - void save(Voucher voucher); + Voucher save(Voucher voucher); List findAll(); } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index e4ea2295e0..77eaa0b42e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -4,7 +4,7 @@ import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import team.marco.vouchermanagementsystem.repository.VoucherRepository; +import team.marco.vouchermanagementsystem.repository.voucher.VoucherRepository; import java.util.List; diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java new file mode 100644 index 0000000000..a98c08af0d --- /dev/null +++ b/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java @@ -0,0 +1,52 @@ +package team.marco.vouchermanagementsystem.repository.voucher; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class MemoryVoucherRepositoryTest { + private MemoryVoucherRepository voucherRepository; + + @BeforeEach + void setUp() { + voucherRepository = new MemoryVoucherRepository(); + } + + @Test + @DisplayName("바우처 생성 시 생성된 바우처를 반환") + void 쿠폰_생성_성공() { + // 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + Voucher saved = voucherRepository.save(voucher); + + // 생성된 바우처 반환 + assertThat(saved).isEqualTo(voucher); + } + + @Test + void 전체_쿠폰_목록_조회_성공() { + // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + voucherRepository.save(voucher); + + int discountPercent = 10; + Voucher voucher2 = new PercentDiscountVoucher(discountPercent); + voucherRepository.save(voucher2); + + // 전체 쿠폰 목록 조회 + List vouchers = voucherRepository.findAll(); + + // 저장된 2개의 쿠폰이 조회 + assertThat(vouchers).hasSize(2); + } +} \ No newline at end of file From eea2b21815eed0788485c2fc4e28cf9ba90a44d1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 20:21:50 +0900 Subject: [PATCH 067/134] =?UTF-8?q?refactor:=20Customer=EC=97=90=EC=84=9C?= =?UTF-8?q?=20getInfo()=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/marco/vouchermanagementsystem/model/Customer.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java index fd39e7a8f4..98c8717fde 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java @@ -3,8 +3,6 @@ import java.time.LocalDateTime; import java.util.UUID; -import static java.text.MessageFormat.format; - public class Customer { private final UUID id; private final String name; @@ -25,10 +23,6 @@ public Customer(String name, String email) { this.createdAt = LocalDateTime.now(); } - public String getInfo() { - return format("id: {0}, 고객명: {1} ", id, name); - } - public UUID getId() { return id; } From 4abee978bc6f94d70ef8f0a55642b79cfb2351eb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 20:30:59 +0900 Subject: [PATCH 068/134] =?UTF-8?q?feat:=20JdbcVoucherRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VoucherController.java | 5 + .../model/voucher/FixedAmountVoucher.java | 13 +- .../model/voucher/PercentDiscountVoucher.java | 10 +- .../model/voucher/Voucher.java | 16 +- .../voucher/JdbcVoucherRepository.java | 140 ++++++++++++++++++ .../voucher/JsonFileVoucherRepository.java | 32 +++- .../repository/voucher/LoadedJsonVoucher.java | 53 +++++-- .../voucher/MemoryVoucherRepository.java | 28 ++++ .../repository/voucher/VoucherRepository.java | 12 ++ .../service/VoucherService.java | 18 +++ 10 files changed, 302 insertions(+), 25 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java index edd9b0b32a..cfa8f1c9a9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java @@ -4,6 +4,7 @@ import team.marco.vouchermanagementsystem.service.VoucherService; import java.util.List; +import java.util.UUID; @Controller public class VoucherController { @@ -26,4 +27,8 @@ public List getVouchersInfo() { .map(Object::toString) .toList(); } + + public void assignVoucherOwner(UUID voucherId, UUID customerId) { + voucherService.assignVoucherOwner(voucherId, customerId); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 803fc3025f..9e2d8e0d84 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -19,7 +19,6 @@ public class FixedAmountVoucher extends Voucher { public FixedAmountVoucher(int amount) { validate(amount); - this.amount = amount; logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); @@ -27,8 +26,18 @@ public FixedAmountVoucher(int amount) { public FixedAmountVoucher(UUID id, int amount) { super(id); + validate(amount); + this.amount = amount; + logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); + } + + public FixedAmountVoucher(UUID id, int amount, UUID ownerId) { + super(id, ownerId); + validate(amount); this.amount = amount; + + logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); } private void validate(int amount) { @@ -48,6 +57,6 @@ public int getAmount() { @Override public String toString() { - return MessageFormat.format("FixedAmountVoucher'{'type={0}, amount={1}'}'", type, amount); + return MessageFormat.format("{0}원 할인 쿠폰 {1}", amount, getOwnerId() == null ? "" : "/ 쿠폰 소지자: " + getOwnerId()); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 36aef393ca..838beecb05 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -19,7 +19,6 @@ public class PercentDiscountVoucher extends Voucher { public PercentDiscountVoucher(int percent) { validate(percent); - this.percent = percent; logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); @@ -28,7 +27,14 @@ public PercentDiscountVoucher(int percent) { public PercentDiscountVoucher(UUID id, int percent) { super(id); validate(percent); + this.percent = percent; + + logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); + } + public PercentDiscountVoucher(UUID id, Integer percent, UUID ownerId) { + super(id, ownerId); + validate(percent); this.percent = percent; logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); @@ -51,6 +57,6 @@ public int getPercent() { @Override public String toString() { - return MessageFormat.format("PercentDiscountVoucher'{'type={0}, percent={1}'}'", type, percent); + return MessageFormat.format("{0}% 할인 쿠폰 {1}", percent, getOwnerId() == null ? "" : "/ 쿠폰 소지자: " + getOwnerId()); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java index d89550328b..030abb6e44 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java @@ -4,18 +4,28 @@ public abstract class Voucher { private final UUID id; + private UUID ownerId; - public Voucher() { - this.id = UUID.randomUUID(); - } + public Voucher() { this.id = UUID.randomUUID(); } public Voucher(UUID id) { this.id = id; } + public Voucher(UUID id, UUID owner) { + this(id); + this.ownerId = owner; + } + public UUID getId() { return id; } + public UUID getOwnerId() { return ownerId; } + abstract public VoucherType getType(); + + public void assigneOwner(UUID owner) { + this.ownerId = ownerId; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java new file mode 100644 index 0000000000..df0a86720c --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java @@ -0,0 +1,140 @@ +package team.marco.vouchermanagementsystem.repository.voucher; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; +import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.vouchermanagementsystem.model.voucher.VoucherType; +import team.marco.vouchermanagementsystem.repository.custromer.CustomerRepository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +import static team.marco.vouchermanagementsystem.util.UUIDUtil.bytesToUUID; + +@Profile("prod") +@Repository +public class JdbcVoucherRepository implements VoucherRepository { + private static final Logger logger = LoggerFactory.getLogger(JdbcVoucherRepository.class); + + private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent) VALUES (UUID_TO_BIN(?), ?, ?, ?)"; + private static final String SELECT_ALL_SQL = "SELECT * FROM vouchers"; + private static final String SELECT_BY_OWNER_SQL = "SELECT * FROM vouchers WHERE owner_id = UUID_TO_BIN(?)"; + private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = UUID_TO_BIN(?)"; + private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = ? WHERE voucher_id = UUID_TO_BIN(?)"; + private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = UUID_TO_BIN(?)"; + + private final JdbcTemplate jdbcTemplate; + private final CustomerRepository customerRepository; + + public JdbcVoucherRepository(JdbcTemplate jdbcTemplate, CustomerRepository customerRepository) { + this.jdbcTemplate = jdbcTemplate; + this.customerRepository = customerRepository; + } + + @Override + public Voucher save(Voucher voucher) { + int update = 0; + switch (voucher.getType()) { + case FIXED -> { + FixedAmountVoucher amountVoucher = (FixedAmountVoucher) voucher; + update = jdbcTemplate.update(INSERT_SQL, + voucher.getId().toString().getBytes(), + voucher.getType().name(), + amountVoucher.getAmount(), + null); + } + case PERCENT -> { + PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; + update = jdbcTemplate.update(INSERT_SQL, + voucher.getId().toString().getBytes(), + voucher.getType().name(), + null, + percentVoucher.getPercent()); + } + } + + if(update != 1) { + logger.error("쿠폰을 추가하는 과정에서 오류가 발생했습니다."); + throw new RuntimeException("쿠폰을 추가하는 과정에서 오류가 발생했습니다."); + } + + return voucher; + } + + @Override + public List findAll() { + List vouchers = new ArrayList<>(); + jdbcTemplate.query(SELECT_ALL_SQL, (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet))); + + return Collections.unmodifiableList(vouchers); + } + + @Override + public List findByOwner(UUID ownerId) { + List vouchers = new ArrayList<>(); + jdbcTemplate.query(SELECT_BY_OWNER_SQL + , (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet)) + , ownerId.toString()); + + return Collections.unmodifiableList(vouchers); + } + + @Override + public Optional findById(UUID voucherId) { + return Optional.of(jdbcTemplate.queryForObject(SELECT_BY_ID_SQL + , (resultSet, rowNum) -> resultSetToVoucher(resultSet) + , voucherId.toString())); + } + + @Override + public Voucher update(Voucher voucher) { + int update = 0; + switch (voucher.getType()) { + case FIXED -> { + FixedAmountVoucher amountVoucher = (FixedAmountVoucher) voucher; + update = jdbcTemplate.update(UPDATE_BY_ID_SQL, + amountVoucher.getAmount(), + null, + amountVoucher.getOwnerId() != null ? amountVoucher.getOwnerId().toString().getBytes() : null, + voucher.getId().toString().getBytes()); + } + case PERCENT -> { + PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; + update = jdbcTemplate.update(UPDATE_BY_ID_SQL, + null, + percentVoucher.getPercent(), + percentVoucher.getOwnerId() != null ? percentVoucher.getOwnerId().toString().getBytes() : null, + voucher.getId().toString().getBytes()); + } + } + + if(update != 1) { + logger.error("쿠폰을 변경하는 과정에서 오류가 발생했습니다."); + throw new RuntimeException("쿠폰을 변경하는 과정에서 오류가 발생했습니다."); + } + + return voucher; + } + + @Override + public void deleteById(UUID voucherId) { + jdbcTemplate.update(DELETE_BY_ID_SQL, voucherId.toString().getBytes()); + } + + private Voucher resultSetToVoucher(ResultSet resultSet) throws SQLException { + UUID voucherId = bytesToUUID(resultSet.getBytes("voucher_id")); + VoucherType voucherType = VoucherType.valueOf(resultSet.getString("voucher_type")); + Integer amount = resultSet.getInt("amount"); + Integer percent = resultSet.getInt("percent"); + UUID ownerId = bytesToUUID(resultSet.getBytes("owner_id")); + + LoadedJsonVoucher jsonVoucher = new LoadedJsonVoucher(voucherId, voucherType, amount, percent, ownerId); + return jsonVoucher.jsonVoucherToVoucher(); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java index 4da12b521c..133277245e 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java @@ -13,10 +13,11 @@ import java.io.UncheckedIOException; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -@Profile({"prod", "dev"}) +@Profile("dev") @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { private final Map voucherMap; @@ -45,7 +46,7 @@ private Map loadVoucherMap() { throw new UncheckedIOException(e); } - jsonVouchers.forEach(data -> loadedVouchers.put(data.getId(), data.convertToVoucher())); + jsonVouchers.forEach(data -> loadedVouchers.put(data.getId(), data.jsonVoucherToVoucher())); return loadedVouchers; } @@ -53,6 +54,7 @@ private Map loadVoucherMap() { @Override public Voucher save(Voucher voucher) { voucherMap.put(voucher.getId(), voucher); + return voucher; } @@ -62,6 +64,32 @@ public List findAll() { .toList(); } + @Override + public List findByOwner(UUID ownerId) { + return voucherMap.values().stream() + .filter(v -> v.getOwnerId() == ownerId) + .toList(); + } + + @Override + public Optional findById(UUID voucherId) { + if(voucherMap.containsKey(voucherId)) { + return Optional.of(voucherMap.get(voucherId)); + } else return Optional.empty(); + } + + @Override + public Voucher update(Voucher voucher) { + voucherMap.put(voucher.getId(), voucher); + + return voucher; + } + + @Override + public void deleteById(UUID voucherId) { + voucherMap.remove(voucherId); + } + @Override public void destroy() { try { diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java index 04c1a63d43..ed60531a6d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java @@ -8,20 +8,18 @@ import java.util.UUID; public class LoadedJsonVoucher { - private UUID id; - private VoucherType type; - private int amount; - private int percent; - - private LoadedJsonVoucher() { - // for object mapper deserializing - } - - public Voucher convertToVoucher() { - return switch (getType()) { - case FIXED -> new FixedAmountVoucher(getId(), getAmount()); - case PERCENT -> new PercentDiscountVoucher(getId(), getPercent()); - }; + private final UUID id; + private final VoucherType type; + private final Integer amount; + private final Integer percent; + private final UUID ownerId; + + public LoadedJsonVoucher(UUID id, VoucherType type, Integer amount, Integer percent, UUID ownerId) { + this.id = id; + this.type = type; + this.amount = amount; + this.percent = percent; + this.ownerId = ownerId; } public UUID getId() { @@ -32,11 +30,34 @@ public VoucherType getType() { return type; } - public int getAmount() { + public Integer getAmount() { return amount; } - public int getPercent() { + public Integer getPercent() { return percent; } + + public UUID getOwnerId() { + return ownerId; + } + + public Voucher jsonVoucherToVoucher() { + return switch (type) { + case FIXED -> { + if(ownerId == null) { + yield new FixedAmountVoucher(id, amount); + } else { + yield new FixedAmountVoucher(id, amount, ownerId); + } + } + case PERCENT -> { + if (ownerId == null) { + yield new PercentDiscountVoucher(id, percent); + } else { + yield new PercentDiscountVoucher(id, percent, ownerId); + } + } + }; + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java index b3bea29682..9db9b32f90 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -17,6 +18,7 @@ public class MemoryVoucherRepository implements VoucherRepository { @Override public Voucher save(Voucher voucher) { voucherMap.put(voucher.getId(), voucher); + return voucher; } @@ -25,4 +27,30 @@ public List findAll() { return voucherMap.values().stream() .toList(); } + + @Override + public List findByOwner(UUID ownerId) { + return voucherMap.values().stream() + .filter(v -> v.getOwnerId() == ownerId) + .toList(); + } + + @Override + public Optional findById(UUID voucherId) { + if(voucherMap.containsKey(voucherId)) { + return Optional.of(voucherMap.get(voucherId)); + } else return Optional.empty(); + } + + @Override + public Voucher update(Voucher voucher) { + voucherMap.put(voucher.getId(), voucher); + + return voucher; + } + + @Override + public void deleteById(UUID voucherId) { + voucherMap.remove(voucherId); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java index 8d81ffcc73..3a375d618f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java @@ -3,9 +3,21 @@ import team.marco.vouchermanagementsystem.model.voucher.Voucher; import java.util.List; +import java.util.Optional; +import java.util.UUID; public interface VoucherRepository { Voucher save(Voucher voucher); List findAll(); + + List findByOwner(UUID ownerId); + + Optional findById(UUID voucherId); + + Voucher update(Voucher voucher); + + void deleteById(UUID voucherId); + + } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index 77eaa0b42e..b7d51f8b42 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -1,26 +1,34 @@ package team.marco.vouchermanagementsystem.service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; import team.marco.vouchermanagementsystem.model.voucher.Voucher; import team.marco.vouchermanagementsystem.repository.voucher.VoucherRepository; import java.util.List; +import java.util.UUID; @Service public class VoucherService { + private static final Logger logger = LoggerFactory.getLogger(VoucherService.class); + private final VoucherRepository voucherRepository; public VoucherService(VoucherRepository voucherRepository) { this.voucherRepository = voucherRepository; } + @Transactional public void createFixedAmountVoucher(int amount) { Voucher voucher = new FixedAmountVoucher(amount); voucherRepository.save(voucher); } + @Transactional public void createPercentDiscountVoucher(int percent) { Voucher voucher = new PercentDiscountVoucher(percent); voucherRepository.save(voucher); @@ -29,4 +37,14 @@ public void createPercentDiscountVoucher(int percent) { public List getVouchers() { return voucherRepository.findAll(); } + + @Transactional + public void assignVoucherOwner(UUID voucherId, UUID customerId) { + logger.debug("[VoucherService] Call assignVoucherOwner()"); + + Voucher voucher = voucherRepository.findById(voucherId).orElseThrow(); + voucher.assigneOwner(customerId); + + voucherRepository.update(voucher); + } } From 46fe36d7ab62c2d260071c3c22c89e0cf1a50d0c Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 20:31:37 +0900 Subject: [PATCH 069/134] =?UTF-8?q?feat:=20UUID=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=9C=A0=ED=8B=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/JdbcCustomerRepository.java | 11 ++++------- .../vouchermanagementsystem/util/UUIDUtil.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java index bd04f06968..79a3d7ed17 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java @@ -7,12 +7,14 @@ import org.springframework.stereotype.Repository; import team.marco.vouchermanagementsystem.model.Customer; -import java.nio.ByteBuffer; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; +import static team.marco.vouchermanagementsystem.util.UUIDUtil.bytesToUUID; + @Repository public class JdbcCustomerRepository implements CustomerRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcCustomerRepository.class); @@ -33,7 +35,7 @@ public Customer insert(Customer customer) { customer.getId().toString().getBytes(), customer.getName(), customer.getEmail(), - customer.getCreatedAt()); + Timestamp.valueOf(customer.getCreatedAt())); if(update != 1) { logger.error("사용자를 추가하는 과정에서 오류가 발생했습니다."); @@ -71,9 +73,4 @@ private Customer resultSetToCustomer(ResultSet resultSet) throws SQLException { return new Customer(customerId, customerName, email, createdAt); } - - private UUID bytesToUUID(byte[] bytes) { - ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); - return new UUID(byteBuffer.getLong(), byteBuffer.getLong()); - } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java b/src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java new file mode 100644 index 0000000000..1c1d9e8dd2 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java @@ -0,0 +1,16 @@ +package team.marco.vouchermanagementsystem.util; + +import java.nio.ByteBuffer; +import java.util.UUID; + +public final class UUIDUtil { + private UUIDUtil() { + // Don't let anyone instantiate this class. + } + + public static UUID bytesToUUID(byte[] bytes) { + if(bytes == null) return null; + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + return new UUID(byteBuffer.getLong(), byteBuffer.getLong()); + } +} From c86bda2bd140bf10a9fc6cb8126b8dfefd54f1d6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 21:34:10 +0900 Subject: [PATCH 070/134] =?UTF-8?q?test:=20JdbcVoucherRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/voucher/FixedAmountVoucher.java | 9 ++ .../model/voucher/PercentDiscountVoucher.java | 9 ++ .../model/voucher/Voucher.java | 2 +- .../voucher/JdbcVoucherRepository.java | 13 +- .../voucher/JdbcVoucherRepositoryTest.java | 137 ++++++++++++++++++ 5 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index 9e2d8e0d84..dad36edcc8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -32,6 +32,15 @@ public FixedAmountVoucher(UUID id, int amount) { logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); } + public FixedAmountVoucher(int amount, UUID ownerId) { + validate(amount); + this.amount = amount; + + assigneOwner(ownerId); + + logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); + } + public FixedAmountVoucher(UUID id, int amount, UUID ownerId) { super(id, ownerId); validate(amount); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index 838beecb05..d3d7694b51 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -32,6 +32,15 @@ public PercentDiscountVoucher(UUID id, int percent) { logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); } + public PercentDiscountVoucher(int percent, UUID ownerId) { + validate(percent); + this.percent = percent; + + assigneOwner(ownerId); + + logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); + } + public PercentDiscountVoucher(UUID id, Integer percent, UUID ownerId) { super(id, ownerId); validate(percent); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java index 030abb6e44..99a4918623 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java @@ -25,7 +25,7 @@ public UUID getId() { abstract public VoucherType getType(); - public void assigneOwner(UUID owner) { + public void assigneOwner(UUID ownerId) { this.ownerId = ownerId; } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java index df0a86720c..8466884ae5 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java @@ -22,11 +22,11 @@ public class JdbcVoucherRepository implements VoucherRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcVoucherRepository.class); - private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent) VALUES (UUID_TO_BIN(?), ?, ?, ?)"; + private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent, owner_id) VALUES (UUID_TO_BIN(?), ?, ?, ?, UUID_TO_BIN(?))"; private static final String SELECT_ALL_SQL = "SELECT * FROM vouchers"; private static final String SELECT_BY_OWNER_SQL = "SELECT * FROM vouchers WHERE owner_id = UUID_TO_BIN(?)"; private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = UUID_TO_BIN(?)"; - private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = ? WHERE voucher_id = UUID_TO_BIN(?)"; + private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = UUID_TO_BIN(?) WHERE voucher_id = UUID_TO_BIN(?)"; private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = UUID_TO_BIN(?)"; private final JdbcTemplate jdbcTemplate; @@ -47,7 +47,8 @@ public Voucher save(Voucher voucher) { voucher.getId().toString().getBytes(), voucher.getType().name(), amountVoucher.getAmount(), - null); + null, + voucher.getOwnerId() == null ? null : voucher.getOwnerId().toString().getBytes()); } case PERCENT -> { PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; @@ -55,7 +56,8 @@ public Voucher save(Voucher voucher) { voucher.getId().toString().getBytes(), voucher.getType().name(), null, - percentVoucher.getPercent()); + percentVoucher.getPercent(), + voucher.getOwnerId() == null ? null : voucher.getOwnerId().toString().getBytes()); } } @@ -70,7 +72,8 @@ public Voucher save(Voucher voucher) { @Override public List findAll() { List vouchers = new ArrayList<>(); - jdbcTemplate.query(SELECT_ALL_SQL, (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet))); + jdbcTemplate.query(SELECT_ALL_SQL + , (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet))); return Collections.unmodifiableList(vouchers); } diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java new file mode 100644 index 0000000000..120791bccf --- /dev/null +++ b/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java @@ -0,0 +1,137 @@ +package team.marco.vouchermanagementsystem.repository.voucher; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Transactional; +import team.marco.vouchermanagementsystem.model.Customer; +import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; +import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.vouchermanagementsystem.repository.custromer.JdbcCustomerRepository; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +@SpringBootTest +@ActiveProfiles("prod") +class JdbcVoucherRepositoryTest { + @Autowired + private JdbcVoucherRepository voucherRepository; + + @Autowired + private JdbcCustomerRepository customerRepository; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @BeforeEach + void setUp() { + String query = "DELETE FROM vouchers"; + jdbcTemplate.update(query); + } + + @Test + @DisplayName("바우처 생성 시 생성된 바우처를 반환") + void 쿠폰_생성_성공() { + // 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + Voucher saved = voucherRepository.save(voucher); + + // 생성된 바우처 반환 + Assertions.assertThat(saved).isEqualTo(voucher); + } + + @Test + void 전체_쿠폰_목록_조회_성공() { + // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + voucherRepository.save(voucher); + + int discountPercent = 10; + Voucher voucher2 = new PercentDiscountVoucher(discountPercent); + voucherRepository.save(voucher2); + + // 전체 쿠폰 목록 조회 + List vouchers = voucherRepository.findAll(); + + // 저장된 2개의 쿠폰이 조회 + assertThat(vouchers).hasSize(2); + } + + @Test + void 쿠폰_아이디로_조회_성공() { + // 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + voucherRepository.save(voucher); + + // 쿠폰 번호로 조회 + Voucher found = voucherRepository.findById(voucher.getId()).get(); + + // 저장한 쿠폰과 동일한 쿠폰 반환 + Assertions.assertThat(found.getId()).isEqualTo(voucher.getId()); + } + + @Test + void 쿠폰_소지자_아이디로_조회_성공() { + // 쿠폰 소지자와 함께 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Customer customer = new Customer("customer", "customer@gmail.com"); + customerRepository.insert(customer); + + Voucher voucher = new FixedAmountVoucher(discountAmount, customer.getId()); + voucherRepository.save(voucher); + + // 쿠폰 소지자 아이디로 조회 + List found = voucherRepository.findByOwner(customer.getId()); + + // 저장한 쿠폰과 동일한 쿠폰 반환 + Assertions.assertThat(found).hasSize(1); + Assertions.assertThat(found.get(0).getId()).isEqualTo(voucher.getId()); + } + + @Test + void 쿠폰_정보_수정_성공() { + // 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + voucherRepository.save(voucher); + + // 쿠폰 소지자 할당 (쿠폰 정보 수정) + Customer customer = new Customer("customer", "customer@gmail.com"); + customerRepository.insert(customer); + voucher.assigneOwner(customer.getId()); + + Voucher updated = voucherRepository.update(voucher); + + // 변경된 쿠폰 정보가 저장 + Assertions.assertThat(updated.getId()).isEqualTo(voucher.getId()); + Assertions.assertThat(updated.getOwnerId()).isEqualTo(customer.getId()); + } + + @Test + void 쿠폰_번호로_삭제_성공() { + // 1,000원 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = new FixedAmountVoucher(discountAmount); + voucherRepository.save(voucher); + + // 쿠폰 삭제 + voucherRepository.deleteById(voucher.getId()); + + // 쿠폰이 삭제됨 + List vouchers = voucherRepository.findAll(); + assertThat(vouchers).hasSize(0); + } + +} \ No newline at end of file From 2267d4c816b0dc77ac14a07b0e4cc0a9da4922df Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 22:00:23 +0900 Subject: [PATCH 071/134] =?UTF-8?q?test:=20JdbcCustomerRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/JdbcCustomerRepository.java | 3 +- .../custromer/JdbcCustomerRepositoryTest.java | 101 ++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java index 79a3d7ed17..f94984db67 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java @@ -57,7 +57,8 @@ public List findAll() { public Optional findById(UUID customerId) { try { Customer customer = jdbcTemplate.queryForObject(SELECT_BY_ID_SQL, - (resultSet, rowNum) -> resultSetToCustomer(resultSet), customerId); + (resultSet, rowNum) -> resultSetToCustomer(resultSet), + customerId.toString().getBytes()); return Optional.of(customer); } catch (DataAccessException e) { diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java new file mode 100644 index 0000000000..461137cce8 --- /dev/null +++ b/src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java @@ -0,0 +1,101 @@ +package team.marco.vouchermanagementsystem.repository.custromer; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DuplicateKeyException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Transactional; +import team.marco.vouchermanagementsystem.model.Customer; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@Transactional +@SpringBootTest +@ActiveProfiles("prod") +class JdbcCustomerRepositoryTest { + @Autowired + private JdbcCustomerRepository customerRepository; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @BeforeEach + void setUp() { + String query = "DELETE FROM customers"; + jdbcTemplate.update(query); + } + + @Test + @DisplayName("유저 생성 시 생성된 유저를 반환") + void 사용자_생성_성공() { + // 사용자 생성 + String name = "customer"; + String email = "customer@gmail.com"; + Customer customer = new Customer(name, email); + + Customer saved = customerRepository.insert(customer); + + // UUID와 생성 시간은 주어지지 않으면 자동으로 들어감 + Assertions.assertThat(saved.getId()).isNotNull(); + Assertions.assertThat(saved.getCreatedAt()).isNotNull(); + // 생성된 사용자 반환 + Assertions.assertThat(saved.getId()).isEqualTo(customer.getId()); + } + + @Test + @DisplayName("동일한 이메일을 가진 유저는 생성할 수 없다.") + void 사용자_생성_실패() { + // 사용자 생성 + String name = "customer"; + String email = "customer@gmail.com"; + Customer customer = new Customer(name, email); + customerRepository.insert(customer); + + // 이미 존재하는 이메일과 함께 생성 시도 + String name2 = "customer2"; + String sameEmail = "customer@gmail.com"; + Customer customer2 = new Customer(name2, sameEmail); + + // 에러 발생 + assertThrows(DuplicateKeyException.class, + () -> customerRepository.insert(customer2)); + } + + @Test + void 전체_사용자_목록_조회_성공() { + // 사용자 생성 + Customer customer = new Customer("customer", "customer@gmail.com"); + Customer customer2 = new Customer("customer2", "customer2@gmail.com"); + customerRepository.insert(customer); + customerRepository.insert(customer2); + + // 전체 사용자 목록 조회 + List customers = customerRepository.findAll(); + + // 저장된 2명의 사용자가 조회 + assertThat(customers).hasSize(2); + } + + @Test + void 사용자_아이디로_조회_성공() { + // 사용자 생성 + String name = "customer"; + String email = "customer@gmail.com"; + Customer customer = new Customer(name, email); + customerRepository.insert(customer); + + // 사용자 아이디로 조회 + Customer found = customerRepository.findById(customer.getId()).get(); + + // 저장한 사용자와 동일한 사용자 반환 + Assertions.assertThat(found.getId()).isEqualTo(customer.getId()); + } +} \ No newline at end of file From 819ce0d8fee77d192e06ffb6a280eeb80cf275f9 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 22:23:40 +0900 Subject: [PATCH 072/134] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EB=B0=94?= =?UTF-8?q?=EC=9A=B0=EC=B2=98=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(SEARCH=20=EC=BB=A4=EB=A7=A8=EB=93=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VoucherController.java | 4 ++++ .../model/voucher/FixedAmountVoucher.java | 6 +++++- .../model/voucher/PercentDiscountVoucher.java | 6 +++++- .../vouchermanagementsystem/service/VoucherService.java | 4 ++++ .../marco/vouchermanagementsystem/view/CommandType.java | 2 +- .../view/ConsoleVoucherApplication.java | 9 +++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java index cfa8f1c9a9..34417cde67 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java @@ -22,6 +22,10 @@ public void createPercentDiscountVoucher(int percent) { voucherService.createPercentDiscountVoucher(percent); } + public String getVoucherInfo(String voucherId) { + return voucherService.getVoucher(UUID.fromString(voucherId)).toString(); + } + public List getVouchersInfo() { return voucherService.getVouchers().stream() .map(Object::toString) diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java index dad36edcc8..3ea6993b54 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java @@ -66,6 +66,10 @@ public int getAmount() { @Override public String toString() { - return MessageFormat.format("{0}원 할인 쿠폰 {1}", amount, getOwnerId() == null ? "" : "/ 쿠폰 소지자: " + getOwnerId()); + return MessageFormat.format(""" + 쿠폰명: {0}원 할인 쿠폰 + 쿠폰번호: {1} + 쿠폰 소지자: {2} + """, amount, getId().toString(), getOwnerId() == null ? "없음" : getOwnerId().toString()); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java index d3d7694b51..9ad11f899a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java @@ -66,6 +66,10 @@ public int getPercent() { @Override public String toString() { - return MessageFormat.format("{0}% 할인 쿠폰 {1}", percent, getOwnerId() == null ? "" : "/ 쿠폰 소지자: " + getOwnerId()); + return MessageFormat.format(""" + 쿠폰명: {0}% 할인 쿠폰 + 쿠폰번호: {1} + 쿠폰 소지자: {2} + """, percent, getId().toString(), getOwnerId() == null ? "없음" : getOwnerId().toString()); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index b7d51f8b42..2d6e540a0c 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -47,4 +47,8 @@ public void assignVoucherOwner(UUID voucherId, UUID customerId) { voucherRepository.update(voucher); } + + public Voucher getVoucher(UUID voucherId) { + return voucherRepository.findById(voucherId).orElseThrow(); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java index 2a59a67537..4ed95b2eb9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java @@ -3,7 +3,7 @@ import static java.text.MessageFormat.format; public enum CommandType { - CREATE, LIST, BLACKLIST, EXIT; + CREATE, LIST, SEARCH, BLACKLIST, EXIT; public static CommandType getCommandType(String input) { try { diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java index a2a381ce0f..74a71922ec 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java @@ -39,6 +39,7 @@ public void selectCommand() { === 쿠폰 관리 프로그램 === create: 쿠폰 생성 list: 쿠폰 목록 조회 + search: 쿠폰 검색 blacklist: 블랙 리스트 유저 조회 exit: 프로그램 종료"""); @@ -48,11 +49,19 @@ public void selectCommand() { switch (commandType) { case CREATE -> createVoucher(); case LIST -> getVoucherList(); + case SEARCH -> getVoucherInfo(); case BLACKLIST -> getBlacklist(); case EXIT -> isRunning = false; } } + private void getVoucherInfo() { + Console.print("쿠폰 번호를 입력해 주세요."); + String voucherId = Console.readString(); + + Console.print(voucherController.getVoucherInfo(voucherId)); + } + private void createVoucher() { logger.info("Call createVoucher()"); From 9213a0e691ba91fd2444be83c94936e926d52c02 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 23:04:48 +0900 Subject: [PATCH 073/134] =?UTF-8?q?feat:=20wallet=20Application=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CustomerController.java | 37 ++++++++ .../controller/UserController.java | 23 ----- .../service/CustomerService.java | 20 ++++ .../view/CommandType.java | 2 +- .../view/ConsoleVoucherApplication.java | 15 ++- .../view/ConsoleWalletApplication.java | 95 +++++++++++++++++++ 6 files changed, 165 insertions(+), 27 deletions(-) create mode 100644 src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java create mode 100644 src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java new file mode 100644 index 0000000000..19f3db498d --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java @@ -0,0 +1,37 @@ +package team.marco.vouchermanagementsystem.controller; + +import org.springframework.stereotype.Controller; +import team.marco.vouchermanagementsystem.service.BlacklistService; +import team.marco.vouchermanagementsystem.service.CustomerService; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; + +import static java.text.MessageFormat.format; + +@Controller +public class CustomerController { + private final CustomerService customerService; + private final BlacklistService blacklistService; + + public CustomerController(CustomerService customerService, BlacklistService blacklistService) { + this.customerService = customerService; + this.blacklistService = blacklistService; + } + + public List getBlacklistInfo() { + return blacklistService.getBlacklist().stream() + .map(dto -> format("id: {0}, 고객명: {1} ", dto.getId() , dto.getName())) + .toList(); + } + + public boolean isExistCustomer(String customerId) { + try { + customerService.findCustomer(UUID.fromString(customerId)); + return true; + } catch (NoSuchElementException e) { + return false; + } + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java deleted file mode 100644 index cc59dfcc42..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/UserController.java +++ /dev/null @@ -1,23 +0,0 @@ -package team.marco.vouchermanagementsystem.controller; - -import org.springframework.stereotype.Controller; -import team.marco.vouchermanagementsystem.service.BlacklistService; - -import java.util.List; - -import static java.text.MessageFormat.format; - -@Controller -public class UserController { - private final BlacklistService blacklistService; - - public UserController(BlacklistService blacklistService) { - this.blacklistService = blacklistService; - } - - public List getBlacklistInfo() { - return blacklistService.getBlacklist().stream() - .map(dto -> format("id: {0}, 고객명: {1} ", dto.getId() , dto.getName())) - .toList(); - } -} diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java b/src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java new file mode 100644 index 0000000000..5fba7b4b6e --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java @@ -0,0 +1,20 @@ +package team.marco.vouchermanagementsystem.service; + +import org.springframework.stereotype.Service; +import team.marco.vouchermanagementsystem.model.Customer; +import team.marco.vouchermanagementsystem.repository.custromer.CustomerRepository; + +import java.util.UUID; + +@Service +public class CustomerService { + private final CustomerRepository customerRepository; + + public CustomerService(CustomerRepository customerRepository) { + this.customerRepository = customerRepository; + } + + public Customer findCustomer(UUID customerId) { + return customerRepository.findById(customerId).orElseThrow(); + } +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java index 4ed95b2eb9..7598fc8592 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java @@ -3,7 +3,7 @@ import static java.text.MessageFormat.format; public enum CommandType { - CREATE, LIST, SEARCH, BLACKLIST, EXIT; + CREATE, LIST, SEARCH, BLACKLIST, WALLET, EXIT, REGISTER, REMOVE, BACK; public static CommandType getCommandType(String input) { try { diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java index 74a71922ec..8d098e5a07 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java @@ -3,7 +3,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.vouchermanagementsystem.controller.UserController; +import team.marco.vouchermanagementsystem.controller.CustomerController; import team.marco.vouchermanagementsystem.controller.VoucherController; import team.marco.vouchermanagementsystem.view.util.Console; @@ -13,12 +13,15 @@ public class ConsoleVoucherApplication { private static final Logger logger = LoggerFactory.getLogger(ConsoleVoucherApplication.class); + private final ConsoleWalletApplication walletApplication; private final VoucherController voucherController; - private final UserController userController; + private final CustomerController userController; + private Boolean isRunning; - public ConsoleVoucherApplication(VoucherController voucherController, UserController userController) { + public ConsoleVoucherApplication(ConsoleWalletApplication walletApplication, VoucherController voucherController, CustomerController userController) { + this.walletApplication = walletApplication; this.voucherController = voucherController; this.userController = userController; this.isRunning = true; @@ -41,6 +44,7 @@ public void selectCommand() { list: 쿠폰 목록 조회 search: 쿠폰 검색 blacklist: 블랙 리스트 유저 조회 + wallet: 지갑 서비스로 이동 exit: 프로그램 종료"""); String input = Console.readString(); @@ -51,10 +55,15 @@ public void selectCommand() { case LIST -> getVoucherList(); case SEARCH -> getVoucherInfo(); case BLACKLIST -> getBlacklist(); + case WALLET -> runWalletApplication(); case EXIT -> isRunning = false; } } + private void runWalletApplication() { + walletApplication.run(); + } + private void getVoucherInfo() { Console.print("쿠폰 번호를 입력해 주세요."); String voucherId = Console.readString(); diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java new file mode 100644 index 0000000000..af1f2951d0 --- /dev/null +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java @@ -0,0 +1,95 @@ +package team.marco.vouchermanagementsystem.view; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import team.marco.vouchermanagementsystem.controller.CustomerController; +import team.marco.vouchermanagementsystem.controller.VoucherController; +import team.marco.vouchermanagementsystem.view.util.Console; + +@Component +public class ConsoleWalletApplication { + private static final Logger logger = LoggerFactory.getLogger(ConsoleWalletApplication.class); + + private final VoucherController voucherController; + private final CustomerController customerController; + + private Boolean isRunning; + + public ConsoleWalletApplication(VoucherController voucherController, CustomerController customerController) { + this.voucherController = voucherController; + this.customerController = customerController; + this.isRunning = true; + } + + public void run() { + Console.print("지갑 서비스를 이용하기 위해 사용자의 아이디를 입력해주세요."); + String customerId = Console.readString(); + + if(!customerController.isExistCustomer(customerId)) { + throw new IllegalArgumentException("올바른 사용자 아이디가 아닙니다."); + } + + while (isRunning) { + try { + selectCommand(customerId); + } catch (Exception e) { + handleException(e); + } + } + } + + private void selectCommand(String customerId) { + Console.print(""" + === 지갑 관리 프로그램 === + register: 쿠폰 등록 + list: 나의 쿠폰 목록 조회 + remove: 쿠폰 삭제 + back: 쿠폰 관리 페이지로 돌아가기"""); + + String input = Console.readString(); + + CommandType commandType = CommandType.getCommandType(input); + switch (commandType) { + case REGISTER -> registerVoucher(customerId); + case LIST -> getMyVouchers(customerId); + case REMOVE -> removeVoucher(customerId); + case BACK -> backToMainApplication(); + } + } + + private void registerVoucher(String customerId) { + + } + + private void getMyVouchers(String customerId) { + + } + + private void removeVoucher(String customerId) { + + } + + private void backToMainApplication() { + isRunning = false; + } + + private void handleException(Exception e) { + if(e instanceof NumberFormatException) { + Console.print("숫자를 입력해 주세요."); + return; + } + + if(e instanceof IllegalArgumentException) { + Console.print(e.getMessage()); + return; + } + + logger.error(e.toString()); + + Console.print(e.getMessage()); + + isRunning = false; + } + +} From 36f34c40daea80f22af25c7db9c5b6afe5b629da Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 23:32:06 +0900 Subject: [PATCH 074/134] =?UTF-8?q?feat:=20=EC=A7=80=EA=B0=91=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VoucherController.java | 14 ++++++++++++-- .../service/VoucherService.java | 8 ++++++++ .../view/ConsoleWalletApplication.java | 10 +++++++++- src/main/resources/schema.sql | 0 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/schema.sql diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java index 34417cde67..2660081e65 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java +++ b/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java @@ -32,7 +32,17 @@ public List getVouchersInfo() { .toList(); } - public void assignVoucherOwner(UUID voucherId, UUID customerId) { - voucherService.assignVoucherOwner(voucherId, customerId); + public List getVouchersInfo(String customerId) { + return voucherService.getVouchers(UUID.fromString(customerId)).stream() + .map(Object::toString) + .toList(); + } + + public void assignVoucherOwner(String voucherId, String customerId) { + voucherService.assignVoucherOwner(UUID.fromString(voucherId), UUID.fromString(customerId)); + } + + public void deleteVoucher(String voucherId) { + voucherService.deleteVoucher(UUID.fromString(voucherId)); } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java index 2d6e540a0c..f3928117aa 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java @@ -38,6 +38,10 @@ public List getVouchers() { return voucherRepository.findAll(); } + public List getVouchers(UUID customerId) { + return voucherRepository.findByOwner(customerId); + } + @Transactional public void assignVoucherOwner(UUID voucherId, UUID customerId) { logger.debug("[VoucherService] Call assignVoucherOwner()"); @@ -51,4 +55,8 @@ public void assignVoucherOwner(UUID voucherId, UUID customerId) { public Voucher getVoucher(UUID voucherId) { return voucherRepository.findById(voucherId).orElseThrow(); } + + public void deleteVoucher(UUID voucherId) { + voucherRepository.deleteById(voucherId); + } } diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java index af1f2951d0..6f56ae3570 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java +++ b/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java @@ -59,15 +59,23 @@ private void selectCommand(String customerId) { } private void registerVoucher(String customerId) { + Console.print("등록하실 쿠폰 번호를 입력해주세요."); + String voucherId = Console.readString(); + voucherController.assignVoucherOwner(voucherId, customerId); + Console.print("쿠폰 등록이 완료되었습니다."); } private void getMyVouchers(String customerId) { - + Console.printStringList(voucherController.getVouchersInfo(customerId)); } private void removeVoucher(String customerId) { + Console.print("제거할 쿠폰 번호를 입력해주세요."); + String voucherId = Console.readString(); + voucherController.deleteVoucher(voucherId); + Console.print("쿠폰 삭제가 완료되었습니다."); } private void backToMainApplication() { diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql new file mode 100644 index 0000000000..e69de29bb2 From f3b1d2a38d0879033de0a2f89bb67da8bf572673 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 27 Oct 2023 23:32:43 +0900 Subject: [PATCH 075/134] =?UTF-8?q?docs:=20voucher=5Fmgmt=5Fsystem=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B2=A0=EC=9D=B4=EC=8A=A4=20ddl?= =?UTF-8?q?=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/schema.sql | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index e69de29bb2..fcd513b721 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -0,0 +1,34 @@ +USE voucher_mgmt_system; + +SHOW tables; + +DROP TABLE vouchers; +DROP TABLE customers; + +CREATE TABLE `customers` ( + `customer_id` binary(16) NOT NULL, + `name` varchar(20) NOT NULL, + `email` varchar(50) NOT NULL, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`customer_id`), + UNIQUE KEY `unq_user_email` (`email`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test00', 'test00@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test01', 'test01@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test02', 'test02@gmail.com'); + +CREATE TABLE `vouchers` ( + `voucher_id` binary(16) NOT NULL, + `voucher_type` enum('FIXED','PERCENT') DEFAULT NULL, + `amount` int DEFAULT NULL, + `percent` int DEFAULT NULL, + `owner_id` binary(16) DEFAULT NULL, + PRIMARY KEY (`voucher_id`), + KEY `fk_owner_id` (`owner_id`), + CONSTRAINT `fk_owner_id` FOREIGN KEY (`owner_id`) REFERENCES `customers` (`customer_id`), + CONSTRAINT `chk_amount` CHECK (((`amount` >= 100) and (`amount` <= 1000000))), + CONSTRAINT `chk_percent` CHECK (((`percent` > 0) and (`percent` <= 50))) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + + From cc06b8b16ebc9dacee02c21c4096132ac2e93794 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 13:14:03 +0900 Subject: [PATCH 076/134] =?UTF-8?q?docs:=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20?= =?UTF-8?q?=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EC=97=B0=EA=B2=B0=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=8C=8C=EC=9D=BC(application.yml,=20schema.sql)?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 4 +-- src/main/resources/schema.sql | 50 +++++++++++++++++------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fe5e93e3ce..f6878a3bca 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,9 +5,9 @@ application: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 username: root - password: wtwt + password: uijin-mysql-pw file: path: diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index fcd513b721..fc2daee0c3 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,34 +1,40 @@ +SHOW DATABASES; + +# voucher_mgmt_system 데이터 베이스가 없다면 실행 +CREATE DATABASE voucher_mgmt_system; + USE voucher_mgmt_system; SHOW tables; +# vouchers, customers 테이블이 존재한다면 실행 DROP TABLE vouchers; DROP TABLE customers; -CREATE TABLE `customers` ( - `customer_id` binary(16) NOT NULL, - `name` varchar(20) NOT NULL, - `email` varchar(50) NOT NULL, - `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`customer_id`), - UNIQUE KEY `unq_user_email` (`email`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; +CREATE TABLE customers ( + customer_id BINARY(16) NOT NULL, + name VARCHAR(20) NOT NULL, + email VARCHAR(50) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT pk_customer_id PRIMARY KEY (customer_id), + CONSTRAINT unq_customer_email UNIQUE KEY (email) +); -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test00', 'test00@gmail.com'); -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test01', 'test01@gmail.com'); -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), 'test02', 'test02@gmail.com'); +# 테스트 데이터 삽입 +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '정의진', '정의진@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '김현우', '김현우@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '이세희', '이세희@gmail.com'); CREATE TABLE `vouchers` ( - `voucher_id` binary(16) NOT NULL, - `voucher_type` enum('FIXED','PERCENT') DEFAULT NULL, - `amount` int DEFAULT NULL, - `percent` int DEFAULT NULL, - `owner_id` binary(16) DEFAULT NULL, - PRIMARY KEY (`voucher_id`), - KEY `fk_owner_id` (`owner_id`), - CONSTRAINT `fk_owner_id` FOREIGN KEY (`owner_id`) REFERENCES `customers` (`customer_id`), - CONSTRAINT `chk_amount` CHECK (((`amount` >= 100) and (`amount` <= 1000000))), - CONSTRAINT `chk_percent` CHECK (((`percent` > 0) and (`percent` <= 50))) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; + voucher_id BINARY(16) NOT NULL, + voucher_type ENUM('FIXED','PERCENT') DEFAULT NULL, + amount INTEGER DEFAULT NULL, + percent INTEGER DEFAULT NULL, + owner_id BINARY(16) DEFAULT NULL, + CONSTRAINT pk_voucher_id PRIMARY KEY (voucher_id), + CONSTRAINT `fk_owner_id` FOREIGN KEY (owner_id) REFERENCES customers (customer_id), + CONSTRAINT `chk_amount` CHECK (((amount >= 100) and (amount <= 1000000))), + CONSTRAINT `chk_percent` CHECK (((percent > 0) and (percent <= 50))) +); From 0b64103bd7d1cc70e63fc3580b3ef7e4a6e96f15 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 15:44:03 +0900 Subject: [PATCH 077/134] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=EB=AA=85=20vouchermanagementsysten=20->=20voucher=5Fm?= =?UTF-8?q?anagement=5Fsystem=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HELP.md | 2 +- .../VoucherManagementSystemApplication.java | 4 ++-- .../configuration/JdbcTemplateConfig.java | 2 +- .../controller/CustomerController.java | 6 +++--- .../controller/VoucherController.java | 4 ++-- .../model/Customer.java | 2 +- .../model/voucher/FixedAmountVoucher.java | 4 ++-- .../model/voucher/PercentDiscountVoucher.java | 4 ++-- .../model/voucher/Voucher.java | 2 +- .../model/voucher/VoucherType.java | 5 +++++ .../repository/custromer/BlacklistRepository.java | 2 +- .../custromer/CsvBlacklistRepository.java | 2 +- .../repository/custromer/CustomerIdAndName.java | 2 +- .../repository/custromer/CustomerRepository.java | 4 ++-- .../custromer/JdbcCustomerRepository.java | 6 +++--- .../repository/voucher/JdbcVoucherRepository.java | 14 +++++++------- .../voucher/JsonFileVoucherRepository.java | 4 ++-- .../repository/voucher/LoadedJsonVoucher.java | 10 +++++----- .../voucher/MemoryVoucherRepository.java | 4 ++-- .../repository/voucher/VoucherRepository.java | 4 ++-- .../service/BlacklistService.java | 6 +++--- .../service/CustomerService.java | 6 +++--- .../service/VoucherService.java | 10 +++++----- .../util/UUIDUtil.java | 2 +- .../view/CommandType.java | 2 +- .../view/ConsoleVoucherApplication.java | 8 ++++---- .../view/ConsoleWalletApplication.java | 8 ++++---- .../view/util/Console.java | 2 +- .../model/voucher/VoucherType.java | 5 ----- src/main/resources/logback.xml | 2 +- .../VoucherManagementSystemApplicationTests.java | 2 +- .../model/voucher/FixedAmountVoucherTest.java | 2 +- .../model/voucher/PercentDiscountVoucherTest.java | 2 +- .../custromer/JdbcCustomerRepositoryTest.java | 4 ++-- .../voucher/JdbcVoucherRepositoryTest.java | 12 ++++++------ .../voucher/MemoryVoucherRepositoryTest.java | 8 ++++---- 36 files changed, 84 insertions(+), 84 deletions(-) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/VoucherManagementSystemApplication.java (87%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/configuration/JdbcTemplateConfig.java (96%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/controller/CustomerController.java (83%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/controller/VoucherController.java (91%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/Customer.java (94%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/voucher/FixedAmountVoucher.java (93%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/voucher/PercentDiscountVoucher.java (93%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/voucher/Voucher.java (90%) create mode 100644 src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/BlacklistRepository.java (61%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/CsvBlacklistRepository.java (95%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/CustomerIdAndName.java (83%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/CustomerRepository.java (65%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/JdbcCustomerRepository.java (93%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/JdbcVoucherRepository.java (91%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/JsonFileVoucherRepository.java (95%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/LoadedJsonVoucher.java (79%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/MemoryVoucherRepository.java (91%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/VoucherRepository.java (72%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/service/BlacklistService.java (64%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/service/CustomerService.java (68%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/service/VoucherService.java (82%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/util/UUIDUtil.java (88%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/view/CommandType.java (89%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/view/ConsoleVoucherApplication.java (94%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/view/ConsoleWalletApplication.java (92%) rename src/main/java/team/marco/{vouchermanagementsystem => voucher_management_system}/view/util/Console.java (96%) delete mode 100644 src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/VoucherManagementSystemApplicationTests.java (81%) rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/voucher/FixedAmountVoucherTest.java (98%) rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/model/voucher/PercentDiscountVoucherTest.java (98%) rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/custromer/JdbcCustomerRepositoryTest.java (96%) rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/JdbcVoucherRepositoryTest.java (90%) rename src/test/java/team/marco/{vouchermanagementsystem => voucher_management_system}/repository/voucher/MemoryVoucherRepositoryTest.java (82%) diff --git a/HELP.md b/HELP.md index aca5665217..3d6d37a6eb 100644 --- a/HELP.md +++ b/HELP.md @@ -2,7 +2,7 @@ The following was discovered as part of building this project: * The JVM level was changed from '16' to '17', review the [JDK Version Range](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions#jdk-version-range) on the wiki for more details. -* The original package name 'team.marco.voucher-management-system' is invalid and this project uses 'team.marco.vouchermanagementsystem' instead. +* The original package name 'team.marco.voucher-management-system' is invalid and this project uses 'team.marco.voucher_management_system' instead. # Getting Started diff --git a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java similarity index 87% rename from src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java rename to src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java index 7dc0557169..a1b614ba5f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java @@ -1,11 +1,11 @@ -package team.marco.vouchermanagementsystem; +package team.marco.voucher_management_system; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import team.marco.vouchermanagementsystem.view.ConsoleVoucherApplication; +import team.marco.voucher_management_system.view.ConsoleVoucherApplication; @SpringBootApplication public class VoucherManagementSystemApplication { diff --git a/src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java b/src/main/java/team/marco/voucher_management_system/configuration/JdbcTemplateConfig.java similarity index 96% rename from src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java rename to src/main/java/team/marco/voucher_management_system/configuration/JdbcTemplateConfig.java index 8d2fc379b2..4a876a0f8a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/configuration/JdbcTemplateConfig.java +++ b/src/main/java/team/marco/voucher_management_system/configuration/JdbcTemplateConfig.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.configuration; +package team.marco.voucher_management_system.configuration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java b/src/main/java/team/marco/voucher_management_system/controller/CustomerController.java similarity index 83% rename from src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java rename to src/main/java/team/marco/voucher_management_system/controller/CustomerController.java index 19f3db498d..4be846f81f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/CustomerController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/CustomerController.java @@ -1,8 +1,8 @@ -package team.marco.vouchermanagementsystem.controller; +package team.marco.voucher_management_system.controller; import org.springframework.stereotype.Controller; -import team.marco.vouchermanagementsystem.service.BlacklistService; -import team.marco.vouchermanagementsystem.service.CustomerService; +import team.marco.voucher_management_system.service.BlacklistService; +import team.marco.voucher_management_system.service.CustomerService; import java.util.List; import java.util.NoSuchElementException; diff --git a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java b/src/main/java/team/marco/voucher_management_system/controller/VoucherController.java similarity index 91% rename from src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java rename to src/main/java/team/marco/voucher_management_system/controller/VoucherController.java index 2660081e65..1852db67b6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/controller/VoucherController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/VoucherController.java @@ -1,7 +1,7 @@ -package team.marco.vouchermanagementsystem.controller; +package team.marco.voucher_management_system.controller; import org.springframework.stereotype.Controller; -import team.marco.vouchermanagementsystem.service.VoucherService; +import team.marco.voucher_management_system.service.VoucherService; import java.util.List; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java b/src/main/java/team/marco/voucher_management_system/model/Customer.java similarity index 94% rename from src/main/java/team/marco/vouchermanagementsystem/model/Customer.java rename to src/main/java/team/marco/voucher_management_system/model/Customer.java index 98c8717fde..9b0aea101c 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/Customer.java +++ b/src/main/java/team/marco/voucher_management_system/model/Customer.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model; +package team.marco.voucher_management_system.model; import java.time.LocalDateTime; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java similarity index 93% rename from src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java rename to src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java index 3ea6993b54..3890484f72 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model.voucher; +package team.marco.voucher_management_system.model.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.model.voucher.VoucherType.FIXED; public class FixedAmountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java similarity index 93% rename from src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java rename to src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java index 9ad11f899a..1d75c4fd6f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model.voucher; +package team.marco.voucher_management_system.model.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.vouchermanagementsystem.model.voucher.VoucherType.PERCENT; +import static team.marco.voucher_management_system.model.voucher.VoucherType.PERCENT; public class PercentDiscountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java b/src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java similarity index 90% rename from src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java rename to src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java index 99a4918623..bd49898c94 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/Voucher.java +++ b/src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model.voucher; +package team.marco.voucher_management_system.model.voucher; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java b/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java new file mode 100644 index 0000000000..4bd0606f13 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java @@ -0,0 +1,5 @@ +package team.marco.voucher_management_system.model.voucher; + +public enum VoucherType { + FIXED, PERCENT +} diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java similarity index 61% rename from src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java index c59895fc1b..015b2cb118 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/BlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java similarity index 95% rename from src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java index 02cc97cbd2..d1017ef5d9 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java similarity index 83% rename from src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java rename to src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java index 54eeab3240..bde195f70d 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerIdAndName.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java similarity index 65% rename from src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java index 07060b6008..d14e0f0095 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/CustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java @@ -1,6 +1,6 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; -import team.marco.vouchermanagementsystem.model.Customer; +import team.marco.voucher_management_system.model.Customer; import java.util.List; import java.util.Optional; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java similarity index 93% rename from src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index f94984db67..fa0067aa45 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -1,11 +1,11 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.Customer; +import team.marco.voucher_management_system.model.Customer; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +13,7 @@ import java.time.LocalDateTime; import java.util.*; -import static team.marco.vouchermanagementsystem.util.UUIDUtil.bytesToUUID; +import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; @Repository public class JdbcCustomerRepository implements CustomerRepository { diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java similarity index 91% rename from src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index 8466884ae5..a36ac69f48 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -1,21 +1,21 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import team.marco.vouchermanagementsystem.model.voucher.VoucherType; -import team.marco.vouchermanagementsystem.repository.custromer.CustomerRepository; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.VoucherType; +import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; -import static team.marco.vouchermanagementsystem.util.UUIDUtil.bytesToUUID; +import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; @Profile("prod") @Repository diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java similarity index 95% rename from src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java index 133277245e..b1fd98ead5 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; @@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.Voucher; import java.io.File; import java.io.IOException; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java similarity index 79% rename from src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java rename to src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java index ed60531a6d..8ece8e39e6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/LoadedJsonVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java @@ -1,9 +1,9 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; -import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import team.marco.vouchermanagementsystem.model.voucher.VoucherType; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.VoucherType; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java similarity index 91% rename from src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java index 9db9b32f90..a383dec485 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java @@ -1,8 +1,8 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.Voucher; import java.util.List; import java.util.Map; diff --git a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java similarity index 72% rename from src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java rename to src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java index 3a375d618f..2dcd10dba2 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java @@ -1,6 +1,6 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.Voucher; import java.util.List; import java.util.Optional; diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java b/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java similarity index 64% rename from src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java rename to src/main/java/team/marco/voucher_management_system/service/BlacklistService.java index 352fcae239..8dce71fda8 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/BlacklistService.java +++ b/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java @@ -1,8 +1,8 @@ -package team.marco.vouchermanagementsystem.service; +package team.marco.voucher_management_system.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.repository.custromer.CsvBlacklistRepository; -import team.marco.vouchermanagementsystem.repository.custromer.CustomerIdAndName; +import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; +import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; import java.util.List; diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java b/src/main/java/team/marco/voucher_management_system/service/CustomerService.java similarity index 68% rename from src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java rename to src/main/java/team/marco/voucher_management_system/service/CustomerService.java index 5fba7b4b6e..29538169cc 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/CustomerService.java +++ b/src/main/java/team/marco/voucher_management_system/service/CustomerService.java @@ -1,8 +1,8 @@ -package team.marco.vouchermanagementsystem.service; +package team.marco.voucher_management_system.service; import org.springframework.stereotype.Service; -import team.marco.vouchermanagementsystem.model.Customer; -import team.marco.vouchermanagementsystem.repository.custromer.CustomerRepository; +import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/VoucherService.java similarity index 82% rename from src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java rename to src/main/java/team/marco/voucher_management_system/service/VoucherService.java index f3928117aa..313691023f 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/service/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/VoucherService.java @@ -1,13 +1,13 @@ -package team.marco.vouchermanagementsystem.service; +package team.marco.voucher_management_system.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import team.marco.vouchermanagementsystem.repository.voucher.VoucherRepository; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import java.util.List; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java b/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java similarity index 88% rename from src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java rename to src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java index 1c1d9e8dd2..5cbaa7a6d6 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/util/UUIDUtil.java +++ b/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.util; +package team.marco.voucher_management_system.util; import java.nio.ByteBuffer; import java.util.UUID; diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java b/src/main/java/team/marco/voucher_management_system/view/CommandType.java similarity index 89% rename from src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java rename to src/main/java/team/marco/voucher_management_system/view/CommandType.java index 7598fc8592..72e8913e46 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/CommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/CommandType.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.view; +package team.marco.voucher_management_system.view; import static java.text.MessageFormat.format; diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java similarity index 94% rename from src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java rename to src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java index 8d098e5a07..03d71e9c2a 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java @@ -1,11 +1,11 @@ -package team.marco.vouchermanagementsystem.view; +package team.marco.voucher_management_system.view; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.vouchermanagementsystem.controller.CustomerController; -import team.marco.vouchermanagementsystem.controller.VoucherController; -import team.marco.vouchermanagementsystem.view.util.Console; +import team.marco.voucher_management_system.controller.CustomerController; +import team.marco.voucher_management_system.controller.VoucherController; +import team.marco.voucher_management_system.view.util.Console; import java.io.UncheckedIOException; diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java similarity index 92% rename from src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java rename to src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java index 6f56ae3570..b8a0b0babc 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/ConsoleWalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java @@ -1,11 +1,11 @@ -package team.marco.vouchermanagementsystem.view; +package team.marco.voucher_management_system.view; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.vouchermanagementsystem.controller.CustomerController; -import team.marco.vouchermanagementsystem.controller.VoucherController; -import team.marco.vouchermanagementsystem.view.util.Console; +import team.marco.voucher_management_system.controller.CustomerController; +import team.marco.voucher_management_system.controller.VoucherController; +import team.marco.voucher_management_system.view.util.Console; @Component public class ConsoleWalletApplication { diff --git a/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java b/src/main/java/team/marco/voucher_management_system/view/util/Console.java similarity index 96% rename from src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java rename to src/main/java/team/marco/voucher_management_system/view/util/Console.java index c46127b345..683e7f6dee 100644 --- a/src/main/java/team/marco/vouchermanagementsystem/view/util/Console.java +++ b/src/main/java/team/marco/voucher_management_system/view/util/Console.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.view.util; +package team.marco.voucher_management_system.view.util; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java b/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java deleted file mode 100644 index 110623b418..0000000000 --- a/src/main/java/team/marco/vouchermanagementsystem/model/voucher/VoucherType.java +++ /dev/null @@ -1,5 +0,0 @@ -package team.marco.vouchermanagementsystem.model.voucher; - -public enum VoucherType { - FIXED, PERCENT -} diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 84f72f7156..a26815d110 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,6 +1,6 @@ - + diff --git a/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java b/src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java similarity index 81% rename from src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java rename to src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java index 22e09505f3..c6e753083f 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/VoucherManagementSystemApplicationTests.java +++ b/src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem; +package team.marco.voucher_management_system; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java similarity index 98% rename from src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java rename to src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java index bee33d3607..bd590b4130 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/FixedAmountVoucherTest.java +++ b/src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model.voucher; +package team.marco.voucher_management_system.model.voucher; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java similarity index 98% rename from src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java rename to src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java index 9214785f0f..817df745a5 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/model/voucher/PercentDiscountVoucherTest.java +++ b/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.model.voucher; +package team.marco.voucher_management_system.model.voucher; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java similarity index 96% rename from src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java rename to src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index 461137cce8..3c00637a95 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.custromer; +package team.marco.voucher_management_system.repository.custromer; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -10,7 +10,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import team.marco.vouchermanagementsystem.model.Customer; +import team.marco.voucher_management_system.model.Customer; import java.util.List; diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java similarity index 90% rename from src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java rename to src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 120791bccf..091dd8a827 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -1,4 +1,4 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -9,11 +9,11 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import team.marco.vouchermanagementsystem.model.Customer; -import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; -import team.marco.vouchermanagementsystem.repository.custromer.JdbcCustomerRepository; +import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.repository.custromer.JdbcCustomerRepository; import java.util.List; diff --git a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java similarity index 82% rename from src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java rename to src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java index a98c08af0d..c14f97f88c 100644 --- a/src/test/java/team/marco/vouchermanagementsystem/repository/voucher/MemoryVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java @@ -1,12 +1,12 @@ -package team.marco.vouchermanagementsystem.repository.voucher; +package team.marco.voucher_management_system.repository.voucher; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.vouchermanagementsystem.model.voucher.FixedAmountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.PercentDiscountVoucher; -import team.marco.vouchermanagementsystem.model.voucher.Voucher; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; import java.util.List; From 93d35e691f3c98049fb2ade46972e2ab8312759d Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 18:10:35 +0900 Subject: [PATCH 078/134] =?UTF-8?q?refactor:=20ConsolevoucherApplication?= =?UTF-8?q?=EC=9D=84=20ManagementApplication=EA=B3=BC=20WalletApplication?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherManagementSystemApplication.java | 4 +- .../view/CommandType.java | 15 ---- .../Console.java => console/ConsoleUtil.java} | 21 +++-- .../view/console/ServiceType.java | 32 +++++++ .../view/console/VoucherApplication.java | 90 +++++++++++++++++++ .../management/ManagementApplication.java} | 85 +++++++++--------- .../management/ManagementCommandType.java | 35 ++++++++ .../wallet/WalletApplication.java} | 56 ++++++------ .../console/wallet/WalletCommandType.java | 33 +++++++ 9 files changed, 277 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/team/marco/voucher_management_system/view/CommandType.java rename src/main/java/team/marco/voucher_management_system/view/{util/Console.java => console/ConsoleUtil.java} (72%) create mode 100644 src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java create mode 100644 src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java rename src/main/java/team/marco/voucher_management_system/view/{ConsoleVoucherApplication.java => console/management/ManagementApplication.java} (54%) create mode 100644 src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java rename src/main/java/team/marco/voucher_management_system/view/{ConsoleWalletApplication.java => console/wallet/WalletApplication.java} (54%) create mode 100644 src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java diff --git a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java index a1b614ba5f..229fba48c0 100644 --- a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import team.marco.voucher_management_system.view.ConsoleVoucherApplication; +import team.marco.voucher_management_system.view.console.VoucherApplication; @SpringBootApplication public class VoucherManagementSystemApplication { @@ -16,7 +16,7 @@ public static void main(String[] args) { logger.info("Program start {}", context.getEnvironment().getActiveProfiles()); - ConsoleVoucherApplication application = context.getBean(ConsoleVoucherApplication.class); + VoucherApplication application = context.getBean(VoucherApplication.class); application.run(); logger.info("Program exit"); diff --git a/src/main/java/team/marco/voucher_management_system/view/CommandType.java b/src/main/java/team/marco/voucher_management_system/view/CommandType.java deleted file mode 100644 index 72e8913e46..0000000000 --- a/src/main/java/team/marco/voucher_management_system/view/CommandType.java +++ /dev/null @@ -1,15 +0,0 @@ -package team.marco.voucher_management_system.view; - -import static java.text.MessageFormat.format; - -public enum CommandType { - CREATE, LIST, SEARCH, BLACKLIST, WALLET, EXIT, REGISTER, REMOVE, BACK; - - public static CommandType getCommandType(String input) { - try { - return valueOf(input.toUpperCase()); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException(format("{0}: 사용할 수 없는 명령어입니다.", input)); - } - } -} diff --git a/src/main/java/team/marco/voucher_management_system/view/util/Console.java b/src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java similarity index 72% rename from src/main/java/team/marco/voucher_management_system/view/util/Console.java rename to src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java index 683e7f6dee..3e5a09d7f6 100644 --- a/src/main/java/team/marco/voucher_management_system/view/util/Console.java +++ b/src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.view.util; +package team.marco.voucher_management_system.view.console; import java.io.BufferedReader; import java.io.IOException; @@ -7,26 +7,35 @@ import java.util.List; import java.util.Objects; -public final class Console { +public final class ConsoleUtil { private static final String INFO_DELIMINATOR = "\n"; private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - private Console() { + private ConsoleUtil() { // Don't let anyone instantiate this class. } public static void print(Object object) { - System.out.println(object + System.lineSeparator()); // thanks to SH, IJ + System.out.print(object + System.lineSeparator()); + } + + public static void println(Object object) { + print(object); + System.out.println(); + } + + public static void println() { + System.out.println(); } public static void printStringList(List list) { String joinedString = String.join(INFO_DELIMINATOR, list); if (!joinedString.isBlank()) { - Console.print(joinedString); + ConsoleUtil.println(joinedString); } - Console.print("조회가 완료되었습니다."); + ConsoleUtil.println("조회가 완료되었습니다."); } public static String readString() { diff --git a/src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java b/src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java new file mode 100644 index 0000000000..6eef936266 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java @@ -0,0 +1,32 @@ +package team.marco.voucher_management_system.view.console; + +import java.util.Arrays; + +public enum ServiceType { + MANAGEMENT(1, "관리자 서비스"), + WALLET(2, "회원 지갑 서비스"), + EXIT(3, "프로그램 종료"); + + private int num; + private String description; + + ServiceType(int num, String description) { + this.num = num; + this.description = description; + } + + static ServiceType get(int num) { + return Arrays.stream(ServiceType.values()) + .filter(v -> v.getNum() == num) + .findAny() + .orElseThrow(); + } + + public int getNum() { + return num; + } + + public String getInfo() { + return num + ". " + description; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java new file mode 100644 index 0000000000..64050b0734 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java @@ -0,0 +1,90 @@ +package team.marco.voucher_management_system.view.console; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import team.marco.voucher_management_system.view.console.management.ManagementApplication; +import team.marco.voucher_management_system.view.console.wallet.WalletApplication; + +import java.io.UncheckedIOException; + +@Component +public class VoucherApplication { + private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); + + private final WalletApplication walletApplication; + private final ManagementApplication managementApplication; + + private Boolean isRunning; + + public VoucherApplication(WalletApplication walletApplication, ManagementApplication managementApplication) { + this.walletApplication = walletApplication; + this.managementApplication = managementApplication; + this.isRunning = true; + } + + public void run() { + while (isRunning) { + try { + selectService(); + } catch (Exception e) { + handleException(e); + } + } + } + + public void selectService() { + ConsoleUtil.print("=== 메인 페이지 ==="); + + for(ServiceType type : ServiceType.values()) { + ConsoleUtil.print(type.getInfo()); + } + + ConsoleUtil.println(); + + ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요. (숫자)"); + int input = ConsoleUtil.readInt(); + + ServiceType type = ServiceType.get(input); + switch (type) { + case MANAGEMENT -> runManagementApplication(); + case WALLET -> runWalletApplication(); + case EXIT -> close(); + } + } + + private void runWalletApplication() { + walletApplication.run(); + } + private void runManagementApplication() { + managementApplication.run(); + } + + private void close() { + logger.info("Call close()"); + + isRunning = false; + ConsoleUtil.print("프로그램이 종료되었습니다."); + } + + private void handleException(Exception e) { + if(e instanceof NumberFormatException) { + ConsoleUtil.print("숫자를 입력해 주세요."); + return; + } + + if(e instanceof IllegalArgumentException) { + ConsoleUtil.print(e.getMessage()); + return; + } + + logger.error(e.toString()); + + String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; + ConsoleUtil.print(errorMessage); + + isRunning = false; + + close(); + } +} diff --git a/src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java similarity index 54% rename from src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java rename to src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java index 03d71e9c2a..7fe9c4cac9 100644 --- a/src/main/java/team/marco/voucher_management_system/view/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java @@ -1,27 +1,24 @@ -package team.marco.voucher_management_system.view; +package team.marco.voucher_management_system.view.console.management; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.CustomerController; import team.marco.voucher_management_system.controller.VoucherController; -import team.marco.voucher_management_system.view.util.Console; +import team.marco.voucher_management_system.view.console.ConsoleUtil; import java.io.UncheckedIOException; @Component -public class ConsoleVoucherApplication { - private static final Logger logger = LoggerFactory.getLogger(ConsoleVoucherApplication.class); +public class ManagementApplication { + private static final Logger logger = LoggerFactory.getLogger(ManagementApplication.class); - private final ConsoleWalletApplication walletApplication; private final VoucherController voucherController; private final CustomerController userController; - private Boolean isRunning; - public ConsoleVoucherApplication(ConsoleWalletApplication walletApplication, VoucherController voucherController, CustomerController userController) { - this.walletApplication = walletApplication; + public ManagementApplication(VoucherController voucherController, CustomerController userController) { this.voucherController = voucherController; this.userController = userController; this.isRunning = true; @@ -38,47 +35,49 @@ public void run() { } public void selectCommand() { - Console.print(""" - === 쿠폰 관리 프로그램 === - create: 쿠폰 생성 - list: 쿠폰 목록 조회 - search: 쿠폰 검색 - blacklist: 블랙 리스트 유저 조회 - wallet: 지갑 서비스로 이동 - exit: 프로그램 종료"""); - - String input = Console.readString(); - - CommandType commandType = CommandType.getCommandType(input); + ConsoleUtil.print("=== 관리자 페이지 ==="); + + for(ManagementCommandType type : ManagementCommandType.values()) { + ConsoleUtil.print(type.getInfo()); + } + + ConsoleUtil.println(); + + ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); + int input = ConsoleUtil.readInt(); + + ManagementCommandType commandType = ManagementCommandType.get(input); switch (commandType) { - case CREATE -> createVoucher(); - case LIST -> getVoucherList(); - case SEARCH -> getVoucherInfo(); + case CREATE_VOUCHER -> createVoucher(); + case VOUCHER_LIST -> getVoucherList(); + case SEARCH_VOUCHER -> getVoucherInfo(); + case CUSTOMER_LIST -> getCustomerList(); case BLACKLIST -> getBlacklist(); - case WALLET -> runWalletApplication(); - case EXIT -> isRunning = false; + case BACK -> close(); } } - private void runWalletApplication() { - walletApplication.run(); + private void getCustomerList() { + /** + * TODO: getCustomerList() 구현 + */ } private void getVoucherInfo() { - Console.print("쿠폰 번호를 입력해 주세요."); - String voucherId = Console.readString(); + ConsoleUtil.print("쿠폰 번호를 입력해 주세요."); + String voucherId = ConsoleUtil.readString(); - Console.print(voucherController.getVoucherInfo(voucherId)); + ConsoleUtil.print(voucherController.getVoucherInfo(voucherId)); } private void createVoucher() { logger.info("Call createVoucher()"); - Console.print(""" + ConsoleUtil.print(""" 0: 고정 금액 할인 쿠폰 1: % 할인 쿠폰"""); - int selected = Console.readInt(); + int selected = ConsoleUtil.readInt(); switch (selected) { case 0 -> createFixedAmountVoucher(); @@ -90,8 +89,8 @@ private void createVoucher() { private void createPercentDiscountVoucher() { logger.info("Call createPercentDiscountVoucher()"); - Console.print("할인율을 입력해 주세요."); - int percent = Console.readInt(); + ConsoleUtil.print("할인율을 입력해 주세요."); + int percent = ConsoleUtil.readInt(); voucherController.createPercentDiscountVoucher(percent); } @@ -99,8 +98,8 @@ private void createPercentDiscountVoucher() { private void createFixedAmountVoucher() { logger.info("Call createFixedAmountVoucher()"); - Console.print("할인 금액을 입력해 주세요."); - int amount = Console.readInt(); + ConsoleUtil.print("할인 금액을 입력해 주세요."); + int amount = ConsoleUtil.readInt(); voucherController.createFixedAmountVoucher(amount); } @@ -108,36 +107,34 @@ private void createFixedAmountVoucher() { private void getVoucherList() { logger.info("Call getVoucherList()"); - Console.printStringList(voucherController.getVouchersInfo()); + ConsoleUtil.printStringList(voucherController.getVouchersInfo()); } private void getBlacklist() { logger.info("Call getBlackListUsers()"); - Console.printStringList(userController.getBlacklistInfo()); + ConsoleUtil.printStringList(userController.getBlacklistInfo()); } private void close() { - logger.info("Call close()"); - - Console.print("프로그램이 종료되었습니다."); + isRunning = false; } private void handleException(Exception e) { if(e instanceof NumberFormatException) { - Console.print("숫자를 입력해 주세요."); + ConsoleUtil.print("숫자를 입력해 주세요."); return; } if(e instanceof IllegalArgumentException) { - Console.print(e.getMessage()); + ConsoleUtil.print(e.getMessage()); return; } logger.error(e.toString()); String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; - Console.print(errorMessage); + ConsoleUtil.print(errorMessage); isRunning = false; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java b/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java new file mode 100644 index 0000000000..8394d7ae87 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java @@ -0,0 +1,35 @@ +package team.marco.voucher_management_system.view.console.management; + +import java.util.Arrays; + +public enum ManagementCommandType { + CREATE_VOUCHER(1, "쿠폰 생성"), + VOUCHER_LIST(2, "쿠폰 목록 조회"), + SEARCH_VOUCHER(3, "쿠폰 검색"), + CUSTOMER_LIST(4, "전체 회원 조회"), + BLACKLIST(5, "블랙 리스트 회원 조회"), + BACK(6, "메인 페이지로 돌아가기"); + + private int num; + private String description; + + ManagementCommandType(int num, String description) { + this.num = num; + this.description = description; + } + + public static ManagementCommandType get(int num) { + return Arrays.stream(ManagementCommandType.values()) + .filter(v -> v.getNum() == num) + .findAny() + .orElseThrow(); + } + + public int getNum() { + return num; + } + + public String getInfo() { + return num + ". " + description; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java similarity index 54% rename from src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java rename to src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java index b8a0b0babc..0f845c35fb 100644 --- a/src/main/java/team/marco/voucher_management_system/view/ConsoleWalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java @@ -1,30 +1,30 @@ -package team.marco.voucher_management_system.view; +package team.marco.voucher_management_system.view.console.wallet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.CustomerController; import team.marco.voucher_management_system.controller.VoucherController; -import team.marco.voucher_management_system.view.util.Console; +import team.marco.voucher_management_system.view.console.ConsoleUtil; @Component -public class ConsoleWalletApplication { - private static final Logger logger = LoggerFactory.getLogger(ConsoleWalletApplication.class); +public class WalletApplication { + private static final Logger logger = LoggerFactory.getLogger(WalletApplication.class); private final VoucherController voucherController; private final CustomerController customerController; private Boolean isRunning; - public ConsoleWalletApplication(VoucherController voucherController, CustomerController customerController) { + public WalletApplication(VoucherController voucherController, CustomerController customerController) { this.voucherController = voucherController; this.customerController = customerController; this.isRunning = true; } public void run() { - Console.print("지갑 서비스를 이용하기 위해 사용자의 아이디를 입력해주세요."); - String customerId = Console.readString(); + ConsoleUtil.print("지갑 서비스를 이용하기 위해 사용자의 아이디를 입력해주세요."); + String customerId = ConsoleUtil.readString(); if(!customerController.isExistCustomer(customerId)) { throw new IllegalArgumentException("올바른 사용자 아이디가 아닙니다."); @@ -40,42 +40,44 @@ public void run() { } private void selectCommand(String customerId) { - Console.print(""" - === 지갑 관리 프로그램 === - register: 쿠폰 등록 - list: 나의 쿠폰 목록 조회 - remove: 쿠폰 삭제 - back: 쿠폰 관리 페이지로 돌아가기"""); + ConsoleUtil.print("=== 지갑 페이지 ==="); - String input = Console.readString(); + for(WalletCommandType type : WalletCommandType.values()) { + ConsoleUtil.print(type.getInfo()); + } + + ConsoleUtil.println(); + + ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); + int input = ConsoleUtil.readInt(); - CommandType commandType = CommandType.getCommandType(input); + WalletCommandType commandType = WalletCommandType.get(input); switch (commandType) { case REGISTER -> registerVoucher(customerId); case LIST -> getMyVouchers(customerId); - case REMOVE -> removeVoucher(customerId); + case REMOVE -> removeVoucher(); case BACK -> backToMainApplication(); } } private void registerVoucher(String customerId) { - Console.print("등록하실 쿠폰 번호를 입력해주세요."); - String voucherId = Console.readString(); + ConsoleUtil.print("등록하실 쿠폰 번호를 입력해주세요."); + String voucherId = ConsoleUtil.readString(); voucherController.assignVoucherOwner(voucherId, customerId); - Console.print("쿠폰 등록이 완료되었습니다."); + ConsoleUtil.print("쿠폰 등록이 완료되었습니다."); } private void getMyVouchers(String customerId) { - Console.printStringList(voucherController.getVouchersInfo(customerId)); + ConsoleUtil.printStringList(voucherController.getVouchersInfo(customerId)); } - private void removeVoucher(String customerId) { - Console.print("제거할 쿠폰 번호를 입력해주세요."); - String voucherId = Console.readString(); + private void removeVoucher() { + ConsoleUtil.print("제거할 쿠폰 번호를 입력해주세요."); + String voucherId = ConsoleUtil.readString(); voucherController.deleteVoucher(voucherId); - Console.print("쿠폰 삭제가 완료되었습니다."); + ConsoleUtil.print("쿠폰 삭제가 완료되었습니다."); } private void backToMainApplication() { @@ -84,18 +86,18 @@ private void backToMainApplication() { private void handleException(Exception e) { if(e instanceof NumberFormatException) { - Console.print("숫자를 입력해 주세요."); + ConsoleUtil.print("숫자를 입력해 주세요."); return; } if(e instanceof IllegalArgumentException) { - Console.print(e.getMessage()); + ConsoleUtil.print(e.getMessage()); return; } logger.error(e.toString()); - Console.print(e.getMessage()); + ConsoleUtil.print(e.getMessage()); isRunning = false; } diff --git a/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java b/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java new file mode 100644 index 0000000000..ef2df92965 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.view.console.wallet; + +import java.util.Arrays; + +public enum WalletCommandType { + REGISTER(1, "쿠폰 등록"), + LIST(2, "나의 쿠폰 목록 조회"), + REMOVE(3, "쿠폰 삭제"), + BACK(4, "메인 페이지로 돌아가기"); + + private int num; + private String description; + + WalletCommandType(int num, String description) { + this.num = num; + this.description = description; + } + + public static WalletCommandType get(int num) { + return Arrays.stream(WalletCommandType.values()) + .filter(v -> v.getNum() == num) + .findAny() + .orElseThrow(); + } + + public int getNum() { + return num; + } + + public String getInfo() { + return num + ". " + description; + } +} From e779e5eabbb9bbfd29be98e777288614cecba99e Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 21:23:14 +0900 Subject: [PATCH 079/134] =?UTF-8?q?test:=20UUIDUtil=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/CsvBlacklistRepository.java | 5 +- .../custromer/JdbcCustomerRepository.java | 5 +- .../voucher/JdbcVoucherRepository.java | 23 ++++---- .../util/UUIDUtil.java | 11 ++++ ...ucherManagementSystemApplicationTests.java | 13 ----- .../util/UUIDUtilTest.java | 55 +++++++++++++++++++ 6 files changed, 84 insertions(+), 28 deletions(-) delete mode 100644 src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java create mode 100644 src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java index d1017ef5d9..08f4bc49c1 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java @@ -11,7 +11,8 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.List; -import java.util.UUID; + +import static team.marco.voucher_management_system.util.UUIDUtil.stringToUUID; @Repository public class CsvBlacklistRepository implements BlacklistRepository { @@ -27,7 +28,7 @@ private List loadBlacklist(String path) { reader.readLine(); // skip header return reader.lines() .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .map(data -> new CustomerIdAndName(UUID.fromString(data[0]), data[1])) + .map(data -> new CustomerIdAndName(stringToUUID(data[0]), data[1])) .toList(); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index fa0067aa45..2b0473f3d6 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -14,6 +14,7 @@ import java.util.*; import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; +import static team.marco.voucher_management_system.util.UUIDUtil.uuidToBytes; @Repository public class JdbcCustomerRepository implements CustomerRepository { @@ -32,7 +33,7 @@ public JdbcCustomerRepository(JdbcTemplate jdbcTemplate) { @Override public Customer insert(Customer customer) { int update = jdbcTemplate.update(INSERT_SQL, - customer.getId().toString().getBytes(), + uuidToBytes(customer.getId()), customer.getName(), customer.getEmail(), Timestamp.valueOf(customer.getCreatedAt())); @@ -58,7 +59,7 @@ public Optional findById(UUID customerId) { try { Customer customer = jdbcTemplate.queryForObject(SELECT_BY_ID_SQL, (resultSet, rowNum) -> resultSetToCustomer(resultSet), - customerId.toString().getBytes()); + uuidToBytes(customerId)); return Optional.of(customer); } catch (DataAccessException e) { diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index a36ac69f48..f6688ddb48 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -16,6 +16,7 @@ import java.util.*; import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; +import static team.marco.voucher_management_system.util.UUIDUtil.uuidToBytes; @Profile("prod") @Repository @@ -44,20 +45,20 @@ public Voucher save(Voucher voucher) { case FIXED -> { FixedAmountVoucher amountVoucher = (FixedAmountVoucher) voucher; update = jdbcTemplate.update(INSERT_SQL, - voucher.getId().toString().getBytes(), + uuidToBytes(voucher.getId()), voucher.getType().name(), amountVoucher.getAmount(), null, - voucher.getOwnerId() == null ? null : voucher.getOwnerId().toString().getBytes()); + voucher.getOwnerId() == null ? null : uuidToBytes(voucher.getOwnerId())); } case PERCENT -> { PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; update = jdbcTemplate.update(INSERT_SQL, - voucher.getId().toString().getBytes(), + uuidToBytes(voucher.getId()), voucher.getType().name(), null, percentVoucher.getPercent(), - voucher.getOwnerId() == null ? null : voucher.getOwnerId().toString().getBytes()); + voucher.getOwnerId() == null ? null : uuidToBytes(voucher.getOwnerId())); } } @@ -83,7 +84,7 @@ public List findByOwner(UUID ownerId) { List vouchers = new ArrayList<>(); jdbcTemplate.query(SELECT_BY_OWNER_SQL , (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet)) - , ownerId.toString()); + , uuidToBytes(ownerId)); return Collections.unmodifiableList(vouchers); } @@ -92,7 +93,7 @@ public List findByOwner(UUID ownerId) { public Optional findById(UUID voucherId) { return Optional.of(jdbcTemplate.queryForObject(SELECT_BY_ID_SQL , (resultSet, rowNum) -> resultSetToVoucher(resultSet) - , voucherId.toString())); + , uuidToBytes(voucherId))); } @Override @@ -104,16 +105,16 @@ public Voucher update(Voucher voucher) { update = jdbcTemplate.update(UPDATE_BY_ID_SQL, amountVoucher.getAmount(), null, - amountVoucher.getOwnerId() != null ? amountVoucher.getOwnerId().toString().getBytes() : null, - voucher.getId().toString().getBytes()); + amountVoucher.getOwnerId() != null ? uuidToBytes(amountVoucher.getOwnerId()) : null, + uuidToBytes(voucher.getId())); } case PERCENT -> { PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; update = jdbcTemplate.update(UPDATE_BY_ID_SQL, null, percentVoucher.getPercent(), - percentVoucher.getOwnerId() != null ? percentVoucher.getOwnerId().toString().getBytes() : null, - voucher.getId().toString().getBytes()); + percentVoucher.getOwnerId() != null ? uuidToBytes(percentVoucher.getOwnerId()) : null, + uuidToBytes(voucher.getId())); } } @@ -127,7 +128,7 @@ public Voucher update(Voucher voucher) { @Override public void deleteById(UUID voucherId) { - jdbcTemplate.update(DELETE_BY_ID_SQL, voucherId.toString().getBytes()); + jdbcTemplate.update(DELETE_BY_ID_SQL, uuidToBytes(voucherId)); } private Voucher resultSetToVoucher(ResultSet resultSet) throws SQLException { diff --git a/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java b/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java index 5cbaa7a6d6..72acb5d4d6 100644 --- a/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java +++ b/src/main/java/team/marco/voucher_management_system/util/UUIDUtil.java @@ -13,4 +13,15 @@ public static UUID bytesToUUID(byte[] bytes) { ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); return new UUID(byteBuffer.getLong(), byteBuffer.getLong()); } + + public static UUID stringToUUID(String string) { + return UUID.fromString(string); + } + + public static byte[] uuidToBytes(UUID uuid) { + ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); + byteBuffer.putLong(uuid.getMostSignificantBits()); + byteBuffer.putLong(uuid.getLeastSignificantBits()); + return byteBuffer.array(); + } } diff --git a/src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java b/src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java deleted file mode 100644 index c6e753083f..0000000000 --- a/src/test/java/team/marco/voucher_management_system/VoucherManagementSystemApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package team.marco.voucher_management_system; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class VoucherManagementSystemApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java b/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java new file mode 100644 index 0000000000..97005e7ed9 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java @@ -0,0 +1,55 @@ +package team.marco.voucher_management_system.util; + +import org.junit.jupiter.api.Test; + +import java.nio.ByteBuffer; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +class UUIDUtilTest { + @Test + void 바이트_배열을_UUID로_변환() { + // uuid가 바이트 배열로 주어졌을 때 + UUID uuid = UUID.randomUUID(); + byte[] uuidBytes = toBytes(uuid); + + // 바이트 배열을 UUID로 변환 + UUID converted = UUIDUtil.bytesToUUID(uuidBytes); + + // 변환 전 uuid를 반환 + assertThat(converted).isEqualTo(uuid); + } + + @Test + void 문자열을_UUID로_변환() { + // uuid가 문자열로 주어졌을 때 + UUID uuid = UUID.randomUUID(); + String uuidString = uuid.toString(); + + // 문자열을 UUID로 변환 + UUID converted = UUIDUtil.stringToUUID(uuidString); + + // 변환 전 uuid를 반환 + assertThat(converted).isEqualTo(uuid); + } + + @Test + void UUID를_바이트_배열로_변환() { + // uuid가 주어 졌을 때 + UUID uuid = UUID.randomUUID(); + + // UUID를 바이트 배열로 변환 + byte[] converted = UUIDUtil.uuidToBytes(uuid); + + // 변환 전 uuid를 반환 + assertThat(converted).isEqualTo(toBytes(uuid)); + } + + private byte[] toBytes(UUID uuid) { + ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); + byteBuffer.putLong(uuid.getMostSignificantBits()); + byteBuffer.putLong(uuid.getLeastSignificantBits()); + return byteBuffer.array(); + } +} \ No newline at end of file From 5e97b28abcbbe8dd2bbd259646e7ebc8ed0c66dd Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 21:35:16 +0900 Subject: [PATCH 080/134] =?UTF-8?q?test:=20PercentDiscountVoucher=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/PercentDiscountVoucherTest.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java index 817df745a5..72a446c0b2 100644 --- a/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java +++ b/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java @@ -10,6 +10,7 @@ class PercentDiscountVoucherTest { @Test + @DisplayName("[할인 비율]로 할인 쿠폰을 생성할 수 있다.") void 고정비율_할인쿠폰_생성_성공() { // 20% 할인 쿠폰 생성 int discountPercent = 20; @@ -24,7 +25,7 @@ class PercentDiscountVoucherTest { } @Test - @DisplayName("UUID 값와 함께 할인 쿠폰 생성 가능") + @DisplayName("[쿠폰 UUID, 할인 비율]로 할인 쿠폰 생성 가능") void 고정비율_할인쿠폰_생성_성공_2() { // 특정 UUID 값을 가진 20% 할인 쿠폰 생성 UUID voucherId = UUID.randomUUID(); @@ -39,6 +40,43 @@ class PercentDiscountVoucherTest { assertThat(voucher.getPercent()).isEqualTo(discountPercent); } + @Test + @DisplayName("[할인 비율, 쿠폰 소지자 UUID]로 할인 쿠폰 생성 가능") + void 고정비율_할인쿠폰_생성_성공_3() { + // 특정 UUID 값을 가진 20% 할인 쿠폰 생성 + 쿠폰 소유자 + UUID voucherId = UUID.randomUUID(); + int discountPercent = 20; + UUID ownerId = UUID.randomUUID(); + PercentDiscountVoucher voucher = new PercentDiscountVoucher(voucherId, discountPercent, ownerId); + + // 1. 입력한 UUID가 할당 + assertThat(voucher.getId()).isEqualTo(voucherId); + // 2. VoucherType은 자동으로 PERCENT + assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getPercent()).isEqualTo(discountPercent); + // 4. 입력한 쿠폰 소지자 할당 + assertThat(voucher.getOwnerId()).isEqualTo(ownerId); + } + + @Test + @DisplayName("[쿠폰 UUID, 할인 비율, 쿠폰 소지자 UUID]로 할인 쿠폰 생성 가능") + void 고정비율_할인쿠폰_생성_성공_4() { + // 쿠폰 소유자와 함께 20% 할인 쿠폰 생성 + int discountPercent = 20; + UUID ownerId = UUID.randomUUID(); + PercentDiscountVoucher voucher = new PercentDiscountVoucher(discountPercent, ownerId); + + // 1. UUID가 자동으로 할당 + assertThat(voucher.getId()).isNotNull(); + // 2. VoucherType은 자동으로 PERCENT + assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); + // 3. 입력한 비율만큼 할인 + assertThat(voucher.getPercent()).isEqualTo(discountPercent); + // 4. 입력한 쿠폰 소지자 할당 + assertThat(voucher.getOwnerId()).isEqualTo(ownerId); + } + @Test @DisplayName("할인 비율은 0%일 수 없다.") void 고정비율_할인쿠폰_생성_실패() { From 5b814df51ce6eb095c4ccd6486133730d4a066be Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 29 Oct 2023 21:42:35 +0900 Subject: [PATCH 081/134] =?UTF-8?q?refactor:=20UUID=EB=A5=BC=20byte[]?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=ED=99=98=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=9D=84=20DB=20=EB=82=B4=EC=9E=A5=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EC=97=90=EC=84=9C=20UUIDUtil=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/custromer/JdbcCustomerRepository.java | 4 ++-- .../repository/voucher/JdbcVoucherRepository.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index 2b0473f3d6..6d31b64e21 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -21,8 +21,8 @@ public class JdbcCustomerRepository implements CustomerRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcCustomerRepository.class); private static final String SELECT_ALL_SQL = "SELECT * FROM customers"; - private static final String SELECT_BY_ID_SQL = "SELECT * FROM customers WHERE customer_id = UUID_TO_BIN(?)"; - private static final String INSERT_SQL = "INSERT INTO customers(customer_id, name, email, created_at) VALUES (UUID_TO_BIN(?), ?, ?, ?)"; + private static final String SELECT_BY_ID_SQL = "SELECT * FROM customers WHERE customer_id = ?"; + private static final String INSERT_SQL = "INSERT INTO customers(customer_id, name, email, created_at) VALUES (?, ?, ?, ?)"; private final JdbcTemplate jdbcTemplate; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index f6688ddb48..cbd0c741c6 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -23,12 +23,12 @@ public class JdbcVoucherRepository implements VoucherRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcVoucherRepository.class); - private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent, owner_id) VALUES (UUID_TO_BIN(?), ?, ?, ?, UUID_TO_BIN(?))"; + private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent, owner_id) VALUES (?, ?, ?, ?, ?)"; private static final String SELECT_ALL_SQL = "SELECT * FROM vouchers"; - private static final String SELECT_BY_OWNER_SQL = "SELECT * FROM vouchers WHERE owner_id = UUID_TO_BIN(?)"; - private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = UUID_TO_BIN(?)"; - private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = UUID_TO_BIN(?) WHERE voucher_id = UUID_TO_BIN(?)"; - private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = UUID_TO_BIN(?)"; + private static final String SELECT_BY_OWNER_SQL = "SELECT * FROM vouchers WHERE owner_id = ?"; + private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = ?"; + private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = ? WHERE voucher_id = ?"; + private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = ?"; private final JdbcTemplate jdbcTemplate; private final CustomerRepository customerRepository; From ce3d0269123a85bda66fcb28b1a0edd836002e05 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 30 Oct 2023 00:28:55 +0900 Subject: [PATCH 082/134] =?UTF-8?q?test:=20VoucherService=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/VoucherService.java | 12 +- .../service/VoucherServiceTest.java | 147 ++++++++++++++++++ 2 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java diff --git a/src/main/java/team/marco/voucher_management_system/service/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/VoucherService.java index 313691023f..2d4b74067d 100644 --- a/src/main/java/team/marco/voucher_management_system/service/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/VoucherService.java @@ -23,15 +23,15 @@ public VoucherService(VoucherRepository voucherRepository) { } @Transactional - public void createFixedAmountVoucher(int amount) { + public Voucher createFixedAmountVoucher(int amount) { Voucher voucher = new FixedAmountVoucher(amount); - voucherRepository.save(voucher); + return voucherRepository.save(voucher); } @Transactional - public void createPercentDiscountVoucher(int percent) { + public Voucher createPercentDiscountVoucher(int percent) { Voucher voucher = new PercentDiscountVoucher(percent); - voucherRepository.save(voucher); + return voucherRepository.save(voucher); } public List getVouchers() { @@ -43,13 +43,13 @@ public List getVouchers(UUID customerId) { } @Transactional - public void assignVoucherOwner(UUID voucherId, UUID customerId) { + public Voucher assignVoucherOwner(UUID voucherId, UUID customerId) { logger.debug("[VoucherService] Call assignVoucherOwner()"); Voucher voucher = voucherRepository.findById(voucherId).orElseThrow(); voucher.assigneOwner(customerId); - voucherRepository.update(voucher); + return voucherRepository.update(voucher); } public Voucher getVoucher(UUID voucherId) { diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java new file mode 100644 index 0000000000..5473a44a1a --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -0,0 +1,147 @@ +package team.marco.voucher_management_system.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; +import team.marco.voucher_management_system.repository.voucher.VoucherRepository; + +import java.util.List; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +class VoucherServiceTest { + private VoucherService voucherService; + private VoucherRepository voucherRepository; + + @BeforeEach + @DisplayName("각 테스트는 빈 메모리 저장소를 가지고 테스트를 시작합니다.") + void VoucherService_초기화() { + voucherRepository = new MemoryVoucherRepository(); + voucherService = new VoucherService(voucherRepository); + } + + @Test + void 고정_할인_쿠폰_생성() { + // 할인 금액이 주어 졌을 때 + int amount = 1000; + + // 고정 금액 쿠폰 생성 요청 + Voucher returned = voucherService.createFixedAmountVoucher(amount); + + // 1. 생성된 쿠폰이 FixedAmountVoucher 타입 + assertThat(returned).isInstanceOf(FixedAmountVoucher.class); + // 2. 생성된 쿠폰의 할인 금액이 amount와 동일 + FixedAmountVoucher voucher = (FixedAmountVoucher) returned; + assertThat(voucher.getAmount()).isEqualTo(amount); + } + + @Test + void 퍼센트_할인_쿠폰_생성() { + // 할인율이 주어 졌을 때 + int percent = 10; + + // % 금액 쿠폰 생성 요청 + Voucher returned = voucherService.createPercentDiscountVoucher(percent); + + // 1. 생성된 쿠폰이 PercentDiscountVoucher 타입 + assertThat(returned).isInstanceOf(PercentDiscountVoucher.class); + // 2. 생성된 쿠폰의 할인율이 percent와 동일 + PercentDiscountVoucher voucher = (PercentDiscountVoucher) returned; + assertThat(voucher.getPercent()).isEqualTo(percent); + } + + @Test + void 전체_쿠폰_목록_조회() { + // 리포지토리에 쿠폰 2개가 저장되어 있을 때 + Voucher voucher = new FixedAmountVoucher(1000); + Voucher voucher2 = new PercentDiscountVoucher(10); + voucherRepository.save(voucher); + voucherRepository.save(voucher2); + + // 전체 쿠폰 목록 요청 + List returned = voucherService.getVouchers(); + + // 쿠폰 목록의 크기가 2 + assertThat(returned).hasSize(2); + } + + @Test + void 쿠폰_목록_조회() { + // 리포지토리에 쿠폰 2개가 저장되어 있을 때 + Voucher voucher = new FixedAmountVoucher(1000); + Voucher voucher2 = new PercentDiscountVoucher(10); + voucherRepository.save(voucher); + voucherRepository.save(voucher2); + + // 전체 쿠폰 목록 요청 + List returned = voucherService.getVouchers(); + + // 쿠폰 목록의 크기가 2 + assertThat(returned).hasSize(2); + } + + @Test + void 특정_사용자의_쿠폰_목록_조회() { + // 쿠폰 소지자가 존재하는 쿠폰 저장 + UUID customerId = UUID.randomUUID(); + Voucher voucher = new FixedAmountVoucher(1000, customerId); + voucherRepository.save(voucher); + + // 쿠폰 소지자가 존재하지 않는 쿠폰 저장 + Voucher voucher2 = new PercentDiscountVoucher(10); + voucherRepository.save(voucher2); + + // 사용자 UUID로 쿠폰 목록 요청 + List returned = voucherService.getVouchers(customerId); + + // 쿠폰 목록의 크기가 1 + assertThat(returned).hasSize(1); + } + + @Test + void 쿠폰_소지자_할당() { + // 쿠폰 생성 + Voucher voucher = new FixedAmountVoucher(1000); + voucherRepository.save(voucher); + + // 쿠폰에 쿠폰 소지자 할당 요청 + UUID customerId = UUID.randomUUID(); + voucherService.assignVoucherOwner(voucher.getId(), customerId); + + // 쿠폰 소지자가 할당한 소지자와 동일 + Voucher returned = voucherRepository.findById(voucher.getId()).get(); + assertThat(returned.getOwnerId()).isEqualTo(customerId); + } + + @Test + void 쿠폰_아이디로_조회() { + // 쿠폰 생성 + Voucher voucher = new FixedAmountVoucher(1000); + voucherRepository.save(voucher); + + // UUID로 쿠폰 조회 + Voucher found = voucherService.getVoucher(voucher.getId()); + + // 조회된 쿠폰의 UUID가 인자로 넘겨준 UUID와 같음 + assertThat(found.getId()).isEqualTo(voucher.getId()); + } + + @Test + void 쿠폰_아이디로_삭제() { + // 쿠폰 생성 + Voucher voucher = new FixedAmountVoucher(1000); + voucherRepository.save(voucher); + + // UUID로 쿠폰 삭제 + voucherService.deleteVoucher(voucher.getId()); + + // 쿠폰이 삭제됨 + List vouchers = voucherRepository.findAll(); + assertThat(vouchers).hasSize(0); + } +} \ No newline at end of file From 50cbc2b2f107028d693553072bf1187349aefa24 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 30 Oct 2023 00:41:01 +0900 Subject: [PATCH 083/134] =?UTF-8?q?test:=20BlacklistService=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/BlacklistService.java | 6 ++-- .../service/BlacklistServiceTest.java | 33 +++++++++++++++++++ src/test/resources/test_blacklist.csv | 3 ++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java create mode 100644 src/test/resources/test_blacklist.csv diff --git a/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java b/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java index 8dce71fda8..16d7658453 100644 --- a/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java +++ b/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java @@ -1,16 +1,16 @@ package team.marco.voucher_management_system.service; import org.springframework.stereotype.Service; -import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; +import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; import java.util.List; @Service public class BlacklistService { - private final CsvBlacklistRepository blacklistRepository; + private final BlacklistRepository blacklistRepository; - public BlacklistService(CsvBlacklistRepository blacklistRepository) { + public BlacklistService(BlacklistRepository blacklistRepository) { this.blacklistRepository = blacklistRepository; } diff --git a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java new file mode 100644 index 0000000000..31c69044d1 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; +import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; +import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class BlacklistServiceTest { + private BlacklistService blacklistService; + private BlacklistRepository blacklistRepository; + + @BeforeEach + void VoucherService_초기화() { + blacklistRepository = new CsvBlacklistRepository("src/test/resources/test_blacklist.csv"); + blacklistService = new BlacklistService(blacklistRepository); + } + + @Test + void 블랙_리스트_조회() { + // test_blacklist 파일에 2명의 블랙리스트가 있을 때 + + // 블랙리스트 조회 + List blacklist = blacklistService.getBlacklist(); + + // 블랙리스트 크기가 2 + assertThat(blacklist).hasSize(2); + } +} \ No newline at end of file diff --git a/src/test/resources/test_blacklist.csv b/src/test/resources/test_blacklist.csv new file mode 100644 index 0000000000..3f6a9afedd --- /dev/null +++ b/src/test/resources/test_blacklist.csv @@ -0,0 +1,3 @@ +id,name +461b8847-578d-43c7-8472-d9374bbac41a,정의진 +461b8847-578d-43c7-8472-d9374bbac42b,김현우 From c474e19821caaa1b0f3aa7d7e32ae18cc95916b8 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Mon, 30 Oct 2023 01:02:12 +0900 Subject: [PATCH 084/134] =?UTF-8?q?test:=20CustomerSerivce=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/CustomerServiceTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java new file mode 100644 index 0000000000..66fe8e85ad --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -0,0 +1,46 @@ +package team.marco.voucher_management_system.service; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.transaction.annotation.Transactional; +import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.repository.custromer.CustomerRepository; + +import static org.assertj.core.api.Assertions.assertThat; + +@Transactional +@SpringBootTest +class CustomerServiceTest { + @Autowired + private CustomerService customerService; + + @Autowired + private CustomerRepository customerRepository; + + @Autowired + private JdbcTemplate jdbcTemplate; + + @BeforeEach + void setUp() { + String query = "DELETE FROM customers"; + jdbcTemplate.update(query); + } + + @Test + void 사용자_ID로_조회() { + // 사용자 등록 + Customer customer = new Customer("test", "test@gmail.com"); + customerRepository.insert(customer); + + // 사용자 조회 + Customer found = customerService.findCustomer(customer.getId()); + + // 등록된 사용자와 동일한 사용자가 조회됨 + assertThat(found.getId()).isEqualTo(customer.getId()); + assertThat(found.getName()).isEqualTo(customer.getName()); + assertThat(found.getEmail()).isEqualTo(customer.getEmail()); + } +} \ No newline at end of file From ec5907ab11c324f97c42f87bb0a5517f6a04d09c Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 31 Oct 2023 16:52:07 +0900 Subject: [PATCH 085/134] =?UTF-8?q?structure:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 레이어별(ex. controller, service ...) 로 나눈 후 도메인별(ex. voucher, customer...)로 나눔 --- .../VoucherManagementSystemApplication.java | 6 +----- .../{ => customer}/CustomerController.java | 6 +++--- .../{ => voucher}/VoucherController.java | 4 ++-- .../{model => domain/customer}/Customer.java | 2 +- .../voucher/FixedAmountVoucher.java | 4 ++-- .../voucher/PercentDiscountVoucher.java | 4 ++-- .../{model => domain}/voucher/Voucher.java | 2 +- .../domain/voucher/VoucherType.java | 5 +++++ .../model/voucher/VoucherType.java | 5 ----- .../custromer/CustomerRepository.java | 2 +- .../custromer/JdbcCustomerRepository.java | 2 +- .../voucher/JdbcVoucherRepository.java | 8 +++---- .../voucher/JsonFileVoucherRepository.java | 2 +- .../repository/voucher/LoadedJsonVoucher.java | 8 +++---- .../voucher/MemoryVoucherRepository.java | 2 +- .../repository/voucher/VoucherRepository.java | 2 +- .../{ => customer}/BlacklistService.java | 2 +- .../{ => customer}/CustomerService.java | 4 ++-- .../service/{ => voucher}/VoucherService.java | 8 +++---- .../{console => consoleapp}/ConsoleUtil.java | 2 +- .../{console => consoleapp}/ServiceType.java | 2 +- .../VoucherApplication.java | 6 +++--- .../management/ManagementApplication.java | 8 +++---- .../management/ManagementCommandType.java | 2 +- .../wallet/WalletApplication.java | 8 +++---- .../wallet/WalletCommandType.java | 2 +- .../voucher/FixedAmountVoucherTest.java | 2 +- .../voucher/PercentDiscountVoucherTest.java | 2 +- .../custromer/JdbcCustomerRepositoryTest.java | 2 +- .../voucher/JdbcVoucherRepositoryTest.java | 21 +++++++++---------- .../voucher/MemoryVoucherRepositoryTest.java | 6 +++--- .../service/BlacklistServiceTest.java | 1 + .../service/CustomerServiceTest.java | 3 ++- .../service/VoucherServiceTest.java | 7 ++++--- 34 files changed, 75 insertions(+), 77 deletions(-) rename src/main/java/team/marco/voucher_management_system/controller/{ => customer}/CustomerController.java (82%) rename src/main/java/team/marco/voucher_management_system/controller/{ => voucher}/VoucherController.java (90%) rename src/main/java/team/marco/voucher_management_system/{model => domain/customer}/Customer.java (93%) rename src/main/java/team/marco/voucher_management_system/{model => domain}/voucher/FixedAmountVoucher.java (93%) rename src/main/java/team/marco/voucher_management_system/{model => domain}/voucher/PercentDiscountVoucher.java (93%) rename src/main/java/team/marco/voucher_management_system/{model => domain}/voucher/Voucher.java (90%) create mode 100644 src/main/java/team/marco/voucher_management_system/domain/voucher/VoucherType.java delete mode 100644 src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java rename src/main/java/team/marco/voucher_management_system/service/{ => customer}/BlacklistService.java (90%) rename src/main/java/team/marco/voucher_management_system/service/{ => customer}/CustomerService.java (79%) rename src/main/java/team/marco/voucher_management_system/service/{ => voucher}/VoucherService.java (85%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/ConsoleUtil.java (96%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/ServiceType.java (91%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/VoucherApplication.java (91%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/management/ManagementApplication.java (92%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/management/ManagementCommandType.java (92%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/wallet/WalletApplication.java (91%) rename src/main/java/team/marco/voucher_management_system/view/{console => consoleapp}/wallet/WalletCommandType.java (91%) rename src/test/java/team/marco/voucher_management_system/{model => domain}/voucher/FixedAmountVoucherTest.java (98%) rename src/test/java/team/marco/voucher_management_system/{model => domain}/voucher/PercentDiscountVoucherTest.java (98%) diff --git a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java index 229fba48c0..7ce3f87291 100644 --- a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import team.marco.voucher_management_system.view.console.VoucherApplication; +import team.marco.voucher_management_system.view.consoleapp.VoucherApplication; @SpringBootApplication public class VoucherManagementSystemApplication { @@ -14,11 +14,7 @@ public class VoucherManagementSystemApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); - logger.info("Program start {}", context.getEnvironment().getActiveProfiles()); - VoucherApplication application = context.getBean(VoucherApplication.class); application.run(); - - logger.info("Program exit"); } } diff --git a/src/main/java/team/marco/voucher_management_system/controller/CustomerController.java b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java similarity index 82% rename from src/main/java/team/marco/voucher_management_system/controller/CustomerController.java rename to src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java index 4be846f81f..b26ee43940 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/CustomerController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java @@ -1,8 +1,8 @@ -package team.marco.voucher_management_system.controller; +package team.marco.voucher_management_system.controller.customer; import org.springframework.stereotype.Controller; -import team.marco.voucher_management_system.service.BlacklistService; -import team.marco.voucher_management_system.service.CustomerService; +import team.marco.voucher_management_system.service.customer.BlacklistService; +import team.marco.voucher_management_system.service.customer.CustomerService; import java.util.List; import java.util.NoSuchElementException; diff --git a/src/main/java/team/marco/voucher_management_system/controller/VoucherController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java similarity index 90% rename from src/main/java/team/marco/voucher_management_system/controller/VoucherController.java rename to src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java index 1852db67b6..d23a2a3ea9 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/VoucherController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java @@ -1,7 +1,7 @@ -package team.marco.voucher_management_system.controller; +package team.marco.voucher_management_system.controller.voucher; import org.springframework.stereotype.Controller; -import team.marco.voucher_management_system.service.VoucherService; +import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/model/Customer.java b/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java similarity index 93% rename from src/main/java/team/marco/voucher_management_system/model/Customer.java rename to src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java index 9b0aea101c..931f076283 100644 --- a/src/main/java/team/marco/voucher_management_system/model/Customer.java +++ b/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model; +package team.marco.voucher_management_system.domain.customer; import java.time.LocalDateTime; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java similarity index 93% rename from src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java rename to src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java index 3890484f72..6ef90b8748 100644 --- a/src/main/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model.voucher; +package team.marco.voucher_management_system.domain.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.voucher_management_system.model.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; public class FixedAmountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); diff --git a/src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java similarity index 93% rename from src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java rename to src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java index 1d75c4fd6f..5d2b90f3c2 100644 --- a/src/main/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model.voucher; +package team.marco.voucher_management_system.domain.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ import java.util.UUID; import static java.text.MessageFormat.format; -import static team.marco.voucher_management_system.model.voucher.VoucherType.PERCENT; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; public class PercentDiscountVoucher extends Voucher { private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); diff --git a/src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java similarity index 90% rename from src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java rename to src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java index bd49898c94..955d83f37d 100644 --- a/src/main/java/team/marco/voucher_management_system/model/voucher/Voucher.java +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model.voucher; +package team.marco.voucher_management_system.domain.voucher; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/domain/voucher/VoucherType.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/VoucherType.java new file mode 100644 index 0000000000..612202b782 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/VoucherType.java @@ -0,0 +1,5 @@ +package team.marco.voucher_management_system.domain.voucher; + +public enum VoucherType { + FIXED, PERCENT +} diff --git a/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java b/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java deleted file mode 100644 index 4bd0606f13..0000000000 --- a/src/main/java/team/marco/voucher_management_system/model/voucher/VoucherType.java +++ /dev/null @@ -1,5 +0,0 @@ -package team.marco.voucher_management_system.model.voucher; - -public enum VoucherType { - FIXED, PERCENT -} diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java index d14e0f0095..7549a487f9 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java @@ -1,6 +1,6 @@ package team.marco.voucher_management_system.repository.custromer; -import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.domain.customer.Customer; import java.util.List; import java.util.Optional; diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index 6d31b64e21..d6b4f0228c 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -5,7 +5,7 @@ import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.domain.customer.Customer; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index cbd0c741c6..6b5c309d95 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -5,10 +5,10 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; -import team.marco.voucher_management_system.model.voucher.VoucherType; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import java.sql.ResultSet; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java index b1fd98ead5..75d8f1c31a 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java @@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import java.io.File; import java.io.IOException; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java index 8ece8e39e6..9120499d8a 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java @@ -1,9 +1,9 @@ package team.marco.voucher_management_system.repository.voucher; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; -import team.marco.voucher_management_system.model.voucher.VoucherType; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java index a383dec485..82da67fba4 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java @@ -2,7 +2,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; import java.util.Map; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java index 2dcd10dba2..f76169b540 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java @@ -1,6 +1,6 @@ package team.marco.voucher_management_system.repository.voucher; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; import java.util.Optional; diff --git a/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java b/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java similarity index 90% rename from src/main/java/team/marco/voucher_management_system/service/BlacklistService.java rename to src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java index 16d7658453..f18217a221 100644 --- a/src/main/java/team/marco/voucher_management_system/service/BlacklistService.java +++ b/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.service; +package team.marco.voucher_management_system.service.customer; import org.springframework.stereotype.Service; import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; diff --git a/src/main/java/team/marco/voucher_management_system/service/CustomerService.java b/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java similarity index 79% rename from src/main/java/team/marco/voucher_management_system/service/CustomerService.java rename to src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java index 29538169cc..6b70f8f10d 100644 --- a/src/main/java/team/marco/voucher_management_system/service/CustomerService.java +++ b/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java @@ -1,7 +1,7 @@ -package team.marco.voucher_management_system.service; +package team.marco.voucher_management_system.service.customer; import org.springframework.stereotype.Service; -import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import java.util.UUID; diff --git a/src/main/java/team/marco/voucher_management_system/service/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java similarity index 85% rename from src/main/java/team/marco/voucher_management_system/service/VoucherService.java rename to src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index 2d4b74067d..5ae11e3a28 100644 --- a/src/main/java/team/marco/voucher_management_system/service/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -1,12 +1,12 @@ -package team.marco.voucher_management_system.service; +package team.marco.voucher_management_system.service.voucher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import java.util.List; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java similarity index 96% rename from src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index 3e5a09d7f6..b73b51a7f4 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.view.console; +package team.marco.voucher_management_system.view.consoleapp; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java similarity index 91% rename from src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java index 6eef936266..8217812c3f 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/ServiceType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.view.console; +package team.marco.voucher_management_system.view.consoleapp; import java.util.Arrays; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java similarity index 91% rename from src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java index 64050b0734..70ebd826c8 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/VoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java @@ -1,10 +1,10 @@ -package team.marco.voucher_management_system.view.console; +package team.marco.voucher_management_system.view.consoleapp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.voucher_management_system.view.console.management.ManagementApplication; -import team.marco.voucher_management_system.view.console.wallet.WalletApplication; +import team.marco.voucher_management_system.view.consoleapp.management.ManagementApplication; +import team.marco.voucher_management_system.view.consoleapp.wallet.WalletApplication; import java.io.UncheckedIOException; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java similarity index 92% rename from src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 7fe9c4cac9..1e14117f39 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -1,11 +1,11 @@ -package team.marco.voucher_management_system.view.console.management; +package team.marco.voucher_management_system.view.consoleapp.management; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.voucher_management_system.controller.CustomerController; -import team.marco.voucher_management_system.controller.VoucherController; -import team.marco.voucher_management_system.view.console.ConsoleUtil; +import team.marco.voucher_management_system.controller.customer.CustomerController; +import team.marco.voucher_management_system.controller.voucher.VoucherController; +import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; import java.io.UncheckedIOException; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java similarity index 92% rename from src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java index 8394d7ae87..7418964fcb 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/management/ManagementCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.view.console.management; +package team.marco.voucher_management_system.view.consoleapp.management; import java.util.Arrays; diff --git a/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java similarity index 91% rename from src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index 0f845c35fb..2c1a90f560 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -1,11 +1,11 @@ -package team.marco.voucher_management_system.view.console.wallet; +package team.marco.voucher_management_system.view.consoleapp.wallet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import team.marco.voucher_management_system.controller.CustomerController; -import team.marco.voucher_management_system.controller.VoucherController; -import team.marco.voucher_management_system.view.console.ConsoleUtil; +import team.marco.voucher_management_system.controller.customer.CustomerController; +import team.marco.voucher_management_system.controller.voucher.VoucherController; +import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; @Component public class WalletApplication { diff --git a/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java similarity index 91% rename from src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java index ef2df92965..1423317b70 100644 --- a/src/main/java/team/marco/voucher_management_system/view/console/wallet/WalletCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.view.console.wallet; +package team.marco.voucher_management_system.view.consoleapp.wallet; import java.util.Arrays; diff --git a/src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java similarity index 98% rename from src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java rename to src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java index bd590b4130..790d7113ae 100644 --- a/src/test/java/team/marco/voucher_management_system/model/voucher/FixedAmountVoucherTest.java +++ b/src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model.voucher; +package team.marco.voucher_management_system.domain.voucher; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java similarity index 98% rename from src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java rename to src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java index 72a446c0b2..e8d2816dab 100644 --- a/src/test/java/team/marco/voucher_management_system/model/voucher/PercentDiscountVoucherTest.java +++ b/src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.model.voucher; +package team.marco.voucher_management_system.domain.voucher; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index 3c00637a95..47c66bc35d 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -10,7 +10,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.domain.customer.Customer; import java.util.List; diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 091dd8a827..5956ae76ab 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -1,6 +1,5 @@ package team.marco.voucher_management_system.repository.voucher; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -9,10 +8,10 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.model.Customer; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.customer.Customer; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.custromer.JdbcCustomerRepository; import java.util.List; @@ -47,7 +46,7 @@ void setUp() { Voucher saved = voucherRepository.save(voucher); // 생성된 바우처 반환 - Assertions.assertThat(saved).isEqualTo(voucher); + assertThat(saved).isEqualTo(voucher); } @Test @@ -79,7 +78,7 @@ void setUp() { Voucher found = voucherRepository.findById(voucher.getId()).get(); // 저장한 쿠폰과 동일한 쿠폰 반환 - Assertions.assertThat(found.getId()).isEqualTo(voucher.getId()); + assertThat(found.getId()).isEqualTo(voucher.getId()); } @Test @@ -96,8 +95,8 @@ void setUp() { List found = voucherRepository.findByOwner(customer.getId()); // 저장한 쿠폰과 동일한 쿠폰 반환 - Assertions.assertThat(found).hasSize(1); - Assertions.assertThat(found.get(0).getId()).isEqualTo(voucher.getId()); + assertThat(found).hasSize(1); + assertThat(found.get(0).getId()).isEqualTo(voucher.getId()); } @Test @@ -115,8 +114,8 @@ void setUp() { Voucher updated = voucherRepository.update(voucher); // 변경된 쿠폰 정보가 저장 - Assertions.assertThat(updated.getId()).isEqualTo(voucher.getId()); - Assertions.assertThat(updated.getOwnerId()).isEqualTo(customer.getId()); + assertThat(updated.getId()).isEqualTo(voucher.getId()); + assertThat(updated.getOwnerId()).isEqualTo(customer.getId()); } @Test diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java index c14f97f88c..ee668dfafc 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java @@ -4,9 +4,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; diff --git a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java index 31c69044d1..35d9a885ac 100644 --- a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java @@ -5,6 +5,7 @@ import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; +import team.marco.voucher_management_system.service.customer.BlacklistService; import java.util.List; diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java index 66fe8e85ad..ca4c6a04d2 100644 --- a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -6,8 +6,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.model.Customer; +import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.repository.custromer.CustomerRepository; +import team.marco.voucher_management_system.service.customer.CustomerService; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index 5473a44a1a..ff44651003 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -3,11 +3,12 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.voucher_management_system.model.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.model.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.model.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; +import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; +import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; import java.util.UUID; From 6395b5fc9e5a3abc1cfe2272595126221081a26c Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 31 Oct 2023 20:00:46 +0900 Subject: [PATCH 086/134] =?UTF-8?q?test:=20UUIDUtilTest=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/UUIDUtilTest.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java b/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java index 97005e7ed9..efe2f0eed0 100644 --- a/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java +++ b/src/test/java/team/marco/voucher_management_system/util/UUIDUtilTest.java @@ -1,5 +1,6 @@ package team.marco.voucher_management_system.util; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; @@ -8,41 +9,45 @@ import static org.assertj.core.api.Assertions.assertThat; class UUIDUtilTest { + + @DisplayName("바이트 배열을 UUID로 변환할 수 있다.") @Test - void 바이트_배열을_UUID로_변환() { - // uuid가 바이트 배열로 주어졌을 때 + void bytesToUUID() { + // given UUID uuid = UUID.randomUUID(); byte[] uuidBytes = toBytes(uuid); - // 바이트 배열을 UUID로 변환 + // when UUID converted = UUIDUtil.bytesToUUID(uuidBytes); - // 변환 전 uuid를 반환 + // then assertThat(converted).isEqualTo(uuid); } + @DisplayName("문자열을 UUID로 변환할 수 있다.") @Test - void 문자열을_UUID로_변환() { - // uuid가 문자열로 주어졌을 때 + void stringToUUID() { + // given UUID uuid = UUID.randomUUID(); String uuidString = uuid.toString(); - // 문자열을 UUID로 변환 + // when UUID converted = UUIDUtil.stringToUUID(uuidString); - // 변환 전 uuid를 반환 + // then assertThat(converted).isEqualTo(uuid); } + @DisplayName("UUID를 바이트 배열로 변환할 수 있다.") @Test - void UUID를_바이트_배열로_변환() { - // uuid가 주어 졌을 때 + void uuidToBytes() { + // given UUID uuid = UUID.randomUUID(); - // UUID를 바이트 배열로 변환 + // when byte[] converted = UUIDUtil.uuidToBytes(uuid); - // 변환 전 uuid를 반환 + // then assertThat(converted).isEqualTo(toBytes(uuid)); } From 37df16d5db7ea93ebe68ec6e00a7ddfe4e73b89f Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 31 Oct 2023 20:40:35 +0900 Subject: [PATCH 087/134] =?UTF-8?q?refactor:=20Customer=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=EC=97=90=20Builder=20=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/customer/Customer.java | 41 +++++++++++++++---- .../custromer/JdbcCustomerRepository.java | 9 ++-- .../custromer/JdbcCustomerRepositoryTest.java | 18 +++++--- .../voucher/JdbcVoucherRepositoryTest.java | 10 ++++- .../service/CustomerServiceTest.java | 8 +++- 5 files changed, 66 insertions(+), 20 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java b/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java index 931f076283..28683a4c4e 100644 --- a/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java +++ b/src/main/java/team/marco/voucher_management_system/domain/customer/Customer.java @@ -9,20 +9,13 @@ public class Customer { private final String email; private final LocalDateTime createdAt; - public Customer(UUID id, String name, String email, LocalDateTime createdAt) { + private Customer(UUID id, String name, String email, LocalDateTime createdAt) { this.id = id; this.name = name; this.email = email; this.createdAt = createdAt; } - public Customer(String name, String email) { - this.id = UUID.randomUUID(); - this.email = email; - this.name = name; - this.createdAt = LocalDateTime.now(); - } - public UUID getId() { return id; } @@ -38,4 +31,36 @@ public String getEmail() { public LocalDateTime getCreatedAt() { return createdAt; } + + public static class Builder { + private UUID id = UUID.randomUUID(); + private String name; + private String email; + private LocalDateTime createdAt = LocalDateTime.now(); + + public Builder(String name, String email) { + validateStringNotBlank(name); + validateStringNotBlank(email); + this.name = name; + this.email = email; + } + + public Builder id(UUID id) { + this.id = id; + return this; + } + + public Builder createdAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + public Customer build() { + return new Customer(id, name, email, createdAt); + } + } + + private static void validateStringNotBlank(String name) { + if(name == null || name.isBlank()) throw new IllegalArgumentException("빈 문자열 일 수 없습니다."); + } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index d6b4f0228c..1e1d0c5fb7 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -68,11 +68,14 @@ public Optional findById(UUID customerId) { } private Customer resultSetToCustomer(ResultSet resultSet) throws SQLException { - UUID customerId = bytesToUUID(resultSet.getBytes("customer_id")); - String customerName = resultSet.getString("name"); + UUID id = bytesToUUID(resultSet.getBytes("customer_id")); + String name = resultSet.getString("name"); String email = resultSet.getString("email"); LocalDateTime createdAt = resultSet.getTimestamp("created_at").toLocalDateTime(); - return new Customer(customerId, customerName, email, createdAt); + return new Customer.Builder(name, email) + .id(id) + .createdAt(createdAt) + .build(); } } diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index 47c66bc35d..ad95cc4ccd 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -39,7 +39,7 @@ void setUp() { // 사용자 생성 String name = "customer"; String email = "customer@gmail.com"; - Customer customer = new Customer(name, email); + Customer customer = createCustomer(name, email); Customer saved = customerRepository.insert(customer); @@ -56,13 +56,13 @@ void setUp() { // 사용자 생성 String name = "customer"; String email = "customer@gmail.com"; - Customer customer = new Customer(name, email); + Customer customer = createCustomer(name, email); customerRepository.insert(customer); // 이미 존재하는 이메일과 함께 생성 시도 String name2 = "customer2"; String sameEmail = "customer@gmail.com"; - Customer customer2 = new Customer(name2, sameEmail); + Customer customer2 = createCustomer(name2, sameEmail); // 에러 발생 assertThrows(DuplicateKeyException.class, @@ -72,8 +72,8 @@ void setUp() { @Test void 전체_사용자_목록_조회_성공() { // 사용자 생성 - Customer customer = new Customer("customer", "customer@gmail.com"); - Customer customer2 = new Customer("customer2", "customer2@gmail.com"); + Customer customer = createCustomer("customer", "customer@gmail.com"); + Customer customer2 = createCustomer("customer2", "customer2@gmail.com"); customerRepository.insert(customer); customerRepository.insert(customer2); @@ -89,7 +89,7 @@ void setUp() { // 사용자 생성 String name = "customer"; String email = "customer@gmail.com"; - Customer customer = new Customer(name, email); + Customer customer = createCustomer(name, email); customerRepository.insert(customer); // 사용자 아이디로 조회 @@ -98,4 +98,10 @@ void setUp() { // 저장한 사용자와 동일한 사용자 반환 Assertions.assertThat(found.getId()).isEqualTo(customer.getId()); } + + private Customer createCustomer(String name, String email) { + return new Customer + .Builder(name, email) + .build(); + } } \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 5956ae76ab..1fcc16fce8 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -85,7 +85,7 @@ void setUp() { void 쿠폰_소지자_아이디로_조회_성공() { // 쿠폰 소지자와 함께 1,000원 할인 쿠폰 생성 int discountAmount = 1_000; - Customer customer = new Customer("customer", "customer@gmail.com"); + Customer customer = createCustomer("customer", "customer@gmail.com"); customerRepository.insert(customer); Voucher voucher = new FixedAmountVoucher(discountAmount, customer.getId()); @@ -107,7 +107,7 @@ void setUp() { voucherRepository.save(voucher); // 쿠폰 소지자 할당 (쿠폰 정보 수정) - Customer customer = new Customer("customer", "customer@gmail.com"); + Customer customer = createCustomer("customer", "customer@gmail.com"); customerRepository.insert(customer); voucher.assigneOwner(customer.getId()); @@ -133,4 +133,10 @@ void setUp() { assertThat(vouchers).hasSize(0); } + private Customer createCustomer(String name, String email) { + return new Customer + .Builder(name, email) + .build(); + } + } \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java index ca4c6a04d2..b54b19068d 100644 --- a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -33,7 +33,7 @@ void setUp() { @Test void 사용자_ID로_조회() { // 사용자 등록 - Customer customer = new Customer("test", "test@gmail.com"); + Customer customer = createCustomer("test", "test@gmail.com"); customerRepository.insert(customer); // 사용자 조회 @@ -44,4 +44,10 @@ void setUp() { assertThat(found.getName()).isEqualTo(customer.getName()); assertThat(found.getEmail()).isEqualTo(customer.getEmail()); } + + private Customer createCustomer(String name, String email) { + return new Customer + .Builder(name, email) + .build(); + } } \ No newline at end of file From 0ba117e685d3f9980a6f14ef720596d300d755e6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Tue, 31 Oct 2023 23:25:25 +0900 Subject: [PATCH 088/134] =?UTF-8?q?test:=20Customer=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/customer/CustomerTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java diff --git a/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java b/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java new file mode 100644 index 0000000000..62995e36e9 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java @@ -0,0 +1,63 @@ +package team.marco.voucher_management_system.domain.customer; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class CustomerTest { + + @DisplayName("이름과 이메일로 사용자를 생성할 수 있다.") + @Test + void createCustomerByBuilder() { + // given + String name = "name"; + String email = "email@gmail.com"; + + // when + Customer customer = new Customer.Builder(name, email).build(); + + // then + assertThat(customer.getId()).isNotNull(); + assertThat(customer.getCreatedAt()).isNotNull(); + assertThat(customer) + .extracting("name", "email") + .contains(name, email); + } + + @DisplayName("사용자 ID는 중복되지 않는다.") + @Test + void createUniqueIdWhenUserCreate() { + // given // when + Customer customer1 = new Customer.Builder("name1", "email1@gmail.com").build(); + Customer customer2 = new Customer.Builder("name2", "email2@gmail.com").build(); + + // then + assertThat(customer1.getId()).isNotEqualTo(customer2.getId()); + } + + @DisplayName("사용자 이름은 빈칸 혹은 공백일 수 없다.") + @Test + void createCustomerWithBlankName() { + // given // when + String blankName = " "; + + // then when + assertThatThrownBy(() -> new Customer.Builder(blankName, "email1@gmail.com").build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("빈 문자열 일 수 없습니다."); + } + + @DisplayName("사용자 이메일은 빈칸 혹은 공백일 수 없다.") + @Test + void createCustomerWithBlankEmail() { + // given // when + String blankEmail = " "; + + // then when + assertThatThrownBy(() -> new Customer.Builder("name", blankEmail).build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("빈 문자열 일 수 없습니다."); + } +} \ No newline at end of file From 97cb580fc202318cdbf8a4d3ecd216872bbc2f77 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 06:31:14 +0900 Subject: [PATCH 089/134] =?UTF-8?q?refactor:=20Voucher=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EC=B6=94=EC=83=81=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/voucher/FixedAmountVoucher.java | 75 ---------- .../voucher/PercentDiscountVoucher.java | 75 ---------- .../domain/voucher/Voucher.java | 95 +++++++++++-- .../voucher/JdbcVoucherRepository.java | 106 ++++----------- .../voucher/JsonFileVoucherRepository.java | 39 +++--- .../repository/voucher/LoadedJsonVoucher.java | 63 --------- .../voucher/MemoryVoucherRepository.java | 24 ++-- .../repository/voucher/VoucherRepository.java | 11 +- src/main/resources/schema.sql | 26 ++-- .../domain/customer/CustomerTest.java | 2 +- .../voucher/FixedAmountVoucherTest.java | 91 ------------- .../voucher/PercentDiscountVoucherTest.java | 128 ------------------ .../domain/voucher/VoucherTest.java | 86 ++++++++++++ .../voucher/JdbcVoucherRepositoryTest.java | 75 +++------- .../voucher/MemoryVoucherRepositoryTest.java | 22 ++- 15 files changed, 265 insertions(+), 653 deletions(-) delete mode 100644 src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java delete mode 100644 src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java delete mode 100644 src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java delete mode 100644 src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java delete mode 100644 src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java create mode 100644 src/test/java/team/marco/voucher_management_system/domain/voucher/VoucherTest.java diff --git a/src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java deleted file mode 100644 index 6ef90b8748..0000000000 --- a/src/main/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucher.java +++ /dev/null @@ -1,75 +0,0 @@ -package team.marco.voucher_management_system.domain.voucher; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.MessageFormat; -import java.util.UUID; - -import static java.text.MessageFormat.format; -import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; - -public class FixedAmountVoucher extends Voucher { - private static final Logger logger = LoggerFactory.getLogger(FixedAmountVoucher.class); - private static final int MIN_AMOUNT = 100; - private static final int MAX_AMOUNT = 1_000_000; - - private final VoucherType type = FIXED; - private final int amount; - - public FixedAmountVoucher(int amount) { - validate(amount); - this.amount = amount; - - logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); - } - - public FixedAmountVoucher(UUID id, int amount) { - super(id); - validate(amount); - this.amount = amount; - - logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); - } - - public FixedAmountVoucher(int amount, UUID ownerId) { - validate(amount); - this.amount = amount; - - assigneOwner(ownerId); - - logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); - } - - public FixedAmountVoucher(UUID id, int amount, UUID ownerId) { - super(id, ownerId); - validate(amount); - this.amount = amount; - - logger.debug("Create FixedAmountVoucher {id: {}, amount: {}}", getId(), amount); - } - - private void validate(int amount) { - if (amount < MIN_AMOUNT || amount > MAX_AMOUNT) { - throw new IllegalArgumentException(format("{0}: 할인 금액은 {1}원 보다 작거나 {1}원 보다 클 수 없습니다.", amount, MIN_AMOUNT, MAX_AMOUNT)); - } - } - - @Override - public VoucherType getType() { - return type; - } - - public int getAmount() { - return amount; - } - - @Override - public String toString() { - return MessageFormat.format(""" - 쿠폰명: {0}원 할인 쿠폰 - 쿠폰번호: {1} - 쿠폰 소지자: {2} - """, amount, getId().toString(), getOwnerId() == null ? "없음" : getOwnerId().toString()); - } -} diff --git a/src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java deleted file mode 100644 index 5d2b90f3c2..0000000000 --- a/src/main/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucher.java +++ /dev/null @@ -1,75 +0,0 @@ -package team.marco.voucher_management_system.domain.voucher; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.text.MessageFormat; -import java.util.UUID; - -import static java.text.MessageFormat.format; -import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; - -public class PercentDiscountVoucher extends Voucher { - private static final Logger logger = LoggerFactory.getLogger(PercentDiscountVoucher.class); - private static final int MIN_PERCENT = 1; - private static final int MAX_PERCENT = 50; - - private final VoucherType type = PERCENT; - private final int percent; - - public PercentDiscountVoucher(int percent) { - validate(percent); - this.percent = percent; - - logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); - } - - public PercentDiscountVoucher(UUID id, int percent) { - super(id); - validate(percent); - this.percent = percent; - - logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); - } - - public PercentDiscountVoucher(int percent, UUID ownerId) { - validate(percent); - this.percent = percent; - - assigneOwner(ownerId); - - logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); - } - - public PercentDiscountVoucher(UUID id, Integer percent, UUID ownerId) { - super(id, ownerId); - validate(percent); - this.percent = percent; - - logger.info("Create PercentDiscountVoucher {id: {}, percent: {}}", getId(), percent); - } - - private void validate(int percent) { - if (percent <= MIN_PERCENT || percent >= MAX_PERCENT) { - throw new IllegalArgumentException(format("{0}: 할인율은 {1}% 보다 작거나 {2}% 보다 클 수 없습니다.", percent, MIN_PERCENT, MAX_PERCENT)); - } - } - - @Override - public VoucherType getType() { - return type; - } - - public int getPercent() { - return percent; - } - - @Override - public String toString() { - return MessageFormat.format(""" - 쿠폰명: {0}% 할인 쿠폰 - 쿠폰번호: {1} - 쿠폰 소지자: {2} - """, percent, getId().toString(), getOwnerId() == null ? "없음" : getOwnerId().toString()); - } -} diff --git a/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java index 955d83f37d..51f134cb29 100644 --- a/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java @@ -2,30 +2,97 @@ import java.util.UUID; -public abstract class Voucher { - private final UUID id; - private UUID ownerId; +import static java.text.MessageFormat.format; - public Voucher() { this.id = UUID.randomUUID(); } +public class Voucher { + private static final int MIN_AMOUNT = 1_000; + private static final int MAX_AMOUNT = 100_000; + private static final int MIN_PERCENT = 5; + private static final int MAX_PERCENT = 100; - public Voucher(UUID id) { + private final Long id; + private final UUID code; + private final VoucherType voucherType; + private final int discountValue; + private String name; + + private Voucher(Long id, UUID code, VoucherType voucherType, int discountValue, String name) { this.id = id; + this.code = code; + this.voucherType = voucherType; + this.discountValue = discountValue; + this.name = name; } - public Voucher(UUID id, UUID owner) { - this(id); - this.ownerId = owner; + public Long getId() { + return id; } - public UUID getId() { - return id; + public UUID getCode() { + return code; + } + + public VoucherType getVoucherType() { + return voucherType; + } + + public int getDiscountValue() { + return discountValue; } - public UUID getOwnerId() { return ownerId; } + public String getName() { + return name; + } + + public static class Builder { + private Long id; + private VoucherType voucherType; + private int discountValue; + private UUID code = UUID.randomUUID(); + private String name; + + public Builder(Long id, VoucherType voucherType, int discountValue) { + this.id = id; + this.voucherType = voucherType; + this.discountValue = discountValue; + switch (voucherType) { + case FIXED -> name = format("{0}원 할인 쿠폰", discountValue); + case PERCENT -> name = format("{0}% 할인 쿠폰", discountValue); + } + } + + public Builder code(UUID code) { + this.code = code; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Voucher build() { + switch (voucherType) { + case FIXED -> validateAmount(discountValue); + case PERCENT -> validatePercent(discountValue); + } + return new Voucher(id, code, voucherType, discountValue, name); + } - abstract public VoucherType getType(); + private void validateAmount(int amount) { + if(amount < MIN_AMOUNT || amount > MAX_AMOUNT) { + throw new IllegalArgumentException( + format("할인 금액은 {0}원 이상, {1}원 이하이어야 합니다.", MIN_AMOUNT, MAX_AMOUNT) + ); + } + } - public void assigneOwner(UUID ownerId) { - this.ownerId = ownerId; + private void validatePercent(int percent) { + if(percent < MIN_PERCENT || percent > MAX_PERCENT) { + throw new IllegalArgumentException( + format("할인 비율은 {0}% 이상, {1}% 이하이어야 합니다.", MIN_PERCENT, MAX_PERCENT) + ); + } + } } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index 6b5c309d95..03a87f3214 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -5,11 +5,8 @@ import org.springframework.context.annotation.Profile; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.domain.voucher.VoucherType; -import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import java.sql.ResultSet; import java.sql.SQLException; @@ -23,44 +20,29 @@ public class JdbcVoucherRepository implements VoucherRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcVoucherRepository.class); - private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, amount, percent, owner_id) VALUES (?, ?, ?, ?, ?)"; + private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, discount_value, code, name) VALUES (?, ?, ?, ?, ?)"; private static final String SELECT_ALL_SQL = "SELECT * FROM vouchers"; - private static final String SELECT_BY_OWNER_SQL = "SELECT * FROM vouchers WHERE owner_id = ?"; private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = ?"; - private static final String UPDATE_BY_ID_SQL = "UPDATE vouchers SET amount = ?, percent = ?, owner_id = ? WHERE voucher_id = ?"; private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = ?"; + private static final String SELECT_MAXIMUM_ID = "SELECT v.voucher_id From vouchers v ORDER BY voucher_id DESC LIMIT 1"; + private static final String SELECT_TOTAL_COUNTS = "SELECT count(*) From vouchers v"; private final JdbcTemplate jdbcTemplate; - private final CustomerRepository customerRepository; - public JdbcVoucherRepository(JdbcTemplate jdbcTemplate, CustomerRepository customerRepository) { + public JdbcVoucherRepository(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; - this.customerRepository = customerRepository; } @Override public Voucher save(Voucher voucher) { int update = 0; - switch (voucher.getType()) { - case FIXED -> { - FixedAmountVoucher amountVoucher = (FixedAmountVoucher) voucher; - update = jdbcTemplate.update(INSERT_SQL, - uuidToBytes(voucher.getId()), - voucher.getType().name(), - amountVoucher.getAmount(), - null, - voucher.getOwnerId() == null ? null : uuidToBytes(voucher.getOwnerId())); - } - case PERCENT -> { - PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; - update = jdbcTemplate.update(INSERT_SQL, - uuidToBytes(voucher.getId()), - voucher.getType().name(), - null, - percentVoucher.getPercent(), - voucher.getOwnerId() == null ? null : uuidToBytes(voucher.getOwnerId())); - } - } + + update = jdbcTemplate.update(INSERT_SQL, + voucher.getId(), + voucher.getVoucherType().name(), + voucher.getDiscountValue(), + uuidToBytes(voucher.getCode()), + voucher.getName()); if(update != 1) { logger.error("쿠폰을 추가하는 과정에서 오류가 발생했습니다."); @@ -80,65 +62,35 @@ public List findAll() { } @Override - public List findByOwner(UUID ownerId) { - List vouchers = new ArrayList<>(); - jdbcTemplate.query(SELECT_BY_OWNER_SQL - , (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet)) - , uuidToBytes(ownerId)); - - return Collections.unmodifiableList(vouchers); - } - - @Override - public Optional findById(UUID voucherId) { + public Optional findById(Long voucherId) { return Optional.of(jdbcTemplate.queryForObject(SELECT_BY_ID_SQL , (resultSet, rowNum) -> resultSetToVoucher(resultSet) - , uuidToBytes(voucherId))); + , voucherId)); } @Override - public Voucher update(Voucher voucher) { - int update = 0; - switch (voucher.getType()) { - case FIXED -> { - FixedAmountVoucher amountVoucher = (FixedAmountVoucher) voucher; - update = jdbcTemplate.update(UPDATE_BY_ID_SQL, - amountVoucher.getAmount(), - null, - amountVoucher.getOwnerId() != null ? uuidToBytes(amountVoucher.getOwnerId()) : null, - uuidToBytes(voucher.getId())); - } - case PERCENT -> { - PercentDiscountVoucher percentVoucher = (PercentDiscountVoucher) voucher; - update = jdbcTemplate.update(UPDATE_BY_ID_SQL, - null, - percentVoucher.getPercent(), - percentVoucher.getOwnerId() != null ? uuidToBytes(percentVoucher.getOwnerId()) : null, - uuidToBytes(voucher.getId())); - } - } - - if(update != 1) { - logger.error("쿠폰을 변경하는 과정에서 오류가 발생했습니다."); - throw new RuntimeException("쿠폰을 변경하는 과정에서 오류가 발생했습니다."); - } - - return voucher; + public void deleteById(Long voucherId) { + jdbcTemplate.update(DELETE_BY_ID_SQL, voucherId); } @Override - public void deleteById(UUID voucherId) { - jdbcTemplate.update(DELETE_BY_ID_SQL, uuidToBytes(voucherId)); + public Optional findLatestVoucherId() { + Long size = jdbcTemplate.queryForObject(SELECT_TOTAL_COUNTS, Long.class); + if(size == 0) return Optional.empty(); + + return Optional.of(jdbcTemplate.queryForObject(SELECT_MAXIMUM_ID, Long.class)); } private Voucher resultSetToVoucher(ResultSet resultSet) throws SQLException { - UUID voucherId = bytesToUUID(resultSet.getBytes("voucher_id")); + Long voucherId = resultSet.getLong("voucher_id"); VoucherType voucherType = VoucherType.valueOf(resultSet.getString("voucher_type")); - Integer amount = resultSet.getInt("amount"); - Integer percent = resultSet.getInt("percent"); - UUID ownerId = bytesToUUID(resultSet.getBytes("owner_id")); - - LoadedJsonVoucher jsonVoucher = new LoadedJsonVoucher(voucherId, voucherType, amount, percent, ownerId); - return jsonVoucher.jsonVoucherToVoucher(); + int discountValue = resultSet.getInt("discount_value"); + UUID code = bytesToUUID(resultSet.getBytes("code")); + String name = resultSet.getString("name"); + + return new Voucher.Builder(voucherId, voucherType, discountValue) + .code(code) + .name(name) + .build(); } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java index 75d8f1c31a..8462f7cd93 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java @@ -11,16 +11,16 @@ import java.io.File; import java.io.IOException; import java.io.UncheckedIOException; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @Profile("dev") @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { - private final Map voucherMap; + private final Map voucherMap; private final ObjectMapper objectMapper; private final File file; @@ -31,22 +31,22 @@ public JsonFileVoucherRepository(@Value("${file.path.voucher_data}") String path voucherMap = loadVoucherMap(); } - private Map loadVoucherMap() { - Map loadedVouchers = new ConcurrentHashMap<>(); + private Map loadVoucherMap() { + Map loadedVouchers = new ConcurrentHashMap<>(); if (!file.exists()) { return loadedVouchers; } - ObjectReader objectReader = objectMapper.readerForListOf(LoadedJsonVoucher.class); - List jsonVouchers; + ObjectReader objectReader = objectMapper.readerForListOf(Voucher.class); + List vouchers; try { - jsonVouchers = objectReader.readValue(file); + vouchers = objectReader.readValue(file); } catch (IOException e) { throw new UncheckedIOException(e); } - jsonVouchers.forEach(data -> loadedVouchers.put(data.getId(), data.jsonVoucherToVoucher())); + vouchers.forEach(voucher -> loadedVouchers.put(voucher.getId(), voucher)); return loadedVouchers; } @@ -65,35 +65,28 @@ public List findAll() { } @Override - public List findByOwner(UUID ownerId) { - return voucherMap.values().stream() - .filter(v -> v.getOwnerId() == ownerId) - .toList(); - } - - @Override - public Optional findById(UUID voucherId) { + public Optional findById(Long voucherId) { if(voucherMap.containsKey(voucherId)) { return Optional.of(voucherMap.get(voucherId)); } else return Optional.empty(); } @Override - public Voucher update(Voucher voucher) { - voucherMap.put(voucher.getId(), voucher); - - return voucher; + public void deleteById(Long voucherId) { + voucherMap.remove(voucherId); } @Override - public void deleteById(UUID voucherId) { - voucherMap.remove(voucherId); + public Optional findLatestVoucherId() { + return voucherMap.keySet().stream() + .max(Comparator.naturalOrder()); } @Override public void destroy() { try { - objectMapper.writeValue(file, voucherMap.values()); + List vouchers = voucherMap.values().stream().toList(); + objectMapper.writeValue(file, vouchers); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java deleted file mode 100644 index 9120499d8a..0000000000 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/LoadedJsonVoucher.java +++ /dev/null @@ -1,63 +0,0 @@ -package team.marco.voucher_management_system.repository.voucher; - -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; -import team.marco.voucher_management_system.domain.voucher.Voucher; -import team.marco.voucher_management_system.domain.voucher.VoucherType; - -import java.util.UUID; - -public class LoadedJsonVoucher { - private final UUID id; - private final VoucherType type; - private final Integer amount; - private final Integer percent; - private final UUID ownerId; - - public LoadedJsonVoucher(UUID id, VoucherType type, Integer amount, Integer percent, UUID ownerId) { - this.id = id; - this.type = type; - this.amount = amount; - this.percent = percent; - this.ownerId = ownerId; - } - - public UUID getId() { - return id; - } - - public VoucherType getType() { - return type; - } - - public Integer getAmount() { - return amount; - } - - public Integer getPercent() { - return percent; - } - - public UUID getOwnerId() { - return ownerId; - } - - public Voucher jsonVoucherToVoucher() { - return switch (type) { - case FIXED -> { - if(ownerId == null) { - yield new FixedAmountVoucher(id, amount); - } else { - yield new FixedAmountVoucher(id, amount, ownerId); - } - } - case PERCENT -> { - if (ownerId == null) { - yield new PercentDiscountVoucher(id, percent); - } else { - yield new PercentDiscountVoucher(id, percent, ownerId); - } - } - }; - } -} diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java index 82da67fba4..5c8a170921 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java @@ -4,16 +4,16 @@ import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @Profile({"local", "debug"}) @Repository public class MemoryVoucherRepository implements VoucherRepository { - private final Map voucherMap = new ConcurrentHashMap<>(); + private final Map voucherMap = new ConcurrentHashMap<>(); @Override public Voucher save(Voucher voucher) { @@ -29,28 +29,20 @@ public List findAll() { } @Override - public List findByOwner(UUID ownerId) { - return voucherMap.values().stream() - .filter(v -> v.getOwnerId() == ownerId) - .toList(); - } - - @Override - public Optional findById(UUID voucherId) { + public Optional findById(Long voucherId) { if(voucherMap.containsKey(voucherId)) { return Optional.of(voucherMap.get(voucherId)); } else return Optional.empty(); } @Override - public Voucher update(Voucher voucher) { - voucherMap.put(voucher.getId(), voucher); - - return voucher; + public void deleteById(Long voucherId) { + voucherMap.remove(voucherId); } @Override - public void deleteById(UUID voucherId) { - voucherMap.remove(voucherId); + public Optional findLatestVoucherId() { + return voucherMap.keySet().stream() + .max(Comparator.naturalOrder()); } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java index f76169b540..c5d7901d7e 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java @@ -4,20 +4,15 @@ import java.util.List; import java.util.Optional; -import java.util.UUID; public interface VoucherRepository { Voucher save(Voucher voucher); List findAll(); - List findByOwner(UUID ownerId); - - Optional findById(UUID voucherId); - - Voucher update(Voucher voucher); - - void deleteById(UUID voucherId); + Optional findById(Long voucherId); + void deleteById(Long voucherId); + Optional findLatestVoucherId(); } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index fc2daee0c3..5fd271ad4b 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -1,15 +1,9 @@ -SHOW DATABASES; - -# voucher_mgmt_system 데이터 베이스가 없다면 실행 -CREATE DATABASE voucher_mgmt_system; +CREATE DATABASE IF NOT EXISTS voucher_mgmt_system; USE voucher_mgmt_system; -SHOW tables; - -# vouchers, customers 테이블이 존재한다면 실행 -DROP TABLE vouchers; -DROP TABLE customers; +DROP TABLE IF EXISTS vouchers; +DROP TABLE IF EXISTS customers; CREATE TABLE customers ( customer_id BINARY(16) NOT NULL, @@ -26,15 +20,13 @@ INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), ' INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '이세희', '이세희@gmail.com'); CREATE TABLE `vouchers` ( - voucher_id BINARY(16) NOT NULL, - voucher_type ENUM('FIXED','PERCENT') DEFAULT NULL, - amount INTEGER DEFAULT NULL, - percent INTEGER DEFAULT NULL, - owner_id BINARY(16) DEFAULT NULL, + voucher_id BIGINT NOT NULL, + voucher_type ENUM('FIXED','PERCENT') NOT NULL, + discount_value INTEGER NOT NULL, + code BINARY(16) NOT NULL, + name VARCHAR(50) DEFAULT NULL, CONSTRAINT pk_voucher_id PRIMARY KEY (voucher_id), - CONSTRAINT `fk_owner_id` FOREIGN KEY (owner_id) REFERENCES customers (customer_id), - CONSTRAINT `chk_amount` CHECK (((amount >= 100) and (amount <= 1000000))), - CONSTRAINT `chk_percent` CHECK (((percent > 0) and (percent <= 50))) + CONSTRAINT unq_code UNIQUE KEY (code) ); diff --git a/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java b/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java index 62995e36e9..7bb8dd6302 100644 --- a/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java +++ b/src/test/java/team/marco/voucher_management_system/domain/customer/CustomerTest.java @@ -8,7 +8,7 @@ class CustomerTest { - @DisplayName("이름과 이메일로 사용자를 생성할 수 있다.") + @DisplayName("필수값(이름, 이메일)만으로 사용자를 생성할 수 있다.") @Test void createCustomerByBuilder() { // given diff --git a/src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java deleted file mode 100644 index 790d7113ae..0000000000 --- a/src/test/java/team/marco/voucher_management_system/domain/voucher/FixedAmountVoucherTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package team.marco.voucher_management_system.domain.voucher; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class FixedAmountVoucherTest { - - @Test - void 고정금액_할인쿠폰_생성_성공() { - // 10,000원 할인 쿠폰 생성 - int discountAmount = 10_000; - FixedAmountVoucher voucher = new FixedAmountVoucher(discountAmount); - - // 1. UUID가 자동으로 할당 - assertThat(voucher.getId()).isNotNull(); - // 2. VoucherType은 자동으로 FIXED - assertThat(voucher.getType()).isEqualTo(VoucherType.FIXED); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getAmount()).isEqualTo(discountAmount); - } - - @Test - @DisplayName("UUID 값와 함께 할인 쿠폰 생성 가능") - void 고정비율_할인쿠폰_생성_성공_2() { - // 특정 UUID 값을 가진 10,000원 할인 쿠폰 생성 - UUID voucherId = UUID.randomUUID(); - int discountAmount = 10_000; - FixedAmountVoucher voucher = new FixedAmountVoucher(voucherId, discountAmount); - - // 1. 입력한 UUID로 생성 - assertThat(voucher.getId()).isEqualTo(voucherId); - // 2. VoucherType은 자동으로 FIXED - assertThat(voucher.getType()).isEqualTo(VoucherType.FIXED); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getAmount()).isEqualTo(discountAmount); - } - - @Test - @DisplayName("할인 금액은 100원보다 작을 수 없다.") - void 고정금액_할인쿠폰_생성_실패() { - // 1. 유효하지 않은 할인 금액 - int invalidAmount = 10; - // 2. 유효한 할인 금액 (엣지포인트) - int validAmount = 100; - - // 1. 10원 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new FixedAmountVoucher(invalidAmount); - }); - - // 2. 100원 할인 쿠폰 생성 시 에러 발생 X - assertDoesNotThrow(() -> { new FixedAmountVoucher(validAmount); }); - } - - @Test - @DisplayName("할인 금액은 100만원보다 클 수 없다.") - void 고정금액_할인쿠폰_생성_실패_2() { - // 1. 유효하지 않은 할인 금액 - int invalidAmount = 1_000_010; - // 2. 유효한 할인 금액 (엣지포인트) - int validAmount = 1_000_000; - - // 1. 100,010원 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new FixedAmountVoucher(invalidAmount); - }); - - // 2. 100,000원 할인 쿠폰 생성 시 에러 발생 X - assertDoesNotThrow(() -> { new FixedAmountVoucher(validAmount); }); - } - - @Test - @DisplayName("UUID와 할인 금액으로 쿠폰을 생성하는 경우에도 유효성 검사 실행") - void 고정비율_할인쿠폰_생성_실패_4() { - // UUID + 유효하지 않은 할인 비율 - UUID voucherId = UUID.randomUUID(); - int invalidAmount = -100; - - // 마이너스(-) 금액 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new PercentDiscountVoucher(voucherId, invalidAmount); - }); - } - -} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java b/src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java deleted file mode 100644 index e8d2816dab..0000000000 --- a/src/test/java/team/marco/voucher_management_system/domain/voucher/PercentDiscountVoucherTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package team.marco.voucher_management_system.domain.voucher; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class PercentDiscountVoucherTest { - @Test - @DisplayName("[할인 비율]로 할인 쿠폰을 생성할 수 있다.") - void 고정비율_할인쿠폰_생성_성공() { - // 20% 할인 쿠폰 생성 - int discountPercent = 20; - PercentDiscountVoucher voucher = new PercentDiscountVoucher(discountPercent); - - // 1. UUID가 자동으로 할당 - assertThat(voucher.getId()).isNotNull(); - // 2. VoucherType은 자동으로 PERCENT - assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getPercent()).isEqualTo(discountPercent); - } - - @Test - @DisplayName("[쿠폰 UUID, 할인 비율]로 할인 쿠폰 생성 가능") - void 고정비율_할인쿠폰_생성_성공_2() { - // 특정 UUID 값을 가진 20% 할인 쿠폰 생성 - UUID voucherId = UUID.randomUUID(); - int discountPercent = 20; - PercentDiscountVoucher voucher = new PercentDiscountVoucher(voucherId, discountPercent); - - // 1. 입력한 UUID로 생성 - assertThat(voucher.getId()).isEqualTo(voucherId); - // 2. VoucherType은 자동으로 PERCENT - assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getPercent()).isEqualTo(discountPercent); - } - - @Test - @DisplayName("[할인 비율, 쿠폰 소지자 UUID]로 할인 쿠폰 생성 가능") - void 고정비율_할인쿠폰_생성_성공_3() { - // 특정 UUID 값을 가진 20% 할인 쿠폰 생성 + 쿠폰 소유자 - UUID voucherId = UUID.randomUUID(); - int discountPercent = 20; - UUID ownerId = UUID.randomUUID(); - PercentDiscountVoucher voucher = new PercentDiscountVoucher(voucherId, discountPercent, ownerId); - - // 1. 입력한 UUID가 할당 - assertThat(voucher.getId()).isEqualTo(voucherId); - // 2. VoucherType은 자동으로 PERCENT - assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getPercent()).isEqualTo(discountPercent); - // 4. 입력한 쿠폰 소지자 할당 - assertThat(voucher.getOwnerId()).isEqualTo(ownerId); - } - - @Test - @DisplayName("[쿠폰 UUID, 할인 비율, 쿠폰 소지자 UUID]로 할인 쿠폰 생성 가능") - void 고정비율_할인쿠폰_생성_성공_4() { - // 쿠폰 소유자와 함께 20% 할인 쿠폰 생성 - int discountPercent = 20; - UUID ownerId = UUID.randomUUID(); - PercentDiscountVoucher voucher = new PercentDiscountVoucher(discountPercent, ownerId); - - // 1. UUID가 자동으로 할당 - assertThat(voucher.getId()).isNotNull(); - // 2. VoucherType은 자동으로 PERCENT - assertThat(voucher.getType()).isEqualTo(VoucherType.PERCENT); - // 3. 입력한 비율만큼 할인 - assertThat(voucher.getPercent()).isEqualTo(discountPercent); - // 4. 입력한 쿠폰 소지자 할당 - assertThat(voucher.getOwnerId()).isEqualTo(ownerId); - } - - @Test - @DisplayName("할인 비율은 0%일 수 없다.") - void 고정비율_할인쿠폰_생성_실패() { - // 유효하지 않은 할인 비율 - int zeroPercent = 0; - - // 0% 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new PercentDiscountVoucher(zeroPercent); - }); - } - - @Test - @DisplayName("할인 비율은 마이너스(-)일 수 없다.") - void 고정비율_할인쿠폰_생성_실패_2() { - // 유효하지 않은 할인 비율 - int minusPercent = -10; - - // -10% 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new PercentDiscountVoucher(minusPercent); - }); - } - - @Test - @DisplayName("할인 비율은 50%를 넘을 수 없다.") - void 고정비율_할인쿠폰_생성_실패_3() { - // 유효하지 않은 할인 비율 - int highPercent = 90; - - // 할인 비율이 50%가 넘는 할인 쿠폰 생성 시 에러 발생 - assertThrows(IllegalArgumentException.class, () -> { - new PercentDiscountVoucher(highPercent); - }); - } - - @Test - @DisplayName("UUID와 할인 비율로 쿠폰을 생성하는 경우에도 유효성 검사 실행") - void 고정비율_할인쿠폰_생성_실패_4() { - // UUID + 유효하지 않은 할인 비율 - UUID voucherId = UUID.randomUUID(); - int highPercent = 90; - - // 할인 비율이 50%가 넘는 할인 쿠폰 생성 시 에러 발생 2 - assertThrows(IllegalArgumentException.class, () -> { - new PercentDiscountVoucher(voucherId, highPercent); - }); - } -} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/domain/voucher/VoucherTest.java b/src/test/java/team/marco/voucher_management_system/domain/voucher/VoucherTest.java new file mode 100644 index 0000000000..dd945b452c --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/domain/voucher/VoucherTest.java @@ -0,0 +1,86 @@ +package team.marco.voucher_management_system.domain.voucher; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; + +class VoucherTest { + + @DisplayName("필수값만(아이디, 쿠폰 종류, 할인값)으로 쿠폰을 생성할 수 있다.") + @Test + void createVoucherByBuilder() { + // given + Long id = 1L; + VoucherType voucherType = FIXED; + int discountValue = 10_000; + + // when + Voucher voucher = new Voucher.Builder(id, voucherType, discountValue).build(); + + // then + assertThat(voucher) + .extracting("id", "voucherType", "discountValue") + .contains(id, voucherType, discountValue); + assertThat(voucher.getCode()).isNotNull(); + assertThat(voucher.getName()).isEqualTo("10,000원 할인 쿠폰"); + } + + @DisplayName("고정 금액 쿠폰은 1,000원이상 할인해야 합니다.") + @Test + void createFixedVoucherWithMinValue() { + // given + int lessAmount = 990; + int minAmount = 1_000; + + // when then + assertThatNoException().isThrownBy(() -> new Voucher.Builder(1L, FIXED, minAmount).build()); + assertThatThrownBy(() -> new Voucher.Builder(2L, FIXED, lessAmount).build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("할인 금액은 1,000원 이상, 100,000원 이하이어야 합니다."); + } + + @DisplayName("고정 금액 쿠폰은 10만원이하로 할인해야 합니다.") + @Test + void createFixedVoucherWithMaxValue() { + // given + int tooMuchAmount = 1000_010; + int maxAmount = 100_000; + + // when then + assertThatNoException().isThrownBy(() -> new Voucher.Builder(1L, FIXED, maxAmount).build()); + assertThatThrownBy(() -> new Voucher.Builder(2L, FIXED, tooMuchAmount).build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("할인 금액은 1,000원 이상, 100,000원 이하이어야 합니다."); + } + + @DisplayName("% 할인 쿠폰은 5% 이상 할인해야 합니다.") + @Test + void createPercentVoucherWithMinValue() { + // given + int lessPercent = 4; + int minPercent = 5; + + // when then + assertThatNoException().isThrownBy(() -> new Voucher.Builder(1L, PERCENT, minPercent).build()); + assertThatThrownBy(() -> new Voucher.Builder(2L, PERCENT, lessPercent).build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("할인 비율은 5% 이상, 100% 이하이어야 합니다."); + } + + @DisplayName("% 할인 쿠폰은 100% 이하로 할인해야 합니다.") + @Test + void createPercentVoucherWithMaxValue() { + // given + int tooMuchPercent = 101; + int maxPercent = 100; + + // when then + assertThatNoException().isThrownBy(() -> new Voucher.Builder(1L, PERCENT, maxPercent).build()); + assertThatThrownBy(() -> new Voucher.Builder(2L, PERCENT, tooMuchPercent).build()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("할인 비율은 5% 이상, 100% 이하이어야 합니다."); + } +} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 1fcc16fce8..7bdb70b103 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -8,15 +8,13 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.domain.customer.Customer; -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; import team.marco.voucher_management_system.domain.voucher.Voucher; -import team.marco.voucher_management_system.repository.custromer.JdbcCustomerRepository; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; @Transactional @SpringBootTest @@ -25,9 +23,6 @@ class JdbcVoucherRepositoryTest { @Autowired private JdbcVoucherRepository voucherRepository; - @Autowired - private JdbcCustomerRepository customerRepository; - @Autowired private JdbcTemplate jdbcTemplate; @@ -41,8 +36,8 @@ void setUp() { @DisplayName("바우처 생성 시 생성된 바우처를 반환") void 쿠폰_생성_성공() { // 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); Voucher saved = voucherRepository.save(voucher); // 생성된 바우처 반환 @@ -52,12 +47,12 @@ void setUp() { @Test void 전체_쿠폰_목록_조회_성공() { // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); voucherRepository.save(voucher); - int discountPercent = 10; - Voucher voucher2 = new PercentDiscountVoucher(discountPercent); + int percent = 10; + Voucher voucher2 = createPercentVoucher(2L, percent); voucherRepository.save(voucher2); // 전체 쿠폰 목록 조회 @@ -70,8 +65,8 @@ void setUp() { @Test void 쿠폰_아이디로_조회_성공() { // 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); voucherRepository.save(voucher); // 쿠폰 번호로 조회 @@ -81,48 +76,11 @@ void setUp() { assertThat(found.getId()).isEqualTo(voucher.getId()); } - @Test - void 쿠폰_소지자_아이디로_조회_성공() { - // 쿠폰 소지자와 함께 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Customer customer = createCustomer("customer", "customer@gmail.com"); - customerRepository.insert(customer); - - Voucher voucher = new FixedAmountVoucher(discountAmount, customer.getId()); - voucherRepository.save(voucher); - - // 쿠폰 소지자 아이디로 조회 - List found = voucherRepository.findByOwner(customer.getId()); - - // 저장한 쿠폰과 동일한 쿠폰 반환 - assertThat(found).hasSize(1); - assertThat(found.get(0).getId()).isEqualTo(voucher.getId()); - } - - @Test - void 쿠폰_정보_수정_성공() { - // 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); - voucherRepository.save(voucher); - - // 쿠폰 소지자 할당 (쿠폰 정보 수정) - Customer customer = createCustomer("customer", "customer@gmail.com"); - customerRepository.insert(customer); - voucher.assigneOwner(customer.getId()); - - Voucher updated = voucherRepository.update(voucher); - - // 변경된 쿠폰 정보가 저장 - assertThat(updated.getId()).isEqualTo(voucher.getId()); - assertThat(updated.getOwnerId()).isEqualTo(customer.getId()); - } - @Test void 쿠폰_번호로_삭제_성공() { // 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); voucherRepository.save(voucher); // 쿠폰 삭제 @@ -133,10 +91,11 @@ void setUp() { assertThat(vouchers).hasSize(0); } - private Customer createCustomer(String name, String email) { - return new Customer - .Builder(name, email) - .build(); + private static Voucher createFixedVoucher(Long id, int amount) { + return new Voucher.Builder(id, FIXED, amount).build(); } + private static Voucher createPercentVoucher(Long id, int percent) { + return new Voucher.Builder(id, PERCENT, percent).build(); + } } \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java index ee668dfafc..2f6df355d4 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java @@ -4,13 +4,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; class MemoryVoucherRepositoryTest { private MemoryVoucherRepository voucherRepository; @@ -24,8 +24,8 @@ void setUp() { @DisplayName("바우처 생성 시 생성된 바우처를 반환") void 쿠폰_생성_성공() { // 1,000원 할인 쿠폰 생성 - int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); Voucher saved = voucherRepository.save(voucher); // 생성된 바우처 반환 @@ -36,11 +36,11 @@ void setUp() { void 전체_쿠폰_목록_조회_성공() { // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 int discountAmount = 1_000; - Voucher voucher = new FixedAmountVoucher(discountAmount); + Voucher voucher = createFixedVoucher(1L, discountAmount); voucherRepository.save(voucher); - int discountPercent = 10; - Voucher voucher2 = new PercentDiscountVoucher(discountPercent); + int percent = 10; + Voucher voucher2 = createPercentVoucher(2L, percent); voucherRepository.save(voucher2); // 전체 쿠폰 목록 조회 @@ -49,4 +49,12 @@ void setUp() { // 저장된 2개의 쿠폰이 조회 assertThat(vouchers).hasSize(2); } + + private static Voucher createFixedVoucher(Long id, int amount) { + return new Voucher.Builder(id, FIXED, amount).build(); + } + + private static Voucher createPercentVoucher(Long id, int percent) { + return new Voucher.Builder(id, PERCENT, percent).build(); + } } \ No newline at end of file From e9ec74301df51307a50d2da0aebb8f930afa6e2c Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 06:32:34 +0900 Subject: [PATCH 090/134] =?UTF-8?q?refactor:=20controller,=20service=20?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=EC=96=B4=EC=97=90=20Dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/VoucherController.java | 23 +---- .../voucher/VoucherCreateRequest.java | 33 +++++++ .../voucher/VoucherCreateServiceRequest.java | 36 +++++++ .../service/voucher/VoucherService.java | 35 ++----- .../service/VoucherServiceTest.java | 95 +++++++++---------- 5 files changed, 127 insertions(+), 95 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java create mode 100644 src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java index d23a2a3ea9..9c9c20f110 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java @@ -4,7 +4,6 @@ import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; -import java.util.UUID; @Controller public class VoucherController { @@ -14,16 +13,12 @@ public VoucherController(VoucherService voucherService) { this.voucherService = voucherService; } - public void createFixedAmountVoucher(int amount) { - voucherService.createFixedAmountVoucher(amount); - } - - public void createPercentDiscountVoucher(int percent) { - voucherService.createPercentDiscountVoucher(percent); + public void createVoucher(VoucherCreateRequest request) { + voucherService.createVoucher(request.toServiceRequest()); } public String getVoucherInfo(String voucherId) { - return voucherService.getVoucher(UUID.fromString(voucherId)).toString(); + return voucherService.getVoucher(Long.valueOf(voucherId)).toString(); } public List getVouchersInfo() { @@ -32,17 +27,7 @@ public List getVouchersInfo() { .toList(); } - public List getVouchersInfo(String customerId) { - return voucherService.getVouchers(UUID.fromString(customerId)).stream() - .map(Object::toString) - .toList(); - } - - public void assignVoucherOwner(String voucherId, String customerId) { - voucherService.assignVoucherOwner(UUID.fromString(voucherId), UUID.fromString(customerId)); - } - public void deleteVoucher(String voucherId) { - voucherService.deleteVoucher(UUID.fromString(voucherId)); + voucherService.deleteVoucher(Long.valueOf(voucherId)); } } diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java new file mode 100644 index 0000000000..6caf4934fa --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.controller.voucher; + +import team.marco.voucher_management_system.domain.voucher.VoucherType; +import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; + +import java.util.Optional; + +public class VoucherCreateRequest { + private VoucherType voucherType; + private int discountValue; + + public VoucherCreateRequest(VoucherType voucherType, int discountValue) { + this.voucherType = voucherType; + this.discountValue = discountValue; + } + + public VoucherCreateServiceRequest toServiceRequest() { + return new VoucherCreateServiceRequest( + voucherType, + discountValue, + Optional.empty(), + Optional.empty() + ); + } + + public VoucherType getVoucherType() { + return voucherType; + } + + public int getDiscountValue() { + return discountValue; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java new file mode 100644 index 0000000000..d6ed6660a0 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java @@ -0,0 +1,36 @@ +package team.marco.voucher_management_system.service.voucher; + +import team.marco.voucher_management_system.domain.voucher.VoucherType; + +import java.util.Optional; +import java.util.UUID; + +public class VoucherCreateServiceRequest { + private VoucherType voucherType; + private int discountValue; + private Optional code; + private Optional name; + + public VoucherCreateServiceRequest(VoucherType voucherType, int discountValue, Optional code, Optional name) { + this.voucherType = voucherType; + this.discountValue = discountValue; + this.code = code; + this.name = name; + } + + public VoucherType getVoucherType() { + return voucherType; + } + + public int getDiscountValue() { + return discountValue; + } + + public Optional getCode() { + return code; + } + + public Optional getName() { + return name; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index 5ae11e3a28..5b1fc208c1 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -4,13 +4,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import java.util.List; -import java.util.UUID; @Service public class VoucherService { @@ -23,14 +20,14 @@ public VoucherService(VoucherRepository voucherRepository) { } @Transactional - public Voucher createFixedAmountVoucher(int amount) { - Voucher voucher = new FixedAmountVoucher(amount); - return voucherRepository.save(voucher); - } + public Voucher createVoucher(VoucherCreateServiceRequest request) { + Long id = voucherRepository.findLatestVoucherId().orElse(1L); + + Voucher.Builder builder = new Voucher.Builder(id, request.getVoucherType(), request.getDiscountValue()); + request.getCode().ifPresent(code -> builder.code(code)); + request.getName().ifPresent(name -> builder.name(name)); + Voucher voucher = builder.build(); - @Transactional - public Voucher createPercentDiscountVoucher(int percent) { - Voucher voucher = new PercentDiscountVoucher(percent); return voucherRepository.save(voucher); } @@ -38,25 +35,11 @@ public List getVouchers() { return voucherRepository.findAll(); } - public List getVouchers(UUID customerId) { - return voucherRepository.findByOwner(customerId); - } - - @Transactional - public Voucher assignVoucherOwner(UUID voucherId, UUID customerId) { - logger.debug("[VoucherService] Call assignVoucherOwner()"); - - Voucher voucher = voucherRepository.findById(voucherId).orElseThrow(); - voucher.assigneOwner(customerId); - - return voucherRepository.update(voucher); - } - - public Voucher getVoucher(UUID voucherId) { + public Voucher getVoucher(Long voucherId) { return voucherRepository.findById(voucherId).orElseThrow(); } - public void deleteVoucher(UUID voucherId) { + public void deleteVoucher(Long voucherId) { voucherRepository.deleteById(voucherId); } } diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index ff44651003..1cf59d72f7 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -3,17 +3,19 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.voucher_management_system.domain.voucher.FixedAmountVoucher; -import team.marco.voucher_management_system.domain.voucher.PercentDiscountVoucher; +import team.marco.voucher_management_system.controller.voucher.VoucherCreateRequest; import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; +import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; -import java.util.UUID; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; class VoucherServiceTest { private VoucherService voucherService; @@ -30,37 +32,47 @@ class VoucherServiceTest { void 고정_할인_쿠폰_생성() { // 할인 금액이 주어 졌을 때 int amount = 1000; + VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( + FIXED, + amount, + Optional.empty(), + Optional.empty() + ); // 고정 금액 쿠폰 생성 요청 - Voucher returned = voucherService.createFixedAmountVoucher(amount); + Voucher returned = voucherService.createVoucher(request); // 1. 생성된 쿠폰이 FixedAmountVoucher 타입 - assertThat(returned).isInstanceOf(FixedAmountVoucher.class); + assertThat(returned.getVoucherType()).isEqualTo(FIXED); // 2. 생성된 쿠폰의 할인 금액이 amount와 동일 - FixedAmountVoucher voucher = (FixedAmountVoucher) returned; - assertThat(voucher.getAmount()).isEqualTo(amount); + assertThat(returned.getDiscountValue()).isEqualTo(amount); } @Test void 퍼센트_할인_쿠폰_생성() { // 할인율이 주어 졌을 때 int percent = 10; + VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( + PERCENT, + percent, + Optional.empty(), + Optional.empty() + ); // % 금액 쿠폰 생성 요청 - Voucher returned = voucherService.createPercentDiscountVoucher(percent); + Voucher returned = voucherService.createVoucher(request); // 1. 생성된 쿠폰이 PercentDiscountVoucher 타입 - assertThat(returned).isInstanceOf(PercentDiscountVoucher.class); + assertThat(returned.getVoucherType()).isEqualTo(PERCENT); // 2. 생성된 쿠폰의 할인율이 percent와 동일 - PercentDiscountVoucher voucher = (PercentDiscountVoucher) returned; - assertThat(voucher.getPercent()).isEqualTo(percent); + assertThat(returned.getDiscountValue()).isEqualTo(percent); } @Test void 전체_쿠폰_목록_조회() { // 리포지토리에 쿠폰 2개가 저장되어 있을 때 - Voucher voucher = new FixedAmountVoucher(1000); - Voucher voucher2 = new PercentDiscountVoucher(10); + Voucher voucher = createFixedVoucher(1L, 1000); + Voucher voucher2 = createPercentVoucher(2L,10); voucherRepository.save(voucher); voucherRepository.save(voucher2); @@ -74,8 +86,8 @@ class VoucherServiceTest { @Test void 쿠폰_목록_조회() { // 리포지토리에 쿠폰 2개가 저장되어 있을 때 - Voucher voucher = new FixedAmountVoucher(1000); - Voucher voucher2 = new PercentDiscountVoucher(10); + Voucher voucher = createFixedVoucher(1L, 1000); + Voucher voucher2 = createPercentVoucher(2L, 10); voucherRepository.save(voucher); voucherRepository.save(voucher2); @@ -86,43 +98,10 @@ class VoucherServiceTest { assertThat(returned).hasSize(2); } - @Test - void 특정_사용자의_쿠폰_목록_조회() { - // 쿠폰 소지자가 존재하는 쿠폰 저장 - UUID customerId = UUID.randomUUID(); - Voucher voucher = new FixedAmountVoucher(1000, customerId); - voucherRepository.save(voucher); - - // 쿠폰 소지자가 존재하지 않는 쿠폰 저장 - Voucher voucher2 = new PercentDiscountVoucher(10); - voucherRepository.save(voucher2); - - // 사용자 UUID로 쿠폰 목록 요청 - List returned = voucherService.getVouchers(customerId); - - // 쿠폰 목록의 크기가 1 - assertThat(returned).hasSize(1); - } - - @Test - void 쿠폰_소지자_할당() { - // 쿠폰 생성 - Voucher voucher = new FixedAmountVoucher(1000); - voucherRepository.save(voucher); - - // 쿠폰에 쿠폰 소지자 할당 요청 - UUID customerId = UUID.randomUUID(); - voucherService.assignVoucherOwner(voucher.getId(), customerId); - - // 쿠폰 소지자가 할당한 소지자와 동일 - Voucher returned = voucherRepository.findById(voucher.getId()).get(); - assertThat(returned.getOwnerId()).isEqualTo(customerId); - } - @Test void 쿠폰_아이디로_조회() { // 쿠폰 생성 - Voucher voucher = new FixedAmountVoucher(1000); + Voucher voucher = createFixedVoucher(1L, 1000); voucherRepository.save(voucher); // UUID로 쿠폰 조회 @@ -135,7 +114,7 @@ class VoucherServiceTest { @Test void 쿠폰_아이디로_삭제() { // 쿠폰 생성 - Voucher voucher = new FixedAmountVoucher(1000); + Voucher voucher = createFixedVoucher(1L, 1000); voucherRepository.save(voucher); // UUID로 쿠폰 삭제 @@ -145,4 +124,20 @@ class VoucherServiceTest { List vouchers = voucherRepository.findAll(); assertThat(vouchers).hasSize(0); } + + private static VoucherCreateRequest createFixedVoucherRequest(int amount) { + return new VoucherCreateRequest(FIXED, amount); + } + + private static VoucherCreateRequest createPercentVoucherRequest(int percent) { + return new VoucherCreateRequest(PERCENT, percent); + } + + private static Voucher createFixedVoucher(Long id, int amount) { + return new Voucher.Builder(id, FIXED, amount).build(); + } + + private static Voucher createPercentVoucher(Long id, int percent) { + return new Voucher.Builder(id, PERCENT, percent).build(); + } } \ No newline at end of file From 47b20e59ea485a2658602f299c531edcb23e1c61 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 07:18:47 +0900 Subject: [PATCH 091/134] =?UTF-8?q?refactor:=20=EC=BD=98=EC=86=94=20?= =?UTF-8?q?=EC=96=B4=ED=94=8C=EB=A6=AC=EC=BC=80=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=ED=8F=AC=EB=A7=B7=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/VoucherController.java | 8 +-- .../controller/voucher/VoucherResponse.java | 33 +++++++++++ .../view/consoleapp/ConsoleUtil.java | 21 +++++++ .../management/ManagementApplication.java | 56 +++++++++++-------- .../consoleapp/wallet/WalletApplication.java | 12 ++-- 5 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java index 9c9c20f110..0535854a1a 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java @@ -17,13 +17,13 @@ public void createVoucher(VoucherCreateRequest request) { voucherService.createVoucher(request.toServiceRequest()); } - public String getVoucherInfo(String voucherId) { - return voucherService.getVoucher(Long.valueOf(voucherId)).toString(); + public VoucherResponse getVoucher(String voucherId) { + return VoucherResponse.of(voucherService.getVoucher(Long.valueOf(voucherId))); } - public List getVouchersInfo() { + public List getVouchers() { return voucherService.getVouchers().stream() - .map(Object::toString) + .map(VoucherResponse::of) .toList(); } diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java new file mode 100644 index 0000000000..a1ac5d6cc2 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.controller.voucher; + +import team.marco.voucher_management_system.domain.voucher.Voucher; + +import java.util.UUID; + +public class VoucherResponse { + private Long id; + private UUID code; + private String name; + + public VoucherResponse(Long id, UUID code, String name) { + this.id = id; + this.code = code; + this.name = name; + } + + public static VoucherResponse of(Voucher voucher) { + return new VoucherResponse(voucher.getId(), voucher.getCode(), voucher.getName()); + } + + public Long getId() { + return id; + } + + public UUID getCode() { + return code; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index b73b51a7f4..d6cf3d9a6b 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -1,5 +1,7 @@ package team.marco.voucher_management_system.view.consoleapp; +import team.marco.voucher_management_system.controller.voucher.VoucherResponse; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -7,6 +9,8 @@ import java.util.List; import java.util.Objects; +import static java.text.MessageFormat.format; + public final class ConsoleUtil { private static final String INFO_DELIMINATOR = "\n"; private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); @@ -61,4 +65,21 @@ private static String readLine() { throw new UncheckedIOException(e); } } + + public static void printVoucherList(List vouchers) { + vouchers.stream().forEach(v -> { + printVoucher(v); + printSeparatorLine(); + }); + } + + private static void printSeparatorLine() { + print("--------------------"); + } + + public static void printVoucher(VoucherResponse voucher) { + print(format("id : {0}", voucher.getId())); + print(format("name : {0}", voucher.getName())); + print(format("code : {0}", voucher.getCode())); + } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 1e14117f39..39431cf51d 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -5,10 +5,14 @@ import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.customer.CustomerController; import team.marco.voucher_management_system.controller.voucher.VoucherController; -import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; +import team.marco.voucher_management_system.controller.voucher.VoucherCreateRequest; import java.io.UncheckedIOException; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleUtil.*; + @Component public class ManagementApplication { private static final Logger logger = LoggerFactory.getLogger(ManagementApplication.class); @@ -35,16 +39,16 @@ public void run() { } public void selectCommand() { - ConsoleUtil.print("=== 관리자 페이지 ==="); + print("=== 관리자 페이지 ==="); for(ManagementCommandType type : ManagementCommandType.values()) { - ConsoleUtil.print(type.getInfo()); + print(type.getInfo()); } - ConsoleUtil.println(); + println(); - ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); - int input = ConsoleUtil.readInt(); + print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); + int input = readInt(); ManagementCommandType commandType = ManagementCommandType.get(input); switch (commandType) { @@ -64,20 +68,20 @@ private void getCustomerList() { } private void getVoucherInfo() { - ConsoleUtil.print("쿠폰 번호를 입력해 주세요."); - String voucherId = ConsoleUtil.readString(); + print("쿠폰 번호를 입력해 주세요."); + String voucherId = readString(); - ConsoleUtil.print(voucherController.getVoucherInfo(voucherId)); + print(voucherController.getVoucher(voucherId)); } private void createVoucher() { logger.info("Call createVoucher()"); - ConsoleUtil.print(""" + print(""" 0: 고정 금액 할인 쿠폰 1: % 할인 쿠폰"""); - int selected = ConsoleUtil.readInt(); + int selected = readInt(); switch (selected) { case 0 -> createFixedAmountVoucher(); @@ -89,31 +93,39 @@ private void createVoucher() { private void createPercentDiscountVoucher() { logger.info("Call createPercentDiscountVoucher()"); - ConsoleUtil.print("할인율을 입력해 주세요."); - int percent = ConsoleUtil.readInt(); + print("할인율을 입력해 주세요."); + int percent = readInt(); + + VoucherCreateRequest request = new VoucherCreateRequest(PERCENT, percent); + voucherController.createVoucher(request); - voucherController.createPercentDiscountVoucher(percent); + println("쿠폰 생성이 완료되었습니다."); } private void createFixedAmountVoucher() { logger.info("Call createFixedAmountVoucher()"); - ConsoleUtil.print("할인 금액을 입력해 주세요."); - int amount = ConsoleUtil.readInt(); + print("할인 금액을 입력해 주세요."); + int amount = readInt(); + + VoucherCreateRequest request = new VoucherCreateRequest(FIXED, amount); + voucherController.createVoucher(request); - voucherController.createFixedAmountVoucher(amount); + println("쿠폰 생성이 완료되었습니다."); } private void getVoucherList() { logger.info("Call getVoucherList()"); - ConsoleUtil.printStringList(voucherController.getVouchersInfo()); + printVoucherList(voucherController.getVouchers()); + println(); + println("조회가 완료되었습니다."); } private void getBlacklist() { logger.info("Call getBlackListUsers()"); - ConsoleUtil.printStringList(userController.getBlacklistInfo()); + printStringList(userController.getBlacklistInfo()); } private void close() { @@ -122,19 +134,19 @@ private void close() { private void handleException(Exception e) { if(e instanceof NumberFormatException) { - ConsoleUtil.print("숫자를 입력해 주세요."); + print("숫자를 입력해 주세요."); return; } if(e instanceof IllegalArgumentException) { - ConsoleUtil.print(e.getMessage()); + print(e.getMessage()); return; } logger.error(e.toString()); String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; - ConsoleUtil.print(errorMessage); + print(errorMessage); isRunning = false; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index 2c1a90f560..db2dd3f722 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -60,16 +60,12 @@ private void selectCommand(String customerId) { } } - private void registerVoucher(String customerId) { - ConsoleUtil.print("등록하실 쿠폰 번호를 입력해주세요."); - String voucherId = ConsoleUtil.readString(); - voucherController.assignVoucherOwner(voucherId, customerId); - - ConsoleUtil.print("쿠폰 등록이 완료되었습니다."); + private void getMyVouchers(String customerId) { + // TODO } - private void getMyVouchers(String customerId) { - ConsoleUtil.printStringList(voucherController.getVouchersInfo(customerId)); + private void registerVoucher(String customerId) { + // TODO } private void removeVoucher() { From 2941058cf066a5a4c4f247f2ee6db6814f068f54 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 07:19:23 +0900 Subject: [PATCH 092/134] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=ED=95=98=EB=8A=94=20id=EB=A1=9C=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/voucher/VoucherService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index 5b1fc208c1..e6a5fca6f7 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -21,9 +21,9 @@ public VoucherService(VoucherRepository voucherRepository) { @Transactional public Voucher createVoucher(VoucherCreateServiceRequest request) { - Long id = voucherRepository.findLatestVoucherId().orElse(1L); + Long latestId = voucherRepository.findLatestVoucherId().orElse(1L); - Voucher.Builder builder = new Voucher.Builder(id, request.getVoucherType(), request.getDiscountValue()); + Voucher.Builder builder = new Voucher.Builder(latestId + 1, request.getVoucherType(), request.getDiscountValue()); request.getCode().ifPresent(code -> builder.code(code)); request.getName().ifPresent(name -> builder.name(name)); Voucher voucher = builder.build(); From 183b21ca9e60f18ff5c201a7b3d9fb0f1ffbbeed Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 08:53:37 +0900 Subject: [PATCH 093/134] =?UTF-8?q?test:=20VoucherRespotitory=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VoucherManagementSystemApplication.java | 3 - .../custromer/CsvBlacklistRepositoryTest.java | 4 + .../voucher/JdbcVoucherRepositoryTest.java | 32 +++- .../JsonFileVoucherRepositoryTest.java | 143 ++++++++++++++++++ .../voucher/MemoryVoucherRepositoryTest.java | 91 ++++++++++- 5 files changed, 264 insertions(+), 9 deletions(-) create mode 100644 src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java create mode 100644 src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java diff --git a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java index 7ce3f87291..fafbcfd7c9 100644 --- a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java @@ -1,7 +1,5 @@ package team.marco.voucher_management_system; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; @@ -9,7 +7,6 @@ @SpringBootApplication public class VoucherManagementSystemApplication { - private static final Logger logger = LoggerFactory.getLogger(VoucherManagementSystemApplication.class); public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java new file mode 100644 index 0000000000..3fc72a3acc --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java @@ -0,0 +1,4 @@ +import static org.junit.jupiter.api.Assertions.*; +class CsvBlacklistRepositoryTest { + +} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 7bdb70b103..90223982c9 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -7,16 +7,15 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.annotation.Transactional; import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -@Transactional @SpringBootTest @ActiveProfiles("prod") class JdbcVoucherRepositoryTest { @@ -91,6 +90,35 @@ void setUp() { assertThat(vouchers).hasSize(0); } + @DisplayName("저장된 쿠폰 id 중 최댓값을 구할 수 있다.") + @Test + void findLatestVoucherId() { + // given + Voucher voucher1 = createFixedVoucher(1L, 1000); + Voucher voucher2 = createFixedVoucher(2L, 2000); + Voucher voucher3 = createPercentVoucher(3L, 30); + voucherRepository.save(voucher1); + voucherRepository.save(voucher2); + voucherRepository.save(voucher3); + + // when + Optional latestId = voucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isFalse(); + assertThat(latestId.get()).isEqualTo(3L); + } + + @DisplayName("저장된 쿠폰이 없는 경우 쿠폰 id 중 최댓값을 요청하면 빈 Optional을 반환한다.") + @Test + void findLatestVoucherIdInEmpty() { + // given when + Optional latestId = voucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isTrue(); + } + private static Voucher createFixedVoucher(Long id, int amount) { return new Voucher.Builder(id, FIXED, amount).build(); } diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java new file mode 100644 index 0000000000..4df16b06dc --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java @@ -0,0 +1,143 @@ +package team.marco.voucher_management_system.repository.voucher; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.test.context.ActiveProfiles; +import team.marco.voucher_management_system.domain.voucher.Voucher; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.*; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; + +@ActiveProfiles("test") +class JsonFileVoucherRepositoryTest { + private JsonFileVoucherRepository fileVoucherRepository; + + public JsonFileVoucherRepositoryTest() { + fileVoucherRepository = new JsonFileVoucherRepository("src/test/resources/test_voucher_data.json"); + } + + @DisplayName("바우처를 생성할 수 있다.") + @Test + void save() { + // 1,000원 할인 쿠폰 생성 + int amount = 1_000; + Voucher voucher = createFixedVoucher(1L, amount); + Voucher saved = fileVoucherRepository.save(voucher); + + // 생성된 바우처 반환 + assertThat(saved).isEqualTo(voucher); + } + + @DisplayName("전체 쿠폰 목록을 조회 할 수 있다.") + @Test + void findAll() { + // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 + int discountAmount = 1_000; + Voucher voucher = createFixedVoucher(1L, discountAmount); + fileVoucherRepository.save(voucher); + + int percent = 10; + Voucher voucher2 = createPercentVoucher(2L, percent); + fileVoucherRepository.save(voucher2); + + // 전체 쿠폰 목록 조회 + List vouchers = fileVoucherRepository.findAll(); + + // 저장된 2개의 쿠폰이 조회 + assertThat(vouchers).hasSize(2); + } + + @DisplayName("쿠폰 id로 쿠폰을 검색할 수 있다.") + @Test + void findById() { + // given + Voucher voucher = createFixedVoucher(1L, 1000); + fileVoucherRepository.save(voucher); + Long voucherId = voucher.getId(); + + // when + Optional found = fileVoucherRepository.findById(voucherId); + + // then + assertThat(found.get()).isNotNull(); + assertThat(found.get()) + .extracting("id", "discountValue") + .containsExactly(1L, 1000); + } + + @DisplayName("존재하지 않는 쿠폰 id로 검색하면 빈 Optional이 반환된다.") + @Test + void findByIdWithInvaildId() { + // given + Long randomId = -1L; + + // when + Optional found = fileVoucherRepository.findById(randomId); + + // then + assertThat(found.isEmpty()).isTrue(); + } + + @DisplayName("쿠폰 id로 쿠폰을 삭제할 수 있다.") + @Test + void deleteById() { + // given + Voucher voucher = createFixedVoucher(1L, 1000); + fileVoucherRepository.save(voucher); + Long voucherId = voucher.getId(); + + Optional before = fileVoucherRepository.findById(voucherId); + assertThatNoException().isThrownBy(before::get); + + // when + fileVoucherRepository.deleteById(voucherId); + + // then + Optional after = fileVoucherRepository.findById(voucherId); + assertThatThrownBy(after::get) + .isInstanceOf(NoSuchElementException.class); + } + + @DisplayName("저장된 쿠폰 id 중 최댓값을 구할 수 있다.") + @Test + void findLatestVoucherId() { + // given + Voucher voucher1 = createFixedVoucher(1L, 1000); + Voucher voucher2 = createFixedVoucher(2L, 2000); + Voucher voucher3 = createPercentVoucher(3L, 30); + fileVoucherRepository.save(voucher1); + fileVoucherRepository.save(voucher2); + fileVoucherRepository.save(voucher3); + + // when + Optional latestId = fileVoucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isFalse(); + assertThat(latestId.get()).isEqualTo(3L); + } + + @DisplayName("저장된 쿠폰이 없는 경우 쿠폰 id 중 최댓값을 요청하면 빈 Optional을 반환한다.") + @Test + void findLatestVoucherIdInEmpty() { + // given when + Optional latestId = fileVoucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isTrue(); + } + + private static Voucher createFixedVoucher(Long id, int amount) { + return new Voucher.Builder(id, FIXED, amount).build(); + } + + private static Voucher createPercentVoucher(Long id, int percent) { + return new Voucher.Builder(id, PERCENT, percent).build(); + } + +} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java index 2f6df355d4..a153ead4ba 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java @@ -7,8 +7,10 @@ import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; @@ -20,9 +22,9 @@ void setUp() { voucherRepository = new MemoryVoucherRepository(); } + @DisplayName("바우처를 생성할 수 있다.") @Test - @DisplayName("바우처 생성 시 생성된 바우처를 반환") - void 쿠폰_생성_성공() { + void save() { // 1,000원 할인 쿠폰 생성 int amount = 1_000; Voucher voucher = createFixedVoucher(1L, amount); @@ -32,8 +34,9 @@ void setUp() { assertThat(saved).isEqualTo(voucher); } + @DisplayName("전체 쿠폰 목록을 조회 할 수 있다.") @Test - void 전체_쿠폰_목록_조회_성공() { + void findAll() { // 1,000원 할인 쿠폰, 10% 할인 쿠폰 생성 int discountAmount = 1_000; Voucher voucher = createFixedVoucher(1L, discountAmount); @@ -50,6 +53,86 @@ void setUp() { assertThat(vouchers).hasSize(2); } + @DisplayName("쿠폰 id로 쿠폰을 검색할 수 있다.") + @Test + void findById() { + // given + Voucher voucher = createFixedVoucher(1L, 1000); + voucherRepository.save(voucher); + Long voucherId = voucher.getId(); + + // when + Optional found = voucherRepository.findById(voucherId); + + // then + assertThat(found.get()).isNotNull(); + assertThat(found.get()) + .extracting("id", "discountValue") + .containsExactly(1L, 1000); + } + + @DisplayName("존재하지 않는 쿠폰 id로 검색하면 빈 Optional이 반환된다.") + @Test + void findByIdWithInvaildId() { + // given + Long randomId = -1L; + + // when + Optional found = voucherRepository.findById(randomId); + + // then + assertThat(found.isEmpty()).isTrue(); + } + + @DisplayName("쿠폰 id로 쿠폰을 삭제할 수 있다.") + @Test + void deleteById() { + // given + Voucher voucher = createFixedVoucher(1L, 1000); + voucherRepository.save(voucher); + Long voucherId = voucher.getId(); + + Optional before = voucherRepository.findById(voucherId); + assertThatNoException().isThrownBy(before::get); + + // when + voucherRepository.deleteById(voucherId); + + // then + Optional after = voucherRepository.findById(voucherId); + assertThatThrownBy(after::get) + .isInstanceOf(NoSuchElementException.class); + } + + @DisplayName("저장된 쿠폰 id 중 최댓값을 구할 수 있다.") + @Test + void findLatestVoucherId() { + // given + Voucher voucher1 = createFixedVoucher(1L, 1000); + Voucher voucher2 = createFixedVoucher(2L, 2000); + Voucher voucher3 = createPercentVoucher(3L, 30); + voucherRepository.save(voucher1); + voucherRepository.save(voucher2); + voucherRepository.save(voucher3); + + // when + Optional latestId = voucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isFalse(); + assertThat(latestId.get()).isEqualTo(3L); + } + + @DisplayName("저장된 쿠폰이 없는 경우 쿠폰 id 중 최댓값을 요청하면 빈 Optional을 반환한다.") + @Test + void findLatestVoucherIdInEmpty() { + // given when + Optional latestId = voucherRepository.findLatestVoucherId(); + + // then + assertThat(latestId.isEmpty()).isTrue(); + } + private static Voucher createFixedVoucher(Long id, int amount) { return new Voucher.Builder(id, FIXED, amount).build(); } From 99d5c2e087bb9598508bfac988907678f1d6e1d6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 08:54:34 +0900 Subject: [PATCH 094/134] =?UTF-8?q?refactor:=20VoucherRespository=EC=97=90?= =?UTF-8?q?=20@Profile=20=EB=8C=80=EC=8B=A0=20@Primary=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/voucher/JdbcVoucherRepository.java | 4 ++-- .../repository/voucher/JsonFileVoucherRepository.java | 2 -- .../repository/voucher/MemoryVoucherRepository.java | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index 03a87f3214..9ed923428e 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -2,7 +2,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -15,7 +15,7 @@ import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; import static team.marco.voucher_management_system.util.UUIDUtil.uuidToBytes; -@Profile("prod") +@Primary @Repository public class JdbcVoucherRepository implements VoucherRepository { private static final Logger logger = LoggerFactory.getLogger(JdbcVoucherRepository.class); diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java index 8462f7cd93..9dc22eef4b 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.ObjectReader; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -17,7 +16,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -@Profile("dev") @Repository public class JsonFileVoucherRepository implements VoucherRepository, DisposableBean { private final Map voucherMap; diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java index 5c8a170921..e041baf6cf 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java @@ -1,6 +1,5 @@ package team.marco.voucher_management_system.repository.voucher; -import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -10,7 +9,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -@Profile({"local", "debug"}) @Repository public class MemoryVoucherRepository implements VoucherRepository { private final Map voucherMap = new ConcurrentHashMap<>(); From a5e93e3376a7b52ed448df09ea197dece8cf1fdb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 08:54:57 +0900 Subject: [PATCH 095/134] =?UTF-8?q?test:=20CsvBlacklistRepository=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/CsvBlacklistRepositoryTest.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java index 3fc72a3acc..caea798a7f 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java @@ -1,4 +1,45 @@ -import static org.junit.jupiter.api.Assertions.*; +package team.marco.voucher_management_system.repository.custromer; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.test.context.ActiveProfiles; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static team.marco.voucher_management_system.util.UUIDUtil.stringToUUID; + +@ActiveProfiles("test") class CsvBlacklistRepositoryTest { - + + private CsvBlacklistRepository csvBlacklistRepository; + + public CsvBlacklistRepositoryTest() { + csvBlacklistRepository = new CsvBlacklistRepository("src/test/resources/test_blacklist.csv"); + } + + @DisplayName("") + @Test + void test() { + /** + * test_blacklist.csv에 + * id name + * 461b8847-578d-43c7-8472-d9374bbac41a 정의진 + * 461b8847-578d-43c7-8472-d9374bbac42b 김현우 + * 를 미리 넣어 놨습니다. + */ + + // when + List blacklist = csvBlacklistRepository.findAll(); + + // then + assertThat(blacklist).hasSize(2); + assertThat(blacklist) + .extracting("id", "name") + .containsExactlyInAnyOrder( + tuple(stringToUUID("461b8847-578d-43c7-8472-d9374bbac41a"), "정의진"), + tuple(stringToUUID("461b8847-578d-43c7-8472-d9374bbac42b"), "김현우") + ); + } } \ No newline at end of file From 9787d4c8ee57dd341a4ecbdd878330c72e11fa59 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 22:58:59 +0900 Subject: [PATCH 096/134] =?UTF-8?q?refactor:=20=EC=BB=A4=EB=A7=A8=EB=93=9C?= =?UTF-8?q?=20=EB=A9=94=EB=89=B4=20=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/consoleapp/ServiceType.java | 10 +++++----- .../management/ManagementCommandType.java | 16 ++++++++-------- .../consoleapp/wallet/WalletCommandType.java | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java index 8217812c3f..652e0895b5 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java @@ -3,12 +3,12 @@ import java.util.Arrays; public enum ServiceType { - MANAGEMENT(1, "관리자 서비스"), - WALLET(2, "회원 지갑 서비스"), - EXIT(3, "프로그램 종료"); + EXIT(1, "프로그램 종료"), + MANAGEMENT(2, "관리자 서비스"), + WALLET(3, "회원 지갑 서비스"); - private int num; - private String description; + private final int num; + private final String description; ServiceType(int num, String description) { this.num = num; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java index 7418964fcb..18137b9f80 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java @@ -3,15 +3,15 @@ import java.util.Arrays; public enum ManagementCommandType { - CREATE_VOUCHER(1, "쿠폰 생성"), - VOUCHER_LIST(2, "쿠폰 목록 조회"), - SEARCH_VOUCHER(3, "쿠폰 검색"), - CUSTOMER_LIST(4, "전체 회원 조회"), - BLACKLIST(5, "블랙 리스트 회원 조회"), - BACK(6, "메인 페이지로 돌아가기"); + BACK(1, "메인 페이지로 돌아가기"), + CREATE_VOUCHER(2, "쿠폰 생성"), + VOUCHER_LIST(3, "쿠폰 목록 조회"), + SEARCH_VOUCHER(4, "쿠폰 검색"), + CUSTOMER_LIST(5, "전체 회원 조회"), + BLACKLIST(6, "블랙 리스트 회원 조회"); - private int num; - private String description; + private final int num; + private final String description; ManagementCommandType(int num, String description) { this.num = num; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java index 1423317b70..b77b599695 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java @@ -3,13 +3,13 @@ import java.util.Arrays; public enum WalletCommandType { - REGISTER(1, "쿠폰 등록"), - LIST(2, "나의 쿠폰 목록 조회"), - REMOVE(3, "쿠폰 삭제"), - BACK(4, "메인 페이지로 돌아가기"); + BACK(1, "메인 페이지로 돌아가기"), + REGISTER(2, "쿠폰 등록"), + LIST(3, "나의 쿠폰 목록 조회"), + REMOVE(4, "쿠폰 삭제"); - private int num; - private String description; + private final int num; + private final String description; WalletCommandType(int num, String description) { this.num = num; From 23adf2b15712f9944a1161e511c15a4d649126ff Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 22:59:37 +0900 Subject: [PATCH 097/134] =?UTF-8?q?refactor:=20=EC=BD=98=EC=86=94=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=83=81=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/consoleapp/ConsoleMessage.java | 24 +++++++++++++ .../view/consoleapp/ConsoleUtil.java | 8 +++-- .../view/consoleapp/VoucherApplication.java | 12 ++++--- .../management/ManagementApplication.java | 35 ++++++++++--------- .../consoleapp/wallet/WalletApplication.java | 16 +++++---- 5 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java new file mode 100644 index 0000000000..d2742161f2 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java @@ -0,0 +1,24 @@ +package team.marco.voucher_management_system.view.consoleapp; + +public class ConsoleMessage { + public static final String MANAGEMENT_HEADER = "==== 관리자 페이지 ===="; + public static final String MAIN_HEADER = "==== 메인 페이지 ===="; + public static final String WALLET_HEADER = "==== 지갑 페이지 ===="; + public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; + public static final String VOUCHER_MANUAL = """ + 1: $ 할인 쿠폰 + 2: % 할인 쿠폰"""; + public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; + public static final String DISCOUNT_PERCENT_REQUEST = "할인율을 입력해 주세요."; + public static final String DISCOUNT_AMOUNT_REQUEST = "할인 금액을 입력해 주세요."; + public static final String VOUCHER_CREATE_COMPLETE = "쿠폰 생성이 완료되었습니다."; + public static final String INQUIRY_COMPLETE = "조회가 완료되었습니다."; + public static final String PROGRAM_EXIT = "프로그램이 종료되었습니다."; + public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; + public static final String PROGRAM_ERROR = "프로그램에 에러가 발생했습니다."; + public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; + public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; + public static final String CUSTOMER_ID_REQUEST = "사용자 아이디를 입력해주세요."; + public static final String CUSTOMER_ID_INVALID = "올바른 사용자 아이디가 아닙니다."; + public static final String VOUCHER_DELETE_COMPLETE = "쿠폰 삭제가 완료되었습니다."; +} diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index d6cf3d9a6b..0a9414215d 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -10,6 +10,8 @@ import java.util.Objects; import static java.text.MessageFormat.format; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.INQUIRY_COMPLETE; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.WRONG_INPUT; public final class ConsoleUtil { private static final String INFO_DELIMINATOR = "\n"; @@ -39,7 +41,7 @@ public static void printStringList(List list) { ConsoleUtil.println(joinedString); } - ConsoleUtil.println("조회가 완료되었습니다."); + ConsoleUtil.println(INQUIRY_COMPLETE); } public static String readString() { @@ -48,7 +50,7 @@ public static String readString() { System.out.println(); if (Objects.isNull(input)) { - throw new RuntimeException("입력 과정에서 오류가 발생했습니다."); + throw new RuntimeException(WRONG_INPUT); } return input; @@ -67,7 +69,7 @@ private static String readLine() { } public static void printVoucherList(List vouchers) { - vouchers.stream().forEach(v -> { + vouchers.forEach(v -> { printVoucher(v); printSeparatorLine(); }); diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java index 70ebd826c8..119f86821b 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java @@ -8,6 +8,8 @@ import java.io.UncheckedIOException; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; + @Component public class VoucherApplication { private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); @@ -34,7 +36,7 @@ public void run() { } public void selectService() { - ConsoleUtil.print("=== 메인 페이지 ==="); + ConsoleUtil.print(MAIN_HEADER); for(ServiceType type : ServiceType.values()) { ConsoleUtil.print(type.getInfo()); @@ -42,7 +44,7 @@ public void selectService() { ConsoleUtil.println(); - ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요. (숫자)"); + ConsoleUtil.print(SELECT_SERVICE); int input = ConsoleUtil.readInt(); ServiceType type = ServiceType.get(input); @@ -64,12 +66,12 @@ private void close() { logger.info("Call close()"); isRunning = false; - ConsoleUtil.print("프로그램이 종료되었습니다."); + ConsoleUtil.print(PROGRAM_EXIT); } private void handleException(Exception e) { if(e instanceof NumberFormatException) { - ConsoleUtil.print("숫자를 입력해 주세요."); + ConsoleUtil.print(NUMBER_REQUIRED); return; } @@ -80,7 +82,7 @@ private void handleException(Exception e) { logger.error(e.toString()); - String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; + String errorMessage = (e instanceof UncheckedIOException)? FILE_ERROR : PROGRAM_ERROR; ConsoleUtil.print(errorMessage); isRunning = false; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 39431cf51d..1075006bbf 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -11,6 +11,7 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; import static team.marco.voucher_management_system.view.consoleapp.ConsoleUtil.*; @Component @@ -39,7 +40,7 @@ public void run() { } public void selectCommand() { - print("=== 관리자 페이지 ==="); + print(MANAGEMENT_HEADER); for(ManagementCommandType type : ManagementCommandType.values()) { print(type.getInfo()); @@ -47,7 +48,7 @@ public void selectCommand() { println(); - print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); + print(SELECT_SERVICE); int input = readInt(); ManagementCommandType commandType = ManagementCommandType.get(input); @@ -68,50 +69,50 @@ private void getCustomerList() { } private void getVoucherInfo() { - print("쿠폰 번호를 입력해 주세요."); + print(VOUCHER_ID_REQUEST); String voucherId = readString(); - print(voucherController.getVoucher(voucherId)); + printVoucher(voucherController.getVoucher(voucherId)); + println(); + println(INQUIRY_COMPLETE); } private void createVoucher() { logger.info("Call createVoucher()"); - print(""" - 0: 고정 금액 할인 쿠폰 - 1: % 할인 쿠폰"""); + print(VOUCHER_MANUAL); int selected = readInt(); switch (selected) { - case 0 -> createFixedAmountVoucher(); - case 1 -> createPercentDiscountVoucher(); - default -> throw new IllegalArgumentException("올바르지 않은 입력입니다."); + case 1 -> createFixedAmountVoucher(); + case 2 -> createPercentDiscountVoucher(); + default -> throw new IllegalArgumentException(WRONG_INPUT); } } private void createPercentDiscountVoucher() { logger.info("Call createPercentDiscountVoucher()"); - print("할인율을 입력해 주세요."); + print(DISCOUNT_PERCENT_REQUEST); int percent = readInt(); VoucherCreateRequest request = new VoucherCreateRequest(PERCENT, percent); voucherController.createVoucher(request); - println("쿠폰 생성이 완료되었습니다."); + println(VOUCHER_CREATE_COMPLETE); } private void createFixedAmountVoucher() { logger.info("Call createFixedAmountVoucher()"); - print("할인 금액을 입력해 주세요."); + print(DISCOUNT_AMOUNT_REQUEST); int amount = readInt(); VoucherCreateRequest request = new VoucherCreateRequest(FIXED, amount); voucherController.createVoucher(request); - println("쿠폰 생성이 완료되었습니다."); + println(VOUCHER_CREATE_COMPLETE); } private void getVoucherList() { @@ -119,7 +120,7 @@ private void getVoucherList() { printVoucherList(voucherController.getVouchers()); println(); - println("조회가 완료되었습니다."); + println(INQUIRY_COMPLETE); } private void getBlacklist() { @@ -134,7 +135,7 @@ private void close() { private void handleException(Exception e) { if(e instanceof NumberFormatException) { - print("숫자를 입력해 주세요."); + print(NUMBER_REQUIRED); return; } @@ -145,7 +146,7 @@ private void handleException(Exception e) { logger.error(e.toString()); - String errorMessage = (e instanceof UncheckedIOException)? "파일을 처리하는 과정에서 에러가 발생했습니다." : "프로그램에 에러가 발생했습니다."; + String errorMessage = (e instanceof UncheckedIOException)? FILE_ERROR : PROGRAM_ERROR; print(errorMessage); isRunning = false; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index db2dd3f722..7c3296f013 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -7,6 +7,8 @@ import team.marco.voucher_management_system.controller.voucher.VoucherController; import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; + @Component public class WalletApplication { private static final Logger logger = LoggerFactory.getLogger(WalletApplication.class); @@ -23,11 +25,11 @@ public WalletApplication(VoucherController voucherController, CustomerController } public void run() { - ConsoleUtil.print("지갑 서비스를 이용하기 위해 사용자의 아이디를 입력해주세요."); + ConsoleUtil.print(CUSTOMER_ID_REQUEST); String customerId = ConsoleUtil.readString(); if(!customerController.isExistCustomer(customerId)) { - throw new IllegalArgumentException("올바른 사용자 아이디가 아닙니다."); + throw new IllegalArgumentException(CUSTOMER_ID_INVALID); } while (isRunning) { @@ -40,7 +42,7 @@ public void run() { } private void selectCommand(String customerId) { - ConsoleUtil.print("=== 지갑 페이지 ==="); + ConsoleUtil.print(WALLET_HEADER); for(WalletCommandType type : WalletCommandType.values()) { ConsoleUtil.print(type.getInfo()); @@ -48,7 +50,7 @@ private void selectCommand(String customerId) { ConsoleUtil.println(); - ConsoleUtil.print("Q. 이용하실 서비스를 선택해 주세요.(숫자)"); + ConsoleUtil.print(SELECT_SERVICE); int input = ConsoleUtil.readInt(); WalletCommandType commandType = WalletCommandType.get(input); @@ -69,11 +71,11 @@ private void registerVoucher(String customerId) { } private void removeVoucher() { - ConsoleUtil.print("제거할 쿠폰 번호를 입력해주세요."); + ConsoleUtil.print(VOUCHER_ID_REQUEST); String voucherId = ConsoleUtil.readString(); voucherController.deleteVoucher(voucherId); - ConsoleUtil.print("쿠폰 삭제가 완료되었습니다."); + ConsoleUtil.print(VOUCHER_DELETE_COMPLETE); } private void backToMainApplication() { @@ -82,7 +84,7 @@ private void backToMainApplication() { private void handleException(Exception e) { if(e instanceof NumberFormatException) { - ConsoleUtil.print("숫자를 입력해 주세요."); + ConsoleUtil.print(NUMBER_REQUIRED); return; } From 1bbe34784fc422890518ee60a155a4a19bc38f15 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Wed, 1 Nov 2023 23:25:18 +0900 Subject: [PATCH 098/134] =?UTF-8?q?chore:=20spring-web,=20thymeleaf=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index d0dfe1f644..290475dc2d 100644 --- a/build.gradle +++ b/build.gradle @@ -16,14 +16,18 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter' + // Spring boot + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-jdbc' + + // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' // Jackson implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' - // Jdbc + // Mysql implementation group: 'com.mysql', name: 'mysql-connector-j', version: '8.1.0' } From 22c6fdc569686950f503b3635df988532cf05a9f Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 2 Nov 2023 01:10:29 +0900 Subject: [PATCH 099/134] =?UTF-8?q?chore:=20thymeleaf=20dialect=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 290475dc2d..2d55d6bfd6 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ dependencies { // Spring boot implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect') implementation 'org.springframework.boot:spring-boot-starter-jdbc' // Test From 5398476c62f6839c1260cdf74369174799bd07d1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 2 Nov 2023 01:16:37 +0900 Subject: [PATCH 100/134] =?UTF-8?q?feat:=20=EC=BF=A0=ED=8F=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=8E=98=EC=9D=B4=EC=A7=80(voucher=5Flist.html)=20?= =?UTF-8?q?=EC=A0=9C=EA=B3=B5=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherViewController.java | 33 +++++++ src/main/resources/application.yml | 20 ++-- .../resources/templates/layouts/aside.html | 14 +++ .../resources/templates/layouts/footer.html | 14 +++ .../resources/templates/layouts/layout.html | 97 +++++++++++++++++++ .../templates/voucher/voucher_list.html | 32 ++++++ 6 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java create mode 100644 src/main/resources/templates/layouts/aside.html create mode 100644 src/main/resources/templates/layouts/footer.html create mode 100644 src/main/resources/templates/layouts/layout.html create mode 100644 src/main/resources/templates/voucher/voucher_list.html diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java new file mode 100644 index 0000000000..f1f07a28b2 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.controller.voucher; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; +import team.marco.voucher_management_system.service.voucher.VoucherService; + +import java.util.List; + +@Controller +@RequestMapping("/vouchers") +public class VoucherViewController { + private static final Logger logger = LoggerFactory.getLogger(VoucherViewController.class); + private final VoucherService voucherService; + + public VoucherViewController(VoucherService voucherService) { + this.voucherService = voucherService; + } + + @GetMapping() + public String findAllVouchers(Model model) { + List vouchers = voucherService.getVouchers().stream() + .map(VoucherResponse::of) + .toList(); + model.addAttribute("vouchers", vouchers); + + return "voucher/voucher_list"; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f6878a3bca..4234c2b427 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,14 +5,20 @@ application: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + url: jdbc:mysql://localhost:3306/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 username: root - password: uijin-mysql-pw + password: wtwt + + thymeleaf: + cache: false + check-template-location: false + enabled: true file: path: - blacklist: "src/main/resources/blacklist.csv" - voucher_data: "src/main/resources/voucher_data.json" + blacklist: "src/main/resources/data/blacklist.csv" + voucher_data: "src/main/resources/data/voucher_data.json" + --- spring: profiles: @@ -24,8 +30,4 @@ spring: --- spring: profiles: - active: "local" ---- -spring: - profiles: - active: "debug" + active: "test" diff --git a/src/main/resources/templates/layouts/aside.html b/src/main/resources/templates/layouts/aside.html new file mode 100644 index 0000000000..52b35295cc --- /dev/null +++ b/src/main/resources/templates/layouts/aside.html @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/layouts/footer.html b/src/main/resources/templates/layouts/footer.html new file mode 100644 index 0000000000..5325462481 --- /dev/null +++ b/src/main/resources/templates/layouts/footer.html @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/layouts/layout.html b/src/main/resources/templates/layouts/layout.html new file mode 100644 index 0000000000..a43f7a1cb9 --- /dev/null +++ b/src/main/resources/templates/layouts/layout.html @@ -0,0 +1,97 @@ + + + + + + + + + + +
+ + + +
+
+ +
+
+
+
+ + diff --git a/src/main/resources/templates/voucher/voucher_list.html b/src/main/resources/templates/voucher/voucher_list.html new file mode 100644 index 0000000000..acafd4da53 --- /dev/null +++ b/src/main/resources/templates/voucher/voucher_list.html @@ -0,0 +1,32 @@ + + + + +
+
+ # 쿠폰 목록 +
+
+
+
+ + + + + + + + + + + + + +
ID쿠폰명쿠폰 코드
+
+
+
+ From 25ba671ada45882c7a4989e1a0aad0ef12f56dce Mon Sep 17 00:00:00 2001 From: uijin-j Date: Thu, 2 Nov 2023 03:05:31 +0900 Subject: [PATCH 101/134] =?UTF-8?q?feat:=20VoucherViewController=EC=97=90?= =?UTF-8?q?=20Voucher=20=EC=82=AD=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/VoucherViewController.java | 15 +++++++++++++++ src/main/resources/templates/layouts/aside.html | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index f1f07a28b2..19b56d5a14 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import team.marco.voucher_management_system.service.voucher.VoucherService; @@ -26,6 +27,20 @@ public String findAllVouchers(Model model) { List vouchers = voucherService.getVouchers().stream() .map(VoucherResponse::of) .toList(); + + model.addAttribute("vouchers", vouchers); + + return "voucher/voucher_list"; + } + + @GetMapping("/{voucherId}") + public String deleteVoucher(@PathVariable Long voucherId, Model model) { + voucherService.deleteVoucher(voucherId); + + List vouchers = voucherService.getVouchers().stream() + .map(VoucherResponse::of) + .toList(); + model.addAttribute("vouchers", vouchers); return "voucher/voucher_list"; diff --git a/src/main/resources/templates/layouts/aside.html b/src/main/resources/templates/layouts/aside.html index 52b35295cc..53d8de8f1a 100644 --- a/src/main/resources/templates/layouts/aside.html +++ b/src/main/resources/templates/layouts/aside.html @@ -6,8 +6,8 @@ From 7338f8ac4671fd797b703d226a1f722d3ce6f5a2 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 18:17:10 +0900 Subject: [PATCH 102/134] =?UTF-8?q?fix:=20=EB=B0=94=EC=9A=B0=EC=B2=98=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=20?= =?UTF-8?q?=EC=8B=9C=20=EC=9A=94=EC=B2=AD=EC=9D=B4=20Post=EB=A1=9C=20?= =?UTF-8?q?=EA=B0=80=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 2 ++ .../templates/voucher/voucher_detail.html | 0 .../templates/voucher/voucher_list.html | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/templates/voucher/voucher_detail.html diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4234c2b427..8fd52e58d0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,6 +14,8 @@ spring: check-template-location: false enabled: true + mvc.hiddenmethod.filter.enabled: true + file: path: blacklist: "src/main/resources/data/blacklist.csv" diff --git a/src/main/resources/templates/voucher/voucher_detail.html b/src/main/resources/templates/voucher/voucher_detail.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/main/resources/templates/voucher/voucher_list.html b/src/main/resources/templates/voucher/voucher_list.html index acafd4da53..88057b8ede 100644 --- a/src/main/resources/templates/voucher/voucher_list.html +++ b/src/main/resources/templates/voucher/voucher_list.html @@ -14,16 +14,23 @@
+ - - - - - + + + + + +
ID 쿠폰명 쿠폰 코드
+
+ + +
+
From 3747c37993cc0cb7c6e34869f16260f45e90b1b3 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 18:49:56 +0900 Subject: [PATCH 103/134] =?UTF-8?q?feat:=20VoucherViewController=EC=97=90?= =?UTF-8?q?=20Voucher=20=EC=83=81=EC=84=B8=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherViewController.java | 11 +++++++ .../templates/voucher/voucher_detail.html | 30 +++++++++++++++++++ .../templates/voucher/voucher_list.html | 4 ++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index 19b56d5a14..7ac3cfa100 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -4,10 +4,12 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; +import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; @@ -34,6 +36,15 @@ public String findAllVouchers(Model model) { } @GetMapping("/{voucherId}") + public String findVoucher(@PathVariable Long voucherId, Model model) { + Voucher voucher = voucherService.getVoucher(voucherId); + + model.addAttribute("voucher", voucher); + + return "voucher/voucher_detail"; + } + + @DeleteMapping("/{voucherId}") public String deleteVoucher(@PathVariable Long voucherId, Model model) { voucherService.deleteVoucher(voucherId); diff --git a/src/main/resources/templates/voucher/voucher_detail.html b/src/main/resources/templates/voucher/voucher_detail.html index e69de29bb2..141f0a008b 100644 --- a/src/main/resources/templates/voucher/voucher_detail.html +++ b/src/main/resources/templates/voucher/voucher_detail.html @@ -0,0 +1,30 @@ + + + + +
+
+ # 쿠폰 목록 +
+
+
+
+ + + + + + + + + + + +
ID쿠폰명쿠폰 코드
+
+
+
+ \ No newline at end of file diff --git a/src/main/resources/templates/voucher/voucher_list.html b/src/main/resources/templates/voucher/voucher_list.html index 88057b8ede..190e088dc6 100644 --- a/src/main/resources/templates/voucher/voucher_list.html +++ b/src/main/resources/templates/voucher/voucher_list.html @@ -28,7 +28,9 @@ - + + + From dafa837e7713acff902aeceeddde0fc133fbbbdb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 19:18:17 +0900 Subject: [PATCH 104/134] =?UTF-8?q?feat:=20VoucherViewController=EC=97=90?= =?UTF-8?q?=20Voucher=20=EC=83=9D=EC=84=B1=20=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherViewController.java | 34 ++++++++++++++++--- .../voucher/voucher_create_form.html | 27 +++++++++++++++ .../templates/voucher/voucher_list.html | 2 +- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/templates/voucher/voucher_create_form.html diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index 7ac3cfa100..a9c6a3676a 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -4,15 +4,15 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; +import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; +import java.util.Optional; @Controller @RequestMapping("/vouchers") @@ -44,6 +44,32 @@ public String findVoucher(@PathVariable Long voucherId, Model model) { return "voucher/voucher_detail"; } + @GetMapping("/create") + public String findVoucherCreateForm() { + return "voucher/voucher_create_form"; + } + + @PostMapping() + public String createVoucher(@RequestParam("voucherType") String voucherType, + @RequestParam("discountValue") int discountValue, + Model model) { + logger.info("createVoucher!"); + voucherService.createVoucher(new VoucherCreateServiceRequest( + VoucherType.valueOf(voucherType), + discountValue, + Optional.empty(), + Optional.empty()) + ); + + List vouchers = voucherService.getVouchers().stream() + .map(VoucherResponse::of) + .toList(); + + model.addAttribute("vouchers", vouchers); + + return "voucher/voucher_list"; + } + @DeleteMapping("/{voucherId}") public String deleteVoucher(@PathVariable Long voucherId, Model model) { voucherService.deleteVoucher(voucherId); diff --git a/src/main/resources/templates/voucher/voucher_create_form.html b/src/main/resources/templates/voucher/voucher_create_form.html new file mode 100644 index 0000000000..2ed7852139 --- /dev/null +++ b/src/main/resources/templates/voucher/voucher_create_form.html @@ -0,0 +1,27 @@ + + + + + Voucher 생성 + + +

쿠폰 생성

+
+
+ + +
+
+ + +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/voucher/voucher_list.html b/src/main/resources/templates/voucher/voucher_list.html index 190e088dc6..7a74ebf151 100644 --- a/src/main/resources/templates/voucher/voucher_list.html +++ b/src/main/resources/templates/voucher/voucher_list.html @@ -3,13 +3,13 @@ xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{/layouts/layout}"> -
# 쿠폰 목록
+
From b74491ee04e9bbd91fb5083ef8e95aec47720a35 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 19:18:48 +0900 Subject: [PATCH 105/134] =?UTF-8?q?docs:=20sample=5Fdata.json=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/data/sample_data.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/resources/data/sample_data.json diff --git a/src/main/resources/data/sample_data.json b/src/main/resources/data/sample_data.json new file mode 100644 index 0000000000..91b4aacec6 --- /dev/null +++ b/src/main/resources/data/sample_data.json @@ -0,0 +1,16 @@ +[ + { + "code": "5e144cb9-b51c-4b10-97f4-f2402479ae06", + "discountValue": 1000, + "id": 2, + "name": "1,000원 할인 쿠폰", + "voucherType": "FIXED" + }, + { + "code": "6bfbb93a-0337-4d1e-bb39-d761052b321a", + "discountValue": 60, + "id": 3, + "name": "60% 할인 쿠폰", + "voucherType": "PERCENT" + } +] From 9bd3c9f6de415ef87a46890a59f11e27428bfbde Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 19:21:24 +0900 Subject: [PATCH 106/134] =?UTF-8?q?structure:=20controller=20=EB=A0=88?= =?UTF-8?q?=EC=9D=B4=EC=96=B4=20=ED=95=98=EC=9C=84=EC=97=90=20dto=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/VoucherController.java | 2 ++ .../controller/voucher/{ => dto}/VoucherCreateRequest.java | 2 +- .../controller/voucher/{ => dto}/VoucherResponse.java | 2 +- .../voucher_management_system/view/consoleapp/ConsoleUtil.java | 2 +- .../view/consoleapp/management/ManagementApplication.java | 2 +- src/main/resources/{ => data}/schema.sql | 0 .../voucher_management_system/service/VoucherServiceTest.java | 2 +- 7 files changed, 7 insertions(+), 5 deletions(-) rename src/main/java/team/marco/voucher_management_system/controller/voucher/{ => dto}/VoucherCreateRequest.java (92%) rename src/main/java/team/marco/voucher_management_system/controller/voucher/{ => dto}/VoucherResponse.java (90%) rename src/main/resources/{ => data}/schema.sql (100%) diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java index 0535854a1a..75b6066843 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherController.java @@ -1,6 +1,8 @@ package team.marco.voucher_management_system.controller.voucher; import org.springframework.stereotype.Controller; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java similarity index 92% rename from src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java rename to src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java index 6caf4934fa..e91f67752e 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherCreateRequest.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.controller.voucher; +package team.marco.voucher_management_system.controller.voucher.dto; import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherResponse.java similarity index 90% rename from src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java rename to src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherResponse.java index a1ac5d6cc2..cfd00d5628 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherResponse.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherResponse.java @@ -1,4 +1,4 @@ -package team.marco.voucher_management_system.controller.voucher; +package team.marco.voucher_management_system.controller.voucher.dto; import team.marco.voucher_management_system.domain.voucher.Voucher; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index 0a9414215d..953b774b61 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -1,6 +1,6 @@ package team.marco.voucher_management_system.view.consoleapp; -import team.marco.voucher_management_system.controller.voucher.VoucherResponse; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 1075006bbf..08f1fe65cd 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -5,7 +5,7 @@ import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.customer.CustomerController; import team.marco.voucher_management_system.controller.voucher.VoucherController; -import team.marco.voucher_management_system.controller.voucher.VoucherCreateRequest; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; import java.io.UncheckedIOException; diff --git a/src/main/resources/schema.sql b/src/main/resources/data/schema.sql similarity index 100% rename from src/main/resources/schema.sql rename to src/main/resources/data/schema.sql diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index 1cf59d72f7..77e8a29265 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -3,7 +3,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import team.marco.voucher_management_system.controller.voucher.VoucherCreateRequest; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; From fc2266b73c7f2f6286b8ffa6846b997a791ab0bb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Fri, 3 Nov 2023 19:21:59 +0900 Subject: [PATCH 107/134] =?UTF-8?q?refactor:=20'dev'=20profile=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/logback.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index a26815d110..360548a302 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -35,18 +35,6 @@ - - - - - - - - - - - - From bacea541e416a447bf98e3e6cbeaaf4d8fd96034 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 17:04:24 +0900 Subject: [PATCH 108/134] =?UTF-8?q?refactor:=20VoucherViewController=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20(=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=B6=84=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherViewController.java | 42 +++++++++---------- .../voucher/dto/VoucherCreateRequest.java | 7 +--- .../voucher/VoucherCreateServiceRequest.java | 13 ++++-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index a9c6a3676a..40d9106907 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -1,7 +1,5 @@ package team.marco.voucher_management_system.controller.voucher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -12,12 +10,10 @@ import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; -import java.util.Optional; @Controller @RequestMapping("/vouchers") public class VoucherViewController { - private static final Logger logger = LoggerFactory.getLogger(VoucherViewController.class); private final VoucherService voucherService; public VoucherViewController(VoucherService voucherService) { @@ -26,11 +22,7 @@ public VoucherViewController(VoucherService voucherService) { @GetMapping() public String findAllVouchers(Model model) { - List vouchers = voucherService.getVouchers().stream() - .map(VoucherResponse::of) - .toList(); - - model.addAttribute("vouchers", vouchers); + getVouchersAndAddToModel(model); return "voucher/voucher_list"; } @@ -53,19 +45,14 @@ public String findVoucherCreateForm() { public String createVoucher(@RequestParam("voucherType") String voucherType, @RequestParam("discountValue") int discountValue, Model model) { - logger.info("createVoucher!"); + if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); + voucherService.createVoucher(new VoucherCreateServiceRequest( VoucherType.valueOf(voucherType), - discountValue, - Optional.empty(), - Optional.empty()) + discountValue) ); - List vouchers = voucherService.getVouchers().stream() - .map(VoucherResponse::of) - .toList(); - - model.addAttribute("vouchers", vouchers); + getVouchersAndAddToModel(model); return "voucher/voucher_list"; } @@ -74,12 +61,23 @@ public String createVoucher(@RequestParam("voucherType") String voucherType, public String deleteVoucher(@PathVariable Long voucherId, Model model) { voucherService.deleteVoucher(voucherId); - List vouchers = voucherService.getVouchers().stream() - .map(VoucherResponse::of) - .toList(); + getVouchersAndAddToModel(model); + return "voucher/voucher_list"; + } + + private void getVouchersAndAddToModel(Model model) { + List vouchers = vouchersToVoucherResponses(voucherService.getVouchers()); model.addAttribute("vouchers", vouchers); + } - return "voucher/voucher_list"; + private List vouchersToVoucherResponses(List vouchers) { + return vouchers.stream() + .map(VoucherResponse::of) + .toList(); + } + + private static boolean isNotPositive(int discountValue) { + return discountValue <= 0; } } diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java index e91f67752e..130d9ea265 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java @@ -3,8 +3,6 @@ import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; -import java.util.Optional; - public class VoucherCreateRequest { private VoucherType voucherType; private int discountValue; @@ -17,10 +15,7 @@ public VoucherCreateRequest(VoucherType voucherType, int discountValue) { public VoucherCreateServiceRequest toServiceRequest() { return new VoucherCreateServiceRequest( voucherType, - discountValue, - Optional.empty(), - Optional.empty() - ); + discountValue); } public VoucherType getVoucherType() { diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java index d6ed6660a0..571a42476f 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherCreateServiceRequest.java @@ -11,11 +11,18 @@ public class VoucherCreateServiceRequest { private Optional code; private Optional name; - public VoucherCreateServiceRequest(VoucherType voucherType, int discountValue, Optional code, Optional name) { + public VoucherCreateServiceRequest(VoucherType voucherType, int discountValue, UUID code, String name) { this.voucherType = voucherType; this.discountValue = discountValue; - this.code = code; - this.name = name; + this.code = Optional.ofNullable(code); + this.name = Optional.ofNullable(name); + } + + public VoucherCreateServiceRequest(VoucherType voucherType, int discountValue) { + this.voucherType = voucherType; + this.discountValue = discountValue; + this.code = Optional.empty(); + this.name = Optional.empty(); } public VoucherType getVoucherType() { From 27879f2399bfada3b147c8dfb07132d32463f3bf Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 17:06:13 +0900 Subject: [PATCH 109/134] =?UTF-8?q?docs:=20resource=20>=20data=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/{ => data}/blacklist.csv | 0 src/main/resources/data/data.sql | 4 ++++ src/main/resources/data/schema.sql | 9 --------- src/main/resources/data/voucher_data.json | 1 + src/main/resources/sample_data.json | 12 ------------ src/main/resources/voucher_data.json | 1 - 6 files changed, 5 insertions(+), 22 deletions(-) rename src/main/resources/{ => data}/blacklist.csv (100%) create mode 100644 src/main/resources/data/data.sql create mode 100644 src/main/resources/data/voucher_data.json delete mode 100644 src/main/resources/sample_data.json delete mode 100644 src/main/resources/voucher_data.json diff --git a/src/main/resources/blacklist.csv b/src/main/resources/data/blacklist.csv similarity index 100% rename from src/main/resources/blacklist.csv rename to src/main/resources/data/blacklist.csv diff --git a/src/main/resources/data/data.sql b/src/main/resources/data/data.sql new file mode 100644 index 0000000000..3a181166f3 --- /dev/null +++ b/src/main/resources/data/data.sql @@ -0,0 +1,4 @@ +# Customers 테스트 데이터 삽입 +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '정의진', '정의진@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '김현우', '김현우@gmail.com'); +INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '이세희', '이세희@gmail.com'); diff --git a/src/main/resources/data/schema.sql b/src/main/resources/data/schema.sql index 5fd271ad4b..f2a63b6315 100644 --- a/src/main/resources/data/schema.sql +++ b/src/main/resources/data/schema.sql @@ -1,7 +1,3 @@ -CREATE DATABASE IF NOT EXISTS voucher_mgmt_system; - -USE voucher_mgmt_system; - DROP TABLE IF EXISTS vouchers; DROP TABLE IF EXISTS customers; @@ -14,11 +10,6 @@ CREATE TABLE customers ( CONSTRAINT unq_customer_email UNIQUE KEY (email) ); -# 테스트 데이터 삽입 -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '정의진', '정의진@gmail.com'); -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '김현우', '김현우@gmail.com'); -INSERT INTO customers(customer_id, name, email) VALUES (UUID_TO_BIN(UUID()), '이세희', '이세희@gmail.com'); - CREATE TABLE `vouchers` ( voucher_id BIGINT NOT NULL, voucher_type ENUM('FIXED','PERCENT') NOT NULL, diff --git a/src/main/resources/data/voucher_data.json b/src/main/resources/data/voucher_data.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/src/main/resources/data/voucher_data.json @@ -0,0 +1 @@ +[] diff --git a/src/main/resources/sample_data.json b/src/main/resources/sample_data.json deleted file mode 100644 index c9314c9b13..0000000000 --- a/src/main/resources/sample_data.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "id": "bf095f82-7c2e-446d-9dd4-81a752bc7f8e", - "percent": 50, - "type": "PERCENT" - }, - { - "amount": 1000, - "id": "b3f3d7c7-44b5-4d32-a442-d77c29ebac99", - "type": "FIXED" - } -] diff --git a/src/main/resources/voucher_data.json b/src/main/resources/voucher_data.json deleted file mode 100644 index 3055141aa4..0000000000 --- a/src/main/resources/voucher_data.json +++ /dev/null @@ -1 +0,0 @@ -[{"id":"b4f46542-29f4-49a1-86fd-599aa1e684fb","type":"FIXED"}] \ No newline at end of file From 894ac027e476389504470f284c0059d5c243fdb1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:05:25 +0900 Subject: [PATCH 110/134] =?UTF-8?q?test:=20VoucherViewController=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherViewControllerTest.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherViewControllerTest.java diff --git a/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherViewControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherViewControllerTest.java new file mode 100644 index 0000000000..30f02865a9 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherViewControllerTest.java @@ -0,0 +1,114 @@ +package team.marco.voucher_management_system.controller.voucher; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.ModelAndViewAssert; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.web.servlet.ModelAndView; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.service.voucher.VoucherService; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; + +@WebMvcTest(controllers = VoucherViewController.class) +class VoucherViewControllerTest { + @Autowired + private MockMvc mockMvc; + + @MockBean + private VoucherService voucherService; + + @DisplayName("전체 쿠폰 목록을 조회할 수 있다.") + @Test + void findAllVouchers() throws Exception { + // given + List vouchers = new ArrayList<>(); + + when(voucherService.getVouchers()).thenReturn(vouchers); + + // when + MvcResult mvcResult = mockMvc.perform( + get("/vouchers") + ).andExpect(status().isOk()).andReturn(); + + // then + ModelAndView modelAndView = mvcResult.getModelAndView(); + ModelAndViewAssert.assertViewName(modelAndView, "voucher/voucher_list"); + } + + @DisplayName("쿠폰 ID로 쿠폰 상세 정보를 조회할 수 있다.") + @Test + void findVoucher() throws Exception { + // given + Voucher voucher = new Voucher.Builder(1L, FIXED, 1_000).build(); + + when(voucherService.getVoucher(voucher.getId())).thenReturn(voucher); + + // when + MvcResult mvcResult = mockMvc.perform( + get("/vouchers/{voucherId}", 1L) + ).andExpect(status().isOk()).andReturn(); + + // then + ModelAndView modelAndView = mvcResult.getModelAndView(); + ModelAndViewAssert.assertViewName(modelAndView, "voucher/voucher_detail"); + } + + @DisplayName("쿠폰 생성 폼 뷰 html 파일을 제공할 수 있다.") + @Test + void findVoucherCreateForm() throws Exception { + // when + MvcResult mvcResult = mockMvc.perform( + get("/vouchers/create") + ).andExpect(status().isOk()).andReturn(); + + // then + ModelAndView modelAndView = mvcResult.getModelAndView(); + ModelAndViewAssert.assertViewName(modelAndView, "voucher/voucher_create_form"); + } + + @DisplayName("쿠폰을 생성할 수 있다.") + @Test + void createVoucher() throws Exception { + // given + String voucherType = FIXED.name(); + int discountValue = 1_000; + + // when + MvcResult mvcResult = mockMvc.perform( + post("/vouchers") + .param("voucherType", voucherType) + .param("discountValue", String.valueOf(discountValue)) + ).andExpect(status().isOk()).andReturn(); + + // then + ModelAndView modelAndView = mvcResult.getModelAndView(); + ModelAndViewAssert.assertViewName(modelAndView, "voucher/voucher_list"); + } + + @DisplayName("쿠폰 ID로 쿠폰을 삭제할 수 있다.") + @Test + void deleteVoucher() throws Exception { + // given + Long voucherId = 1L; + + // when + MvcResult mvcResult = mockMvc.perform( + delete("/vouchers/{voucherId}", voucherId) + ).andExpect(status().isOk()).andReturn(); + + // then + ModelAndView modelAndView = mvcResult.getModelAndView(); + ModelAndViewAssert.assertViewName(modelAndView, "voucher/voucher_list"); + } +} \ No newline at end of file From 24f9489cf7a0b6fdd526276234a1a442b3c087c0 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:06:28 +0900 Subject: [PATCH 111/134] =?UTF-8?q?fix:=20=EC=A0=80=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=EC=97=90=20=EC=A1=B4=EC=9E=AC=ED=95=98=EB=8A=94=20=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=EC=9D=B4=20=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EB=90=98=EB=8A=94=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=EC=9D=98=20=EC=95=84=EC=9D=B4=EB=94=94=EA=B0=80=202L=EC=9D=B4?= =?UTF-8?q?=20=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/voucher/VoucherService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index e6a5fca6f7..39adbc3d8f 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -21,7 +21,7 @@ public VoucherService(VoucherRepository voucherRepository) { @Transactional public Voucher createVoucher(VoucherCreateServiceRequest request) { - Long latestId = voucherRepository.findLatestVoucherId().orElse(1L); + Long latestId = voucherRepository.findLatestVoucherId().orElse(0L); Voucher.Builder builder = new Voucher.Builder(latestId + 1, request.getVoucherType(), request.getDiscountValue()); request.getCode().ifPresent(code -> builder.code(code)); From 1fca23515095e8def3d52cd0c6629839e50f4f69 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:07:26 +0900 Subject: [PATCH 112/134] =?UTF-8?q?feat:=20prod=20profile=EC=9D=84=20defau?= =?UTF-8?q?lt=20profile=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8fd52e58d0..09d5a12d09 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,12 +3,19 @@ application: version: "1.0.0" spring: + profiles: + active: "prod" + datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 username: root password: wtwt + sql: + init: + mode: always + thymeleaf: cache: false check-template-location: false From 05fd8bd093c77c252e97135a8ddc56b265a339e6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:08:14 +0900 Subject: [PATCH 113/134] =?UTF-8?q?test:=20VoucherCreateServiceRequest=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=9E=90=20=EB=B3=80=EA=B2=BD=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20VoucherService=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/VoucherServiceTest.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index 77e8a29265..be1adc6b0c 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -11,7 +11,6 @@ import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; @@ -34,10 +33,7 @@ class VoucherServiceTest { int amount = 1000; VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( FIXED, - amount, - Optional.empty(), - Optional.empty() - ); + amount); // 고정 금액 쿠폰 생성 요청 Voucher returned = voucherService.createVoucher(request); @@ -54,10 +50,7 @@ class VoucherServiceTest { int percent = 10; VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( PERCENT, - percent, - Optional.empty(), - Optional.empty() - ); + percent); // % 금액 쿠폰 생성 요청 Voucher returned = voucherService.createVoucher(request); From 59b3b55a54939b7f367391542e7945370b7043d7 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:59:01 +0900 Subject: [PATCH 114/134] =?UTF-8?q?feat:=20VoucherCreateRequest=EC=97=90?= =?UTF-8?q?=20discountValue=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/dto/VoucherCreateRequest.java | 10 ++++++++++ .../controller/voucher/VoucherControllerTest.java | 4 ++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java index 130d9ea265..6c7040e091 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/dto/VoucherCreateRequest.java @@ -8,6 +8,8 @@ public class VoucherCreateRequest { private int discountValue; public VoucherCreateRequest(VoucherType voucherType, int discountValue) { + validateDiscountValue(discountValue); + this.voucherType = voucherType; this.discountValue = discountValue; } @@ -25,4 +27,12 @@ public VoucherType getVoucherType() { public int getDiscountValue() { return discountValue; } + + private static void validateDiscountValue(int discountValue) { + if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); + } + + private static boolean isNotPositive(int discountValue) { + return discountValue <= 0; + } } diff --git a/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java new file mode 100644 index 0000000000..37b2cc41b0 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java @@ -0,0 +1,4 @@ +import static org.junit.jupiter.api.Assertions.*; +class VoucherControllerTest { + +} \ No newline at end of file From 95d3955e0ef1792a91814499e8d6c1846791a3b6 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 18:59:28 +0900 Subject: [PATCH 115/134] =?UTF-8?q?test:=20VoucherController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../voucher/VoucherControllerTest.java | 103 +++++++++++++++++- 1 file changed, 101 insertions(+), 2 deletions(-) diff --git a/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java index 37b2cc41b0..eb1afa3b19 100644 --- a/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java +++ b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherControllerTest.java @@ -1,4 +1,103 @@ -import static org.junit.jupiter.api.Assertions.*; +package team.marco.voucher_management_system.controller.voucher; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; +import team.marco.voucher_management_system.service.voucher.VoucherService; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.when; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; + +@WebMvcTest(controllers = VoucherController.class) class VoucherControllerTest { - + @MockBean + private VoucherService voucherService; + private VoucherController voucherController; + + @BeforeEach + void setup() { + this.voucherController = new VoucherController(voucherService); + } + + @DisplayName("쿠폰을 생성할 수 있다.") + @Test + void createVoucher() { + // given + VoucherCreateRequest request = new VoucherCreateRequest(FIXED, 1_000); + VoucherCreateServiceRequest serviceRequest = request.toServiceRequest(); + Voucher voucher = new Voucher.Builder(1L, request.getVoucherType(), request.getDiscountValue()).build(); + + when(voucherService.createVoucher(serviceRequest)).thenReturn(voucher); + + // when + voucherController.createVoucher(request); + + // then + assertThatNoException(); + } + + @DisplayName("discountValue가 0이하인 쿠폰 생성 요청은 할 수 없다.") + @Test + void createVoucherWithZeroDiscountValue() { + // given + int zero = 0; + + // when then + assertThatThrownBy(() -> voucherController.createVoucher( + new VoucherCreateRequest(FIXED, zero))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("할인 금액 또는 할인율은 양수입니다."); + } + + @DisplayName("쿠폰 ID로 쿠폰을 조회할 수 있다.") + @Test + void getVoucher() { + // given + Voucher voucher = new Voucher.Builder(1L, FIXED, 1_000).build(); + + when(voucherService.getVoucher(voucher.getId())).thenReturn(voucher); + + // when + VoucherResponse response = voucherController.getVoucher("1"); + + // then + assertThat(response) + .extracting("id", "code", "name") + .containsExactly(1L, voucher.getCode(), voucher.getName()); + } + + @DisplayName("전체 쿠폰 목록을 조회할 수 있다.") + @Test + void getVouchers() { + // given + List vouchers = new ArrayList<>(); + + when(voucherService.getVouchers()).thenReturn(vouchers); + + // when + List response = voucherController.getVouchers(); + + // then + assertThat(response).isNotNull(); + } + + @DisplayName("쿠폰 ID로 쿠폰을 삭제할 수 있다.") + @Test + void deleteVoucher() { + // when + voucherController.deleteVoucher("1"); + + // then + assertThatNoException(); + } } \ No newline at end of file From 5b56f4640d2cd33e91429bd019d6cbc429a87e9e Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 19:21:32 +0900 Subject: [PATCH 116/134] =?UTF-8?q?test:=20CustomerController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CustomerControllerTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java diff --git a/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java new file mode 100644 index 0000000000..51a9cd80eb --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java @@ -0,0 +1,77 @@ +package team.marco.voucher_management_system.controller.customer; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import team.marco.voucher_management_system.domain.customer.Customer; +import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; +import team.marco.voucher_management_system.service.customer.BlacklistService; +import team.marco.voucher_management_system.service.customer.CustomerService; + +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + +@WebMvcTest(controllers = CustomerController.class) +class CustomerControllerTest { + @MockBean + private CustomerService customerService; + + @MockBean + private BlacklistService blacklistService; + + private CustomerController customerController; + + @BeforeEach + void setup() { + this.customerController = new CustomerController(customerService, blacklistService); + } + + @DisplayName("블랙리스트 사용자를 조회할 수 있다.") + @Test + void getBlacklistInfo() { + // given + List blacklist = new ArrayList<>(); + + when(blacklistService.getBlacklist()).thenReturn(blacklist); + + // when + List result = customerController.getBlacklistInfo(); + + // then + assertThat(result).isNotNull(); + } + + @DisplayName("존재하는 사용자인지 확인할 수 있다.") + @Test + void isExistCustomerWhenExist() { + // given + Customer customer = new Customer.Builder("name", "email@gmail.com").build(); + when(customerService.findCustomer(customer.getId())).thenReturn(customer); + + // when + boolean result = customerController.isExistCustomer(customer.getId().toString()); + + // then + assertThat(result).isTrue(); + } + + @DisplayName("존재하지 않는 사용자가 존재하는지 요청하면 확인할 수 있다.") + @Test + void isExistCustomerWhenNotExist() { + // given + Customer customer = new Customer.Builder("name", "email@gmail.com").build(); + when(customerService.findCustomer(customer.getId())).thenThrow(NoSuchElementException.class); + + // when + boolean result = customerController.isExistCustomer(customer.getId().toString()); + + // then + assertThat(result).isFalse(); + } +} \ No newline at end of file From 7b27225d3ea71826c06e11fe1b3412ca9a0310f1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sat, 4 Nov 2023 23:22:04 +0900 Subject: [PATCH 117/134] =?UTF-8?q?feat:=20=EB=B0=94=EC=9A=B0=EC=B2=98=20R?= =?UTF-8?q?estAPI=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 조회, 생성, 삭제 --- httpRequest/voucher-request.http | 21 +++++++ .../controller/ApiResponse.java | 49 +++++++++++++++++ .../voucher/VoucherApiController.java | 55 +++++++++++++++++++ .../voucher/VoucherViewController.java | 4 +- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 httpRequest/voucher-request.http create mode 100644 src/main/java/team/marco/voucher_management_system/controller/ApiResponse.java create mode 100644 src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java diff --git a/httpRequest/voucher-request.http b/httpRequest/voucher-request.http new file mode 100644 index 0000000000..ba33598f20 --- /dev/null +++ b/httpRequest/voucher-request.http @@ -0,0 +1,21 @@ +### 쿠폰 전체 목록 조회 +GET http://localhost:8080/api/vouchers +Accept: application/json + +### 쿠폰 ID로 조회 +GET http://localhost:8080/api/vouchers/2 +Accept: application/json + +### 쿠폰 생성 +POST http://localhost:8080/api/vouchers +Accept: application/json +Content-Type: application/json + +{ + "voucherType": "FIXED", + "discountValue": 5000 +} + +### 쿠폰 삭제 By 쿠폰 ID +DELETE http://localhost:8080/api/vouchers/1 +Accept: application/json \ No newline at end of file diff --git a/src/main/java/team/marco/voucher_management_system/controller/ApiResponse.java b/src/main/java/team/marco/voucher_management_system/controller/ApiResponse.java new file mode 100644 index 0000000000..cf906f6b3a --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/ApiResponse.java @@ -0,0 +1,49 @@ +package team.marco.voucher_management_system.controller; + +import org.springframework.http.HttpStatus; + +public class ApiResponse { + private int code; + private HttpStatus status; + private String message; + private T data; + + public ApiResponse(HttpStatus status, String message, T data) { + this.code = status.value(); + this.status = status; + this.message = message; + this.data = data; + } + + public static ApiResponse of(HttpStatus httpStatus, String message, T data) { + return new ApiResponse<>(httpStatus, message, data); + } + + public static ApiResponse of(HttpStatus httpStatus, T data) { + return of(httpStatus, httpStatus.name(), data); + } + + public static ApiResponse ok(T data) { + return of(HttpStatus.OK, data); + } + + public static ApiResponse ok() { + return of(HttpStatus.OK, null); + } + + public int getCode() { + return code; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } + + public T getData() { + return data; + } +} \ No newline at end of file diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java new file mode 100644 index 0000000000..c17ac26f11 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java @@ -0,0 +1,55 @@ +package team.marco.voucher_management_system.controller.voucher; + +import org.springframework.web.bind.annotation.*; +import team.marco.voucher_management_system.controller.ApiResponse; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.service.voucher.VoucherService; + +import java.util.List; + +@RestController +@RequestMapping("/api/vouchers") +public class VoucherApiController { + private final VoucherService voucherService; + + public VoucherApiController(VoucherService voucherService) { + this.voucherService = voucherService; + } + + @GetMapping + public ApiResponse> findAllVouchers() { + List vouchers = voucherService.getVouchers().stream() + .map(VoucherResponse::of) + .toList(); + + return ApiResponse.ok(vouchers); + } + + @GetMapping("/{voucherId}") + public ApiResponse getVoucher(@PathVariable Long voucherId) { + VoucherResponse voucher = VoucherResponse.of(voucherService.getVoucher(voucherId)); + + return ApiResponse.ok(voucher); + } + + /** + * TODO 조건별 조회기능 (바우처 생성기간 및 특정 할인 타입별) + */ + + @PostMapping + public ApiResponse createVoucher(@RequestBody VoucherCreateRequest request) { + Voucher voucher = voucherService.createVoucher(request.toServiceRequest()); + VoucherResponse response = VoucherResponse.of(voucher); + + return ApiResponse.ok(response); + } + + @DeleteMapping("/{voucherId}") + public ApiResponse deleteVoucher(@PathVariable Long voucherId) { + voucherService.deleteVoucher(voucherId); + + return ApiResponse.ok(); + } +} diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index 40d9106907..ef6d45bf3f 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -20,7 +20,7 @@ public VoucherViewController(VoucherService voucherService) { this.voucherService = voucherService; } - @GetMapping() + @GetMapping public String findAllVouchers(Model model) { getVouchersAndAddToModel(model); @@ -41,7 +41,7 @@ public String findVoucherCreateForm() { return "voucher/voucher_create_form"; } - @PostMapping() + @PostMapping public String createVoucher(@RequestParam("voucherType") String voucherType, @RequestParam("discountValue") int discountValue, Model model) { From a1f374f1c9846f887702544a882921e6df2e24c1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 00:59:50 +0900 Subject: [PATCH 118/134] =?UTF-8?q?feat:=20=ED=95=A0=EC=9D=B8=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EB=B3=84=20=EC=BF=A0=ED=8F=B0=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- httpRequest/voucher-request.http | 4 + .../voucher/VoucherApiController.java | 20 ++- .../voucher/JdbcVoucherRepository.java | 11 ++ .../voucher/JsonFileVoucherRepository.java | 12 ++ .../voucher/MemoryVoucherRepository.java | 12 ++ .../repository/voucher/VoucherRepository.java | 3 + .../service/voucher/VoucherService.java | 4 + .../voucher/VoucherApiControllerTest.java | 125 ++++++++++++++++++ .../voucher/JdbcVoucherRepositoryTest.java | 17 +++ .../JsonFileVoucherRepositoryTest.java | 17 +++ .../voucher/MemoryVoucherRepositoryTest.java | 17 +++ .../service/VoucherServiceTest.java | 18 +++ 12 files changed, 253 insertions(+), 7 deletions(-) create mode 100644 src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherApiControllerTest.java diff --git a/httpRequest/voucher-request.http b/httpRequest/voucher-request.http index ba33598f20..cef34bf215 100644 --- a/httpRequest/voucher-request.http +++ b/httpRequest/voucher-request.http @@ -2,6 +2,10 @@ GET http://localhost:8080/api/vouchers Accept: application/json +### 쿠폰 타입으로 조회 +GET http://localhost:8080/api/vouchers?voucherType=FIXED +Accept: application/json + ### 쿠폰 ID로 조회 GET http://localhost:8080/api/vouchers/2 Accept: application/json diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java index c17ac26f11..bab6b79d53 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherApiController.java @@ -1,10 +1,12 @@ package team.marco.voucher_management_system.controller.voucher; +import jakarta.annotation.Nullable; import org.springframework.web.bind.annotation.*; import team.marco.voucher_management_system.controller.ApiResponse; import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.service.voucher.VoucherService; import java.util.List; @@ -19,10 +21,18 @@ public VoucherApiController(VoucherService voucherService) { } @GetMapping - public ApiResponse> findAllVouchers() { + public ApiResponse> findAllVouchers(@Nullable @RequestParam VoucherType voucherType) { + if(voucherType != null) { + List vouchers = voucherService.getVouchersByVoucherType(voucherType).stream() + .map(VoucherResponse::of) + .toList(); + + return ApiResponse.ok(vouchers); + } + List vouchers = voucherService.getVouchers().stream() - .map(VoucherResponse::of) - .toList(); + .map(VoucherResponse::of) + .toList(); return ApiResponse.ok(vouchers); } @@ -34,10 +44,6 @@ public ApiResponse getVoucher(@PathVariable Long voucherId) { return ApiResponse.ok(voucher); } - /** - * TODO 조건별 조회기능 (바우처 생성기간 및 특정 할인 타입별) - */ - @PostMapping public ApiResponse createVoucher(@RequestBody VoucherCreateRequest request) { Voucher voucher = voucherService.createVoucher(request.toServiceRequest()); diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index 9ed923428e..f2462eb426 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -22,6 +22,7 @@ public class JdbcVoucherRepository implements VoucherRepository { private static final String INSERT_SQL = "INSERT INTO vouchers(voucher_id, voucher_type, discount_value, code, name) VALUES (?, ?, ?, ?, ?)"; private static final String SELECT_ALL_SQL = "SELECT * FROM vouchers"; + private static final String SELECT_ALL_BY_TYPE_SQL = "SELECT * FROM vouchers WHERE voucher_type = ?"; private static final String SELECT_BY_ID_SQL = "SELECT * FROM vouchers WHERE voucher_id = ?"; private static final String DELETE_BY_ID_SQL = "DELETE From vouchers WHERE voucher_id = ?"; private static final String SELECT_MAXIMUM_ID = "SELECT v.voucher_id From vouchers v ORDER BY voucher_id DESC LIMIT 1"; @@ -61,6 +62,16 @@ public List findAll() { return Collections.unmodifiableList(vouchers); } + @Override + public List findAllByVoucherType(VoucherType type) { + List vouchers = new ArrayList<>(); + jdbcTemplate.query(SELECT_ALL_BY_TYPE_SQL + , (resultSet, rowNum) -> vouchers.add(resultSetToVoucher(resultSet)) + , type.name()); + + return Collections.unmodifiableList(vouchers); + } + @Override public Optional findById(Long voucherId) { return Optional.of(jdbcTemplate.queryForObject(SELECT_BY_ID_SQL diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java index 9dc22eef4b..f29b536af6 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepository.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import java.io.File; import java.io.IOException; @@ -62,6 +63,13 @@ public List findAll() { .toList(); } + @Override + public List findAllByVoucherType(VoucherType type) { + return voucherMap.values().stream() + .filter(v -> isSameType(type, v)) + .toList(); + } + @Override public Optional findById(Long voucherId) { if(voucherMap.containsKey(voucherId)) { @@ -89,4 +97,8 @@ public void destroy() { throw new UncheckedIOException(e); } } + + private static boolean isSameType(VoucherType type, Voucher v) { + return v.getVoucherType() == type; + } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java index e041baf6cf..00153896f4 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepository.java @@ -2,6 +2,7 @@ import org.springframework.stereotype.Repository; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import java.util.Comparator; import java.util.List; @@ -26,6 +27,13 @@ public List findAll() { .toList(); } + @Override + public List findAllByVoucherType(VoucherType type) { + return voucherMap.values().stream() + .filter(v -> isSameType(type, v)) + .toList(); + } + @Override public Optional findById(Long voucherId) { if(voucherMap.containsKey(voucherId)) { @@ -43,4 +51,8 @@ public Optional findLatestVoucherId() { return voucherMap.keySet().stream() .max(Comparator.naturalOrder()); } + + private static boolean isSameType(VoucherType type, Voucher v) { + return v.getVoucherType() == type; + } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java index c5d7901d7e..b1e1248899 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java @@ -1,6 +1,7 @@ package team.marco.voucher_management_system.repository.voucher; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import java.util.List; import java.util.Optional; @@ -9,6 +10,8 @@ public interface VoucherRepository { Voucher save(Voucher voucher); List findAll(); + + List findAllByVoucherType(VoucherType type); Optional findById(Long voucherId); diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index 39adbc3d8f..2d7ad02214 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import java.util.List; @@ -34,6 +35,9 @@ public Voucher createVoucher(VoucherCreateServiceRequest request) { public List getVouchers() { return voucherRepository.findAll(); } + public List getVouchersByVoucherType(VoucherType type) { + return voucherRepository.findAllByVoucherType(type); + } public Voucher getVoucher(Long voucherId) { return voucherRepository.findById(voucherId).orElseThrow(); diff --git a/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherApiControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherApiControllerTest.java new file mode 100644 index 0000000000..a5769a7000 --- /dev/null +++ b/src/test/java/team/marco/voucher_management_system/controller/voucher/VoucherApiControllerTest.java @@ -0,0 +1,125 @@ +package team.marco.voucher_management_system.controller.voucher; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; +import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; +import team.marco.voucher_management_system.service.voucher.VoucherService; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; + +@WebMvcTest(controllers = VoucherApiController.class) +class VoucherApiControllerTest { + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private VoucherService voucherService; + + @DisplayName("전체 쿠폰 목록을 조회할 수 있다.") + @Test + void findAllVouchers() throws Exception { + // given + List vouchers = new ArrayList<>(); + + when(voucherService.getVouchers()).thenReturn(vouchers); + + // when then + mockMvc.perform( + get("/api/vouchers") + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("200")) + .andExpect(jsonPath("$.status").value("OK")) + .andExpect(jsonPath("$.message").value("OK")) + .andExpect(jsonPath("$.data").isArray()); + } + + @DisplayName("쿠폰 유형을 넘기면 해당 유형의 쿠폰 목록을 조회할 수 있다.") + @Test + void findAllVouchersWithVoucherType() throws Exception { + // given + VoucherType voucherType = FIXED; + List vouchers = new ArrayList<>(); + + when(voucherService.getVouchers()).thenReturn(vouchers); + + // when then + mockMvc.perform( + get("/api/vouchers") + .param("voucherType", voucherType.name()) + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("200")) + .andExpect(jsonPath("$.status").value("OK")) + .andExpect(jsonPath("$.message").value("OK")) + .andExpect(jsonPath("$.data").isArray()); + } + + @DisplayName("쿠폰 ID로 쿠폰 상세 정보를 조회할 수 있다.") + @Test + void getVoucher() throws Exception { + // given + Voucher voucher = new Voucher.Builder(1L, FIXED, 1_000).build(); + + when(voucherService.getVoucher(voucher.getId())).thenReturn(voucher); + + // when then + mockMvc.perform( + get("/api/vouchers/{voucherId}", 1L) + ) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("200")) + .andExpect(jsonPath("$.status").value("OK")) + .andExpect(jsonPath("$.message").value("OK")) + .andExpect(jsonPath("$.data.id").value(voucher.getId())) + .andExpect(jsonPath("$.data.code").value(voucher.getCode().toString())) + .andExpect(jsonPath("$.data.name").value(voucher.getName())); + } + + @DisplayName("쿠폰을 생성할 수 있다.") + @Test + void createVoucher() throws Exception { + // given + VoucherCreateRequest request = new VoucherCreateRequest(FIXED, 1000); + Voucher voucher = new Voucher.Builder(1L, FIXED, 1000).build(); + when(voucherService.createVoucher(any())).thenReturn(voucher); + + // when then + mockMvc.perform( + post("/api/vouchers") + .content(objectMapper.writeValueAsString(request)) + .contentType(MediaType.APPLICATION_JSON) + ).andExpect(status().isOk()); + } + + @DisplayName("쿠폰 ID로 쿠폰을 삭제할 수 있다.") + @Test + void deleteVoucher() throws Exception { + // given + Long voucherId = 1L; + + // when + mockMvc.perform( + delete("/api/vouchers/{voucherId}", voucherId) + ).andExpect(status().isOk()).andReturn(); + } +} \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 90223982c9..321bdc0671 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -61,6 +61,23 @@ void setUp() { assertThat(vouchers).hasSize(2); } + @DisplayName("특정 쿠폰 종류에 해당하는 쿠폰 목록을 조회할 수 있습니다.") + @Test + void findAllByVoucherType() { + // given + Voucher fixedVoucher = createFixedVoucher(1L, 1000); + voucherRepository.save(fixedVoucher); + + Voucher percentVoucher = createPercentVoucher(2L, 10); + voucherRepository.save(percentVoucher); + + // when + List found = voucherRepository.findAllByVoucherType(FIXED); + + // then + assertThat(found).hasSize(1); + } + @Test void 쿠폰_아이디로_조회_성공() { // 1,000원 할인 쿠폰 생성 diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java index 4df16b06dc..1b562953aa 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java @@ -52,6 +52,23 @@ void findAll() { assertThat(vouchers).hasSize(2); } + @DisplayName("특정 쿠폰 종류에 해당하는 쿠폰 목록을 조회할 수 있습니다.") + @Test + void findAllByVoucherType() { + // given + Voucher fixedVoucher = createFixedVoucher(1L, 1000); + fileVoucherRepository.save(fixedVoucher); + + Voucher percentVoucher = createPercentVoucher(2L, 10); + fileVoucherRepository.save(percentVoucher); + + // when + List found = fileVoucherRepository.findAllByVoucherType(FIXED); + + // then + assertThat(found).hasSize(1); + } + @DisplayName("쿠폰 id로 쿠폰을 검색할 수 있다.") @Test void findById() { diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java index a153ead4ba..ba2adb42e9 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/MemoryVoucherRepositoryTest.java @@ -53,6 +53,23 @@ void findAll() { assertThat(vouchers).hasSize(2); } + @DisplayName("특정 쿠폰 종류에 해당하는 쿠폰 목록을 조회할 수 있습니다.") + @Test + void findAllByVoucherType() { + // given + Voucher fixedVoucher = createFixedVoucher(1L, 1000); + voucherRepository.save(fixedVoucher); + + Voucher percentVoucher = createPercentVoucher(2L, 10); + voucherRepository.save(percentVoucher); + + // when + List found = voucherRepository.findAllByVoucherType(FIXED); + + // then + assertThat(found).hasSize(1); + } + @DisplayName("쿠폰 id로 쿠폰을 검색할 수 있다.") @Test void findById() { diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index be1adc6b0c..1ab669b0ae 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; import team.marco.voucher_management_system.domain.voucher.Voucher; +import team.marco.voucher_management_system.domain.voucher.VoucherType; import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; @@ -91,6 +92,23 @@ class VoucherServiceTest { assertThat(returned).hasSize(2); } + @DisplayName("특정 쿠폰 유형에 해당하는 쿠폰 목록을 조회할 수 있습니다.") + @Test + void getVouchersByVoucherType() { + // given + VoucherType voucherType = FIXED; + Voucher fixedVoucher = createFixedVoucher(1L, 1000); + Voucher percentVoucher = createPercentVoucher(2L, 10); + voucherRepository.save(fixedVoucher); + voucherRepository.save(percentVoucher); + + // when + List found = voucherService.getVouchersByVoucherType(voucherType); + + // then + assertThat(found).hasSize(1); + } + @Test void 쿠폰_아이디로_조회() { // 쿠폰 생성 From 9886727a29b3ca0df9c061e83f4d77de9e4d0da1 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 04:10:12 +0900 Subject: [PATCH 119/134] =?UTF-8?q?test:=20Service=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=9C=20MemoryRepositoy=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=97=90=EC=84=9C=20JdbcRepository=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 28 +++++++++------ src/main/resources/data/schema.sql | 34 +++++++++++++++++-- .../custromer/CsvBlacklistRepositoryTest.java | 3 -- .../custromer/JdbcCustomerRepositoryTest.java | 4 +-- .../voucher/JdbcVoucherRepositoryTest.java | 6 ++-- .../JsonFileVoucherRepositoryTest.java | 2 -- .../service/CustomerServiceTest.java | 4 +-- .../service/VoucherServiceTest.java | 20 ++++++++--- 8 files changed, 71 insertions(+), 30 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 09d5a12d09..eb62e25290 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,16 +6,6 @@ spring: profiles: active: "prod" - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: root - password: wtwt - - sql: - init: - mode: always - thymeleaf: cache: false check-template-location: false @@ -32,11 +22,29 @@ file: spring: profiles: active: "prod" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw --- spring: profiles: active: "dev" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw --- spring: profiles: active: "test" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/test_voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw diff --git a/src/main/resources/data/schema.sql b/src/main/resources/data/schema.sql index f2a63b6315..011015170e 100644 --- a/src/main/resources/data/schema.sql +++ b/src/main/resources/data/schema.sql @@ -1,3 +1,35 @@ +DROP DATABASE IF EXISTS voucher_mgmt_system; +DROP DATABASE IF EXISTS test_voucher_mgmt_system; + +CREATE DATABASE voucher_mgmt_system; +CREATE DATABASE test_voucher_mgmt_system; + +USE voucher_mgmt_system; + +DROP TABLE IF EXISTS vouchers; +DROP TABLE IF EXISTS customers; + +CREATE TABLE customers ( + customer_id BINARY(16) NOT NULL, + name VARCHAR(20) NOT NULL, + email VARCHAR(50) NOT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT pk_customer_id PRIMARY KEY (customer_id), + CONSTRAINT unq_customer_email UNIQUE KEY (email) +); + +CREATE TABLE `vouchers` ( + voucher_id BIGINT NOT NULL, + voucher_type ENUM('FIXED','PERCENT') NOT NULL, + discount_value INTEGER NOT NULL, + code BINARY(16) NOT NULL, + name VARCHAR(50) DEFAULT NULL, + CONSTRAINT pk_voucher_id PRIMARY KEY (voucher_id), + CONSTRAINT unq_code UNIQUE KEY (code) +); + +USE test_voucher_mgmt_system; + DROP TABLE IF EXISTS vouchers; DROP TABLE IF EXISTS customers; @@ -19,5 +51,3 @@ CREATE TABLE `vouchers` ( CONSTRAINT pk_voucher_id PRIMARY KEY (voucher_id), CONSTRAINT unq_code UNIQUE KEY (code) ); - - diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java index caea798a7f..22ea3b7d42 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.test.context.ActiveProfiles; import java.util.List; @@ -10,9 +9,7 @@ import static org.assertj.core.groups.Tuple.tuple; import static team.marco.voucher_management_system.util.UUIDUtil.stringToUUID; -@ActiveProfiles("test") class CsvBlacklistRepositoryTest { - private CsvBlacklistRepository csvBlacklistRepository; public CsvBlacklistRepositoryTest() { diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index ad95cc4ccd..e9e67fded8 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -9,7 +9,6 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.annotation.Transactional; import team.marco.voucher_management_system.domain.customer.Customer; import java.util.List; @@ -17,9 +16,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -@Transactional @SpringBootTest -@ActiveProfiles("prod") +@ActiveProfiles("test") class JdbcCustomerRepositoryTest { @Autowired private JdbcCustomerRepository customerRepository; diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 321bdc0671..56fd28a740 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -16,8 +16,8 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -@SpringBootTest -@ActiveProfiles("prod") +@JdbcTest +@ActiveProfiles("test") class JdbcVoucherRepositoryTest { @Autowired private JdbcVoucherRepository voucherRepository; diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java index 1b562953aa..c8a611170f 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java @@ -2,7 +2,6 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; @@ -13,7 +12,6 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -@ActiveProfiles("test") class JsonFileVoucherRepositoryTest { private JsonFileVoucherRepository fileVoucherRepository; diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java index b54b19068d..83f5787a2a 100644 --- a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -5,15 +5,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.transaction.annotation.Transactional; +import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.repository.custromer.CustomerRepository; import team.marco.voucher_management_system.service.customer.CustomerService; import static org.assertj.core.api.Assertions.assertThat; -@Transactional @SpringBootTest +@ActiveProfiles("test") class CustomerServiceTest { @Autowired private CustomerService customerService; diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index 1ab669b0ae..cf09ada8cf 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -3,10 +3,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; import team.marco.voucher_management_system.domain.voucher.Voucher; import team.marco.voucher_management_system.domain.voucher.VoucherType; -import team.marco.voucher_management_system.repository.voucher.MemoryVoucherRepository; import team.marco.voucher_management_system.repository.voucher.VoucherRepository; import team.marco.voucher_management_system.service.voucher.VoucherCreateServiceRequest; import team.marco.voucher_management_system.service.voucher.VoucherService; @@ -17,15 +20,22 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; +@SpringBootTest +@ActiveProfiles("test") class VoucherServiceTest { + @Autowired private VoucherService voucherService; + + @Autowired private VoucherRepository voucherRepository; + @Autowired + private JdbcTemplate jdbcTemplate; + @BeforeEach - @DisplayName("각 테스트는 빈 메모리 저장소를 가지고 테스트를 시작합니다.") - void VoucherService_초기화() { - voucherRepository = new MemoryVoucherRepository(); - voucherService = new VoucherService(voucherRepository); + void setUp() { + String query = "DELETE FROM vouchers"; + jdbcTemplate.update(query); } @Test From 06a2b217559f0bfc5b2aae205be8f67cca2c5dfe Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 05:01:51 +0900 Subject: [PATCH 120/134] =?UTF-8?q?refactor:=20ConsoleVoucherApplication?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드 분리, 상수 분리 --- .../VoucherManagementSystemApplication.java | 4 +- ...on.java => ConsoleVoucherApplication.java} | 51 ++++++++++++------- .../view/consoleapp/ServiceType.java | 20 +++++--- 3 files changed, 48 insertions(+), 27 deletions(-) rename src/main/java/team/marco/voucher_management_system/view/consoleapp/{VoucherApplication.java => ConsoleVoucherApplication.java} (69%) diff --git a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java index fafbcfd7c9..a4e79c6ca0 100644 --- a/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java +++ b/src/main/java/team/marco/voucher_management_system/VoucherManagementSystemApplication.java @@ -3,7 +3,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import team.marco.voucher_management_system.view.consoleapp.VoucherApplication; +import team.marco.voucher_management_system.view.consoleapp.ConsoleVoucherApplication; @SpringBootApplication public class VoucherManagementSystemApplication { @@ -11,7 +11,7 @@ public class VoucherManagementSystemApplication { public static void main(String[] args) { ApplicationContext context = SpringApplication.run(VoucherManagementSystemApplication.class, args); - VoucherApplication application = context.getBean(VoucherApplication.class); + ConsoleVoucherApplication application = context.getBean(ConsoleVoucherApplication.class); application.run(); } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java similarity index 69% rename from src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java rename to src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java index 119f86821b..9d0edaa53a 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/VoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java @@ -11,58 +11,71 @@ import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; @Component -public class VoucherApplication { - private static final Logger logger = LoggerFactory.getLogger(VoucherApplication.class); - +public class ConsoleVoucherApplication implements Runnable { + private static final Logger logger = LoggerFactory.getLogger(ConsoleVoucherApplication.class); + private final WalletApplication walletApplication; private final ManagementApplication managementApplication; private Boolean isRunning; - public VoucherApplication(WalletApplication walletApplication, ManagementApplication managementApplication) { + public ConsoleVoucherApplication(WalletApplication walletApplication, ManagementApplication managementApplication) { this.walletApplication = walletApplication; this.managementApplication = managementApplication; this.isRunning = true; } + @Override public void run() { while (isRunning) { - try { - selectService(); - } catch (Exception e) { - handleException(e); - } + provideLauncher(); + } + } + + private void provideLauncher() { + try { + provideServiceManual(); + ServiceType input = getServiceRequest(); + handleServiceRequest(input); + } catch (Exception e) { + handleException(e); } } - public void selectService() { + private void provideServiceManual() { ConsoleUtil.print(MAIN_HEADER); for(ServiceType type : ServiceType.values()) { - ConsoleUtil.print(type.getInfo()); + ConsoleUtil.print(type.getManual()); } ConsoleUtil.println(); + } + public ServiceType getServiceRequest() { ConsoleUtil.print(SELECT_SERVICE); int input = ConsoleUtil.readInt(); - ServiceType type = ServiceType.get(input); - switch (type) { + return ServiceType.get(input); + } + + public void handleServiceRequest(ServiceType requestedServiceType) { + switch (requestedServiceType) { case MANAGEMENT -> runManagementApplication(); case WALLET -> runWalletApplication(); - case EXIT -> close(); + case EXIT -> exitProgram(); } } - private void runWalletApplication() { - walletApplication.run(); - } private void runManagementApplication() { managementApplication.run(); } - private void close() { + private void runWalletApplication() { + walletApplication.run(); + } + + private void exitProgram() { logger.info("Call close()"); isRunning = false; @@ -87,6 +100,6 @@ private void handleException(Exception e) { isRunning = false; - close(); + exitProgram(); } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java index 652e0895b5..5910b5527a 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java @@ -2,10 +2,14 @@ import java.util.Arrays; +import static java.text.MessageFormat.format; + public enum ServiceType { - EXIT(1, "프로그램 종료"), - MANAGEMENT(2, "관리자 서비스"), - WALLET(3, "회원 지갑 서비스"); + EXIT(1, "프로그램을 종료합니다."), + MANAGEMENT(2, "관리자 서비스로 이동합니다."), + WALLET(3, "회원 지갑 서비스로 이동합니다."); + + private static final String SERVICE_NOT_EXIST = "해당 서비스가 존재하지 않습니다."; private final int num; private final String description; @@ -17,16 +21,20 @@ public enum ServiceType { static ServiceType get(int num) { return Arrays.stream(ServiceType.values()) - .filter(v -> v.getNum() == num) + .filter(v -> isEqual(num, v.getNum())) .findAny() - .orElseThrow(); + .orElseThrow(() -> new IllegalArgumentException(format(SERVICE_NOT_EXIST))); + } + + private static boolean isEqual(int targetNum, int serviceNum) { + return targetNum == serviceNum; } public int getNum() { return num; } - public String getInfo() { + public String getManual() { return num + ". " + description; } } From d8baa9b416839fab7e0f3dc38b3b8bbb8a8d4dd5 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 12:43:06 +0900 Subject: [PATCH 121/134] =?UTF-8?q?refactor:=20=EC=BD=98=EC=86=94=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=95=88=EC=97=90=EC=84=9C=20=EC=83=81=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=80=EC=9E=A5=ED=95=98=EA=B3=A0=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A7=8C=20=EB=B3=84?= =?UTF-8?q?=EB=8F=84=EC=9D=98=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../error/ErrorMessage.java | 9 ++++ .../view/consoleapp/ConsoleMessage.java | 24 --------- .../view/consoleapp/ConsoleUtil.java | 50 +++++++++---------- .../consoleapp/ConsoleVoucherApplication.java | 10 ++-- .../management/ManagementApplication.java | 12 ++++- .../consoleapp/wallet/WalletApplication.java | 8 ++- 6 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java delete mode 100644 src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java diff --git a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java new file mode 100644 index 0000000000..b4c53b20db --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java @@ -0,0 +1,9 @@ +package team.marco.voucher_management_system.error; + +public class ErrorMessage { + public static final String CUSTOMER_ID_INVALID = "올바른 사용자 아이디가 아닙니다."; + public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; + public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; + public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; + public static final String PROGRAM_ERROR = "프로그램에 에러가 발생했습니다."; +} diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java deleted file mode 100644 index d2742161f2..0000000000 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleMessage.java +++ /dev/null @@ -1,24 +0,0 @@ -package team.marco.voucher_management_system.view.consoleapp; - -public class ConsoleMessage { - public static final String MANAGEMENT_HEADER = "==== 관리자 페이지 ===="; - public static final String MAIN_HEADER = "==== 메인 페이지 ===="; - public static final String WALLET_HEADER = "==== 지갑 페이지 ===="; - public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; - public static final String VOUCHER_MANUAL = """ - 1: $ 할인 쿠폰 - 2: % 할인 쿠폰"""; - public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; - public static final String DISCOUNT_PERCENT_REQUEST = "할인율을 입력해 주세요."; - public static final String DISCOUNT_AMOUNT_REQUEST = "할인 금액을 입력해 주세요."; - public static final String VOUCHER_CREATE_COMPLETE = "쿠폰 생성이 완료되었습니다."; - public static final String INQUIRY_COMPLETE = "조회가 완료되었습니다."; - public static final String PROGRAM_EXIT = "프로그램이 종료되었습니다."; - public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; - public static final String PROGRAM_ERROR = "프로그램에 에러가 발생했습니다."; - public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; - public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; - public static final String CUSTOMER_ID_REQUEST = "사용자 아이디를 입력해주세요."; - public static final String CUSTOMER_ID_INVALID = "올바른 사용자 아이디가 아닙니다."; - public static final String VOUCHER_DELETE_COMPLETE = "쿠폰 삭제가 완료되었습니다."; -} diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index 953b774b61..5d159962af 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -10,38 +10,28 @@ import java.util.Objects; import static java.text.MessageFormat.format; -import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.INQUIRY_COMPLETE; -import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.WRONG_INPUT; +import static team.marco.voucher_management_system.error.ErrorMessage.WRONG_INPUT; public final class ConsoleUtil { - private static final String INFO_DELIMINATOR = "\n"; private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + private static final String INFO_DELIMINATOR = "\n"; + private static final String SEPARATOR_LINE = "--------------------"; private ConsoleUtil() { // Don't let anyone instantiate this class. } public static void print(Object object) { - System.out.print(object + System.lineSeparator()); - } - - public static void println(Object object) { - print(object); - System.out.println(); + System.out.println(object); } public static void println() { System.out.println(); } - public static void printStringList(List list) { - String joinedString = String.join(INFO_DELIMINATOR, list); - - if (!joinedString.isBlank()) { - ConsoleUtil.println(joinedString); - } - - ConsoleUtil.println(INQUIRY_COMPLETE); + public static void println(Object object) { + print(object); + println(); } public static String readString() { @@ -60,11 +50,11 @@ public static int readInt() { return Integer.parseInt(readString()); } - private static String readLine() { - try { - return reader.readLine(); - } catch (IOException e) { - throw new UncheckedIOException(e); + public static void printStringList(List list) { + String joinedString = String.join(INFO_DELIMINATOR, list); + + if (!joinedString.isBlank()) { + println(joinedString); } } @@ -75,13 +65,21 @@ public static void printVoucherList(List vouchers) { }); } - private static void printSeparatorLine() { - print("--------------------"); - } - public static void printVoucher(VoucherResponse voucher) { print(format("id : {0}", voucher.getId())); print(format("name : {0}", voucher.getName())); print(format("code : {0}", voucher.getCode())); } + + private static String readLine() { + try { + return reader.readLine(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static void printSeparatorLine() { + print(SEPARATOR_LINE); + } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java index 9d0edaa53a..f1f611a291 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java @@ -8,12 +8,15 @@ import java.io.UncheckedIOException; -import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; +import static team.marco.voucher_management_system.error.ErrorMessage.*; @Component public class ConsoleVoucherApplication implements Runnable { private static final Logger logger = LoggerFactory.getLogger(ConsoleVoucherApplication.class); - + public static final String MAIN_HEADER = "==== 메인 페이지 ===="; + public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; + public static final String PROGRAM_EXIT = "프로그램이 종료되었습니다."; + private final WalletApplication walletApplication; private final ManagementApplication managementApplication; @@ -54,9 +57,8 @@ private void provideServiceManual() { public ServiceType getServiceRequest() { ConsoleUtil.print(SELECT_SERVICE); - int input = ConsoleUtil.readInt(); - return ServiceType.get(input); + return ServiceType.get(ConsoleUtil.readInt()); } public void handleServiceRequest(ServiceType requestedServiceType) { diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 08f1fe65cd..fdb30624f4 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -11,12 +11,22 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; +import static team.marco.voucher_management_system.error.ErrorMessage.*; import static team.marco.voucher_management_system.view.consoleapp.ConsoleUtil.*; @Component public class ManagementApplication { private static final Logger logger = LoggerFactory.getLogger(ManagementApplication.class); + public static final String MANAGEMENT_HEADER = "==== 관리자 페이지 ===="; + public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; + public static final String DISCOUNT_PERCENT_REQUEST = "할인율을 입력해 주세요."; + public static final String DISCOUNT_AMOUNT_REQUEST = "할인 금액을 입력해 주세요."; + public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; + public static final String VOUCHER_CREATE_COMPLETE = "쿠폰 생성이 완료되었습니다."; + public static final String INQUIRY_COMPLETE = "조회가 완료되었습니다."; + public static final String VOUCHER_MANUAL = """ + 1: $ 할인 쿠폰 + 2: % 할인 쿠폰"""; private final VoucherController voucherController; private final CustomerController userController; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index 7c3296f013..a6073b17f9 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -7,11 +7,17 @@ import team.marco.voucher_management_system.controller.voucher.VoucherController; import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; -import static team.marco.voucher_management_system.view.consoleapp.ConsoleMessage.*; +import static team.marco.voucher_management_system.error.ErrorMessage.CUSTOMER_ID_INVALID; +import static team.marco.voucher_management_system.error.ErrorMessage.NUMBER_REQUIRED; @Component public class WalletApplication { private static final Logger logger = LoggerFactory.getLogger(WalletApplication.class); + public static final String CUSTOMER_ID_REQUEST = "사용자 아이디를 입력해주세요."; + public static final String WALLET_HEADER = "==== 지갑 페이지 ===="; + public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; + public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; + public static final String VOUCHER_DELETE_COMPLETE = "쿠폰 삭제가 완료되었습니다."; private final VoucherController voucherController; private final CustomerController customerController; From cd5a13326b09688bd8e1a12fab37fdfa7ee1c756 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:20:49 +0900 Subject: [PATCH 122/134] =?UTF-8?q?docs:=20application.yml=EC=9D=84=20prof?= =?UTF-8?q?ile=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/CustomerIdAndName.java | 21 ---------- src/main/resources/application-dev.yml | 12 ++++++ src/main/resources/application-prod.yml | 11 +++++ src/main/resources/application-test.yml | 11 +++++ src/main/resources/application.yml | 40 +------------------ .../custromer/CsvBlacklistRepositoryTest.java | 10 ++++- .../voucher/JdbcVoucherRepositoryTest.java | 4 +- .../JsonFileVoucherRepositoryTest.java | 9 ++++- 8 files changed, 53 insertions(+), 65 deletions(-) delete mode 100644 src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-prod.yml create mode 100644 src/main/resources/application-test.yml diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java deleted file mode 100644 index bde195f70d..0000000000 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerIdAndName.java +++ /dev/null @@ -1,21 +0,0 @@ -package team.marco.voucher_management_system.repository.custromer; - -import java.util.UUID; - -public class CustomerIdAndName { - private final UUID id; - private final String name; - - public CustomerIdAndName(UUID id, String name) { - this.id = id; - this.name = name; - } - - public UUID getId() { - return id; - } - - public String getName() { - return name; - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000000..0cca9935aa --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,12 @@ +# application-dav.yml +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw + +file: + path: + blacklist: "src/main/resources/data/blacklist.csv" + voucher_data: "src/main/resources/data/voucher_data.json" \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000000..fd00dee326 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,11 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw + +file: + path: + blacklist: "src/main/resources/data/blacklist.csv" + voucher_data: "src/main/resources/data/voucher_data.json" \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml new file mode 100644 index 0000000000..39108f691f --- /dev/null +++ b/src/main/resources/application-test.yml @@ -0,0 +1,11 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3305/test_voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + username: root + password: uijin-mysql-pw + +file: + path: + blacklist: "src/test/resources/test_blacklist.csv" + voucher_data: "src/test/resources/test_voucher_data.json" \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index eb62e25290..f92c3839ea 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,47 +4,11 @@ application: spring: profiles: - active: "prod" + default: prod thymeleaf: cache: false check-template-location: false enabled: true - mvc.hiddenmethod.filter.enabled: true - -file: - path: - blacklist: "src/main/resources/data/blacklist.csv" - voucher_data: "src/main/resources/data/voucher_data.json" - ---- -spring: - profiles: - active: "prod" - - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: root - password: uijin-mysql-pw ---- -spring: - profiles: - active: "dev" - - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3305/voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: root - password: uijin-mysql-pw ---- -spring: - profiles: - active: "test" - - datasource: - driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3305/test_voucher_mgmt_system?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: root - password: uijin-mysql-pw + mvc.hiddenmethod.filter.enabled: true \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java index 22ea3b7d42..f99db43718 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java @@ -2,6 +2,10 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import java.util.List; @@ -9,11 +13,13 @@ import static org.assertj.core.groups.Tuple.tuple; import static team.marco.voucher_management_system.util.UUIDUtil.stringToUUID; +@SpringBootTest +@ActiveProfiles("test") class CsvBlacklistRepositoryTest { private CsvBlacklistRepository csvBlacklistRepository; - public CsvBlacklistRepositoryTest() { - csvBlacklistRepository = new CsvBlacklistRepository("src/test/resources/test_blacklist.csv"); + public CsvBlacklistRepositoryTest(@Value("${file.path.blacklist}") String path) { + csvBlacklistRepository = new CsvBlacklistRepository(path); } @DisplayName("") diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java index 56fd28a740..8acc98eacf 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepositoryTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -16,7 +16,7 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -@JdbcTest +@SpringBootTest @ActiveProfiles("test") class JdbcVoucherRepositoryTest { @Autowired diff --git a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java index c8a611170f..baf3be6ab1 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/voucher/JsonFileVoucherRepositoryTest.java @@ -2,6 +2,9 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.domain.voucher.Voucher; import java.util.List; @@ -12,11 +15,13 @@ import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; +@SpringBootTest +@ActiveProfiles("test") class JsonFileVoucherRepositoryTest { private JsonFileVoucherRepository fileVoucherRepository; - public JsonFileVoucherRepositoryTest() { - fileVoucherRepository = new JsonFileVoucherRepository("src/test/resources/test_voucher_data.json"); + public JsonFileVoucherRepositoryTest(@Value("${file.path.voucher_data}") String path) { + fileVoucherRepository = new JsonFileVoucherRepository(path); } @DisplayName("바우처를 생성할 수 있다.") From 4850a6ee46b11ec0fa330d9e6d346f14cdeec076 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:22:23 +0900 Subject: [PATCH 123/134] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CustomerController.java | 16 ++++++- .../customer/dto/CustomerResponse.java | 33 ++++++++++++++ .../custromer/CustomerRepository.java | 1 + .../custromer/JdbcCustomerRepository.java | 19 +++++--- .../service/customer/CustomerService.java | 17 ++++++- .../customer/CustomerControllerTest.java | 44 +++++++++++++++++-- .../custromer/JdbcCustomerRepositoryTest.java | 16 +++++++ .../service/CustomerServiceTest.java | 19 +++++++- 8 files changed, 152 insertions(+), 13 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerResponse.java diff --git a/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java index b26ee43940..d2df711e23 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java @@ -1,6 +1,8 @@ package team.marco.voucher_management_system.controller.customer; import org.springframework.stereotype.Controller; +import team.marco.voucher_management_system.controller.customer.dto.CustomerResponse; +import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.service.customer.BlacklistService; import team.marco.voucher_management_system.service.customer.CustomerService; @@ -28,10 +30,22 @@ public List getBlacklistInfo() { public boolean isExistCustomer(String customerId) { try { - customerService.findCustomer(UUID.fromString(customerId)); + customerService.findCustomerById(UUID.fromString(customerId)); return true; } catch (NoSuchElementException e) { return false; } } + + public List findAll() { + return customerService.findAllCustomer().stream() + .map(CustomerResponse::of) + .peek(System.out::println) + .toList(); + } + + public Customer findCustomerByEmail(String email) { + Customer customer = customerService.findCustomerByEmail(email); + return customer; + } } diff --git a/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerResponse.java b/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerResponse.java new file mode 100644 index 0000000000..4682bfb176 --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerResponse.java @@ -0,0 +1,33 @@ +package team.marco.voucher_management_system.controller.customer.dto; + +import team.marco.voucher_management_system.domain.customer.Customer; + +import java.time.LocalDateTime; + +public class CustomerResponse { + private String name; + private String email; + private LocalDateTime createdAt; + + public CustomerResponse(String name, String email, LocalDateTime createdAt) { + this.name = name; + this.email = email; + this.createdAt = createdAt; + } + + public static CustomerResponse of(Customer customer) { + return new CustomerResponse(customer.getName(), customer.getEmail(), customer.getCreatedAt()); + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java index 7549a487f9..b3c833e255 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CustomerRepository.java @@ -10,4 +10,5 @@ public interface CustomerRepository { Customer insert(Customer customer); List findAll(); Optional findById(UUID customerId); + Optional findByEmail(String email); } diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index 1e1d0c5fb7..10a8f7291c 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -1,7 +1,5 @@ package team.marco.voucher_management_system.repository.custromer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; @@ -18,10 +16,10 @@ @Repository public class JdbcCustomerRepository implements CustomerRepository { - private static final Logger logger = LoggerFactory.getLogger(JdbcCustomerRepository.class); private static final String SELECT_ALL_SQL = "SELECT * FROM customers"; private static final String SELECT_BY_ID_SQL = "SELECT * FROM customers WHERE customer_id = ?"; + private static final String SELECT_BY_EMAIL_SQL = "SELECT * FROM customers WHERE email = ?"; private static final String INSERT_SQL = "INSERT INTO customers(customer_id, name, email, created_at) VALUES (?, ?, ?, ?)"; private final JdbcTemplate jdbcTemplate; @@ -39,7 +37,6 @@ public Customer insert(Customer customer) { Timestamp.valueOf(customer.getCreatedAt())); if(update != 1) { - logger.error("사용자를 추가하는 과정에서 오류가 발생했습니다."); throw new RuntimeException("사용자를 추가하는 과정에서 오류가 발생했습니다."); } @@ -50,7 +47,6 @@ public Customer insert(Customer customer) { public List findAll() { List customers = new ArrayList<>(); jdbcTemplate.query(SELECT_ALL_SQL, (resultSet, rowNum) -> customers.add(resultSetToCustomer(resultSet))); - return Collections.unmodifiableList(customers); } @@ -67,6 +63,19 @@ public Optional findById(UUID customerId) { } } + @Override + public Optional findByEmail(String email) { + try { + Customer customer = jdbcTemplate.queryForObject(SELECT_BY_EMAIL_SQL, + (resultSet, rowNum) -> resultSetToCustomer(resultSet), + email); + + return Optional.of(customer); + } catch (DataAccessException e) { + return Optional.empty(); + } + } + private Customer resultSetToCustomer(ResultSet resultSet) throws SQLException { UUID id = bytesToUUID(resultSet.getBytes("customer_id")); String name = resultSet.getString("name"); diff --git a/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java b/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java index 6b70f8f10d..a6bcc412d9 100644 --- a/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java +++ b/src/main/java/team/marco/voucher_management_system/service/customer/CustomerService.java @@ -1,11 +1,17 @@ package team.marco.voucher_management_system.service.customer; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.repository.custromer.CustomerRepository; +import java.util.List; import java.util.UUID; +import static team.marco.voucher_management_system.error.ErrorMessage.CUSTOMER_ID_INVALID; +import static team.marco.voucher_management_system.error.ErrorMessage.INVALID_EMAIL; + +@Transactional(readOnly = true) @Service public class CustomerService { private final CustomerRepository customerRepository; @@ -14,7 +20,14 @@ public CustomerService(CustomerRepository customerRepository) { this.customerRepository = customerRepository; } - public Customer findCustomer(UUID customerId) { - return customerRepository.findById(customerId).orElseThrow(); + public List findAllCustomer() { + return customerRepository.findAll(); + } + + public Customer findCustomerById(UUID customerId) { + return customerRepository.findById(customerId).orElseThrow(() -> new IllegalArgumentException(CUSTOMER_ID_INVALID)); + } + public Customer findCustomerByEmail(String email) { + return customerRepository.findByEmail(email).orElseThrow(() -> new IllegalArgumentException(INVALID_EMAIL)); } } diff --git a/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java index 51a9cd80eb..753720927d 100644 --- a/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java +++ b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java @@ -5,8 +5,9 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; +import team.marco.voucher_management_system.controller.customer.dto.CustomerResponse; import team.marco.voucher_management_system.domain.customer.Customer; -import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; import team.marco.voucher_management_system.service.customer.BlacklistService; import team.marco.voucher_management_system.service.customer.CustomerService; @@ -47,12 +48,12 @@ void getBlacklistInfo() { assertThat(result).isNotNull(); } - @DisplayName("존재하는 사용자인지 확인할 수 있다.") + @DisplayName("사용자 ID로 존재하는 사용자인지 확인할 수 있다.") @Test void isExistCustomerWhenExist() { // given Customer customer = new Customer.Builder("name", "email@gmail.com").build(); - when(customerService.findCustomer(customer.getId())).thenReturn(customer); + when(customerService.findCustomerById(customer.getId())).thenReturn(customer); // when boolean result = customerController.isExistCustomer(customer.getId().toString()); @@ -66,7 +67,7 @@ void isExistCustomerWhenExist() { void isExistCustomerWhenNotExist() { // given Customer customer = new Customer.Builder("name", "email@gmail.com").build(); - when(customerService.findCustomer(customer.getId())).thenThrow(NoSuchElementException.class); + when(customerService.findCustomerById(customer.getId())).thenThrow(NoSuchElementException.class); // when boolean result = customerController.isExistCustomer(customer.getId().toString()); @@ -74,4 +75,39 @@ void isExistCustomerWhenNotExist() { // then assertThat(result).isFalse(); } + + @DisplayName("전체 사용자 목록을 확인할 수 있습니다.") + @Test + void findAll() { + // given + Customer customer = new Customer.Builder("name", "email@gmail.com").build(); + List customers = new ArrayList<>(); + customers.add(customer); + + when(customerService.findAllCustomer()).thenReturn(customers); + + // when + List result = customerController.findAll(); + + // then + assertThat(result).hasSize(1); + assertThat(result.get(0)) + .extracting("name", "email") + .containsExactly(customer.getName(), customer.getEmail()); + } + + @DisplayName("사용자 이메일로 사용자를 조회할 수 있다.") + @Test + void findCustomerByEmail() { + // given + String email = "email@gmail.com"; + Customer customer = new Customer.Builder("name", email).build(); + when(customerService.findCustomerByEmail(email)).thenReturn(customer); + + // when + Customer found = customerController.findCustomerByEmail(email); + + // then + assertThat(found).isNotNull(); + } } \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index e9e67fded8..9f81e70e41 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -97,6 +97,22 @@ void setUp() { Assertions.assertThat(found.getId()).isEqualTo(customer.getId()); } + @DisplayName("사용자 이메일로 사용자를 조회할 수 있다.") + @Test + void findByEmail() { + // given + String name = "customer"; + String email = "customer@gmail.com"; + Customer customer = createCustomer(name, email); + customerRepository.insert(customer); + + // when + Customer found = customerRepository.findByEmail("customer@gmail.com").get(); + + // then + Assertions.assertThat(found.getId()).isEqualTo(customer.getId()); + } + private Customer createCustomer(String name, String email) { return new Customer .Builder(name, email) diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java index 83f5787a2a..d6313943e2 100644 --- a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -1,6 +1,7 @@ package team.marco.voucher_management_system.service; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -37,7 +38,7 @@ void setUp() { customerRepository.insert(customer); // 사용자 조회 - Customer found = customerService.findCustomer(customer.getId()); + Customer found = customerService.findCustomerById(customer.getId()); // 등록된 사용자와 동일한 사용자가 조회됨 assertThat(found.getId()).isEqualTo(customer.getId()); @@ -45,6 +46,22 @@ void setUp() { assertThat(found.getEmail()).isEqualTo(customer.getEmail()); } + @DisplayName("사용자를 email로 조회할 수 있다.") + @Test + void findCustomerByEmail() { + // given + String email = "test@gmail.com"; + Customer customer = createCustomer("test", email); + customerRepository.insert(customer); + + // when + Customer found = customerService.findCustomerByEmail(email); + + // then + assertThat(found.getEmail()).isEqualTo(email); + assertThat(found.getName()).isEqualTo(customer.getName()); + } + private Customer createCustomer(String name, String email) { return new Customer .Builder(name, email) From 6533f54693fc0893661d8a34aadd181228dbdd86 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:23:29 +0900 Subject: [PATCH 124/134] =?UTF-8?q?refacotr:=20CustomerIdAndName=EC=9C=84?= =?UTF-8?q?=EC=B9=98=EB=A5=BC=20dto=20=ED=8F=B4=EB=8D=94=20=EC=95=84?= =?UTF-8?q?=EB=9E=98=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/dto/CustomerIdAndName.java | 21 +++++++++++++++++++ .../custromer/BlacklistRepository.java | 2 ++ .../custromer/CsvBlacklistRepository.java | 1 + .../service/customer/BlacklistService.java | 2 +- .../view/consoleapp/ConsoleUtil.java | 14 +++++++++++++ .../service/BlacklistServiceTest.java | 2 +- 6 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerIdAndName.java diff --git a/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerIdAndName.java b/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerIdAndName.java new file mode 100644 index 0000000000..7c5388a8fa --- /dev/null +++ b/src/main/java/team/marco/voucher_management_system/controller/customer/dto/CustomerIdAndName.java @@ -0,0 +1,21 @@ +package team.marco.voucher_management_system.controller.customer.dto; + +import java.util.UUID; + +public class CustomerIdAndName { + private final UUID id; + private final String name; + + public CustomerIdAndName(UUID id, String name) { + this.id = id; + this.name = name; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java index 015b2cb118..a3632555f1 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/BlacklistRepository.java @@ -1,5 +1,7 @@ package team.marco.voucher_management_system.repository.custromer; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; + import java.util.List; public interface BlacklistRepository { diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java index 08f4bc49c1..a0dce4a164 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java @@ -2,6 +2,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Repository; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java b/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java index f18217a221..ed615faed7 100644 --- a/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java +++ b/src/main/java/team/marco/voucher_management_system/service/customer/BlacklistService.java @@ -1,8 +1,8 @@ package team.marco.voucher_management_system.service.customer; import org.springframework.stereotype.Service; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; -import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; import java.util.List; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index 5d159962af..aa0b880a1d 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -1,5 +1,6 @@ package team.marco.voucher_management_system.view.consoleapp; +import team.marco.voucher_management_system.controller.customer.dto.CustomerResponse; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; import java.io.BufferedReader; @@ -58,6 +59,19 @@ public static void printStringList(List list) { } } + public static void printCustomerList(List customers) { + customers.forEach(c -> { + printCustomer(c); + printSeparatorLine(); + }); + } + + public static void printCustomer(CustomerResponse customer) { + print(format("name : {0}", customer.getName())); + print(format("email : {0}", customer.getEmail())); + print(format("createdAt : {0}", customer.getCreatedAt())); + } + public static void printVoucherList(List vouchers) { vouchers.forEach(v -> { printVoucher(v); diff --git a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java index 35d9a885ac..13df3d61a7 100644 --- a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java @@ -2,9 +2,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; -import team.marco.voucher_management_system.repository.custromer.CustomerIdAndName; import team.marco.voucher_management_system.service.customer.BlacklistService; import java.util.List; From cad8d05a4ecb86be1c4eb891863465d4576e48ac Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:25:04 +0900 Subject: [PATCH 125/134] =?UTF-8?q?refactor:=20consoleApp=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=EC=A0=81=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 메서드명 리네임, 메서드 분리 --- .../error/ErrorMessage.java | 1 + .../consoleapp/ConsoleVoucherApplication.java | 6 +- .../view/consoleapp/ServiceType.java | 16 ++--- .../management/ManagementApplication.java | 60 ++++++++--------- .../management/ManagementCommandType.java | 18 +++-- .../consoleapp/wallet/WalletApplication.java | 66 +++++++++++-------- .../consoleapp/wallet/WalletCommandType.java | 12 +++- 7 files changed, 98 insertions(+), 81 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java index b4c53b20db..ebdb49d517 100644 --- a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java +++ b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java @@ -2,6 +2,7 @@ public class ErrorMessage { public static final String CUSTOMER_ID_INVALID = "올바른 사용자 아이디가 아닙니다."; + public static final String INVALID_EMAIL = "해당 이메일의 사용자는 존재하지 않습니다."; public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java index f1f611a291..c8aa5e7e62 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java @@ -65,7 +65,7 @@ public void handleServiceRequest(ServiceType requestedServiceType) { switch (requestedServiceType) { case MANAGEMENT -> runManagementApplication(); case WALLET -> runWalletApplication(); - case EXIT -> exitProgram(); + case EXIT -> exit(); } } @@ -77,7 +77,7 @@ private void runWalletApplication() { walletApplication.run(); } - private void exitProgram() { + private void exit() { logger.info("Call close()"); isRunning = false; @@ -102,6 +102,6 @@ private void handleException(Exception e) { isRunning = false; - exitProgram(); + exit(); } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java index 5910b5527a..166ad471c3 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ServiceType.java @@ -11,10 +11,10 @@ public enum ServiceType { private static final String SERVICE_NOT_EXIST = "해당 서비스가 존재하지 않습니다."; - private final int num; + private final Integer num; private final String description; - ServiceType(int num, String description) { + ServiceType(Integer num, String description) { this.num = num; this.description = description; } @@ -26,15 +26,15 @@ static ServiceType get(int num) { .orElseThrow(() -> new IllegalArgumentException(format(SERVICE_NOT_EXIST))); } - private static boolean isEqual(int targetNum, int serviceNum) { - return targetNum == serviceNum; - } - - public int getNum() { + public Integer getNum() { return num; } public String getManual() { - return num + ". " + description; + return format("{0}. {1}", num, description); + } + + private static Boolean isEqual(int targetNum, int serviceNum) { + return targetNum == serviceNum; } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index fdb30624f4..ff4f1865b4 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -6,12 +6,12 @@ import team.marco.voucher_management_system.controller.customer.CustomerController; import team.marco.voucher_management_system.controller.voucher.VoucherController; import team.marco.voucher_management_system.controller.voucher.dto.VoucherCreateRequest; - -import java.io.UncheckedIOException; +import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; import static team.marco.voucher_management_system.domain.voucher.VoucherType.FIXED; import static team.marco.voucher_management_system.domain.voucher.VoucherType.PERCENT; -import static team.marco.voucher_management_system.error.ErrorMessage.*; +import static team.marco.voucher_management_system.error.ErrorMessage.NUMBER_REQUIRED; +import static team.marco.voucher_management_system.error.ErrorMessage.WRONG_INPUT; import static team.marco.voucher_management_system.view.consoleapp.ConsoleUtil.*; @Component @@ -21,7 +21,7 @@ public class ManagementApplication { public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; public static final String DISCOUNT_PERCENT_REQUEST = "할인율을 입력해 주세요."; public static final String DISCOUNT_AMOUNT_REQUEST = "할인 금액을 입력해 주세요."; - public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; + public static final String VOUCHER_ID_REQUEST = "쿠폰 아이디를 입력해 주세요."; public static final String VOUCHER_CREATE_COMPLETE = "쿠폰 생성이 완료되었습니다."; public static final String INQUIRY_COMPLETE = "조회가 완료되었습니다."; public static final String VOUCHER_MANUAL = """ @@ -29,53 +29,59 @@ public class ManagementApplication { 2: % 할인 쿠폰"""; private final VoucherController voucherController; - private final CustomerController userController; + private final CustomerController customerController; private Boolean isRunning; - public ManagementApplication(VoucherController voucherController, CustomerController userController) { + public ManagementApplication(VoucherController voucherController, CustomerController customerController) { this.voucherController = voucherController; - this.userController = userController; + this.customerController = customerController; this.isRunning = true; } public void run() { while (isRunning) { try { - selectCommand(); + provideCommandManual(); + ManagementCommandType input = getCommandType(); + handleCommand(input); } catch (Exception e) { handleException(e); } } } - public void selectCommand() { + public void provideCommandManual() { print(MANAGEMENT_HEADER); for(ManagementCommandType type : ManagementCommandType.values()) { - print(type.getInfo()); + print(type.getManual()); } println(); + } + public ManagementCommandType getCommandType() { print(SELECT_SERVICE); - int input = readInt(); - ManagementCommandType commandType = ManagementCommandType.get(input); + return ManagementCommandType.get(readInt()); + } + + public void handleCommand(ManagementCommandType commandType) { switch (commandType) { case CREATE_VOUCHER -> createVoucher(); case VOUCHER_LIST -> getVoucherList(); case SEARCH_VOUCHER -> getVoucherInfo(); case CUSTOMER_LIST -> getCustomerList(); case BLACKLIST -> getBlacklist(); - case BACK -> close(); + case BACK -> exit(); } } private void getCustomerList() { - /** - * TODO: getCustomerList() 구현 - */ + ConsoleUtil.printCustomerList(customerController.findAll()); + println(); + println(INQUIRY_COMPLETE); } private void getVoucherInfo() { @@ -136,31 +142,21 @@ private void getVoucherList() { private void getBlacklist() { logger.info("Call getBlackListUsers()"); - printStringList(userController.getBlacklistInfo()); + printStringList(customerController.getBlacklistInfo()); + println(); + println(INQUIRY_COMPLETE); } - private void close() { + private void exit() { isRunning = false; } private void handleException(Exception e) { if(e instanceof NumberFormatException) { - print(NUMBER_REQUIRED); + ConsoleUtil.print(NUMBER_REQUIRED); return; } - if(e instanceof IllegalArgumentException) { - print(e.getMessage()); - return; - } - - logger.error(e.toString()); - - String errorMessage = (e instanceof UncheckedIOException)? FILE_ERROR : PROGRAM_ERROR; - print(errorMessage); - - isRunning = false; - - close(); + ConsoleUtil.println(e.getMessage()); } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java index 18137b9f80..8728ffbdfd 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementCommandType.java @@ -2,6 +2,8 @@ import java.util.Arrays; +import static java.text.MessageFormat.format; + public enum ManagementCommandType { BACK(1, "메인 페이지로 돌아가기"), CREATE_VOUCHER(2, "쿠폰 생성"), @@ -10,17 +12,17 @@ public enum ManagementCommandType { CUSTOMER_LIST(5, "전체 회원 조회"), BLACKLIST(6, "블랙 리스트 회원 조회"); - private final int num; + private final Integer num; private final String description; - ManagementCommandType(int num, String description) { + ManagementCommandType(Integer num, String description) { this.num = num; this.description = description; } - public static ManagementCommandType get(int num) { + public static ManagementCommandType get(Integer num) { return Arrays.stream(ManagementCommandType.values()) - .filter(v -> v.getNum() == num) + .filter(v -> isEqual(num, v.getNum())) .findAny() .orElseThrow(); } @@ -29,7 +31,11 @@ public int getNum() { return num; } - public String getInfo() { - return num + ". " + description; + public String getManual() { + return format("{0}. {1}", num, description); + } + + private static Boolean isEqual(int targetNum, int serviceNum) { + return targetNum == serviceNum; } } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index a6073b17f9..3112b4aec2 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -5,15 +5,19 @@ import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.customer.CustomerController; import team.marco.voucher_management_system.controller.voucher.VoucherController; +import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.view.consoleapp.ConsoleUtil; +import java.util.UUID; + import static team.marco.voucher_management_system.error.ErrorMessage.CUSTOMER_ID_INVALID; import static team.marco.voucher_management_system.error.ErrorMessage.NUMBER_REQUIRED; +import static team.marco.voucher_management_system.view.consoleapp.ConsoleUtil.*; @Component public class WalletApplication { private static final Logger logger = LoggerFactory.getLogger(WalletApplication.class); - public static final String CUSTOMER_ID_REQUEST = "사용자 아이디를 입력해주세요."; + public static final String CUSTOMER_EMAIL_REQUEST = "사용자 이메일을 입력해주세요."; public static final String WALLET_HEADER = "==== 지갑 페이지 ===="; public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; @@ -23,6 +27,7 @@ public class WalletApplication { private final CustomerController customerController; private Boolean isRunning; + private UUID customerId; public WalletApplication(VoucherController voucherController, CustomerController customerController) { this.voucherController = voucherController; @@ -31,35 +36,48 @@ public WalletApplication(VoucherController voucherController, CustomerController } public void run() { - ConsoleUtil.print(CUSTOMER_ID_REQUEST); - String customerId = ConsoleUtil.readString(); - - if(!customerController.isExistCustomer(customerId)) { - throw new IllegalArgumentException(CUSTOMER_ID_INVALID); - } + customerId = validateCustomer(); while (isRunning) { try { - selectCommand(customerId); - } catch (Exception e) { + provideCommandManual(); + WalletCommandType input = getCommandType(); + handleCommand(input); + } catch (IllegalArgumentException e) { handleException(e); } } } - private void selectCommand(String customerId) { - ConsoleUtil.print(WALLET_HEADER); + private UUID validateCustomer() { + ConsoleUtil.print(CUSTOMER_EMAIL_REQUEST); + String customerEmail = ConsoleUtil.readString(); + + Customer customer = customerController.findCustomerByEmail(customerEmail); + + if(customer == null) { + throw new IllegalArgumentException(CUSTOMER_ID_INVALID); + } + return customer.getId(); + } + + public void provideCommandManual() { + print(WALLET_HEADER); for(WalletCommandType type : WalletCommandType.values()) { - ConsoleUtil.print(type.getInfo()); + print(type.getManual()); } - ConsoleUtil.println(); + println(); + } + + public WalletCommandType getCommandType() { + print(SELECT_SERVICE); - ConsoleUtil.print(SELECT_SERVICE); - int input = ConsoleUtil.readInt(); + return WalletCommandType.get(readInt()); + } - WalletCommandType commandType = WalletCommandType.get(input); + public void handleCommand(WalletCommandType commandType) { switch (commandType) { case REGISTER -> registerVoucher(customerId); case LIST -> getMyVouchers(customerId); @@ -68,11 +86,11 @@ private void selectCommand(String customerId) { } } - private void getMyVouchers(String customerId) { + private void getMyVouchers(UUID customerId) { // TODO } - private void registerVoucher(String customerId) { + private void registerVoucher(UUID customerId) { // TODO } @@ -94,16 +112,6 @@ private void handleException(Exception e) { return; } - if(e instanceof IllegalArgumentException) { - ConsoleUtil.print(e.getMessage()); - return; - } - - logger.error(e.toString()); - - ConsoleUtil.print(e.getMessage()); - - isRunning = false; + ConsoleUtil.println(e.getMessage()); } - } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java index b77b599695..f2cd868052 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletCommandType.java @@ -2,6 +2,8 @@ import java.util.Arrays; +import static java.text.MessageFormat.format; + public enum WalletCommandType { BACK(1, "메인 페이지로 돌아가기"), REGISTER(2, "쿠폰 등록"), @@ -18,7 +20,7 @@ public enum WalletCommandType { public static WalletCommandType get(int num) { return Arrays.stream(WalletCommandType.values()) - .filter(v -> v.getNum() == num) + .filter(v -> isEqual(num, v.getNum())) .findAny() .orElseThrow(); } @@ -27,7 +29,11 @@ public int getNum() { return num; } - public String getInfo() { - return num + ". " + description; + public String getManual() { + return format("{0}. {1}", num, description); + } + + private static Boolean isEqual(int targetNum, int serviceNum) { + return targetNum == serviceNum; } } From bd8d7fb44a8158dcf9f70edba60eabaac72a0a44 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:25:39 +0900 Subject: [PATCH 126/134] =?UTF-8?q?refactor:=20VoucherService=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EC=9D=B4=20=20@Transactional(readOnly=20=3D=20true)?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/voucher/VoucherService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index 2d7ad02214..f27d2dac12 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -10,6 +10,7 @@ import java.util.List; +@Transactional(readOnly = true) @Service public class VoucherService { private static final Logger logger = LoggerFactory.getLogger(VoucherService.class); @@ -43,6 +44,7 @@ public Voucher getVoucher(Long voucherId) { return voucherRepository.findById(voucherId).orElseThrow(); } + @Transactional public void deleteVoucher(Long voucherId) { voucherRepository.deleteById(voucherId); } From 1fbc3cbdb23880d8eb84ee1f0d95da38e344409b Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 15:43:31 +0900 Subject: [PATCH 127/134] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=8F=AC=EB=A7=B7=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custromer/CsvBlacklistRepositoryTest.java | 4 +- .../custromer/JdbcCustomerRepositoryTest.java | 40 ++++++------ .../service/BlacklistServiceTest.java | 21 ++++--- .../service/CustomerServiceTest.java | 9 +-- .../service/VoucherServiceTest.java | 62 ++++++++----------- src/test/resources/test_voucher_data.json | 1 + 6 files changed, 67 insertions(+), 70 deletions(-) create mode 100644 src/test/resources/test_voucher_data.json diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java index f99db43718..e48681694c 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepositoryTest.java @@ -22,9 +22,9 @@ public CsvBlacklistRepositoryTest(@Value("${file.path.blacklist}") String path) csvBlacklistRepository = new CsvBlacklistRepository(path); } - @DisplayName("") + @DisplayName("파일에 저장된 사용자 블랙리스트를 조회할 수 있습니다.") @Test - void test() { + void findAll() { /** * test_blacklist.csv에 * id name diff --git a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java index 9f81e70e41..cafd20e113 100644 --- a/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java +++ b/src/test/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepositoryTest.java @@ -31,69 +31,71 @@ void setUp() { jdbcTemplate.update(query); } + @DisplayName("사용자를 생성할 수 있습니다.") @Test - @DisplayName("유저 생성 시 생성된 유저를 반환") - void 사용자_생성_성공() { - // 사용자 생성 + void insert() { + // given String name = "customer"; String email = "customer@gmail.com"; Customer customer = createCustomer(name, email); + // when Customer saved = customerRepository.insert(customer); + // then // UUID와 생성 시간은 주어지지 않으면 자동으로 들어감 Assertions.assertThat(saved.getId()).isNotNull(); Assertions.assertThat(saved.getCreatedAt()).isNotNull(); - // 생성된 사용자 반환 Assertions.assertThat(saved.getId()).isEqualTo(customer.getId()); } + @DisplayName("동일한 이메일을 가진 유저는 생성할 수 없습니다.") @Test - @DisplayName("동일한 이메일을 가진 유저는 생성할 수 없다.") - void 사용자_생성_실패() { - // 사용자 생성 + void insertWithDuplicateEmail() { + // given String name = "customer"; String email = "customer@gmail.com"; Customer customer = createCustomer(name, email); customerRepository.insert(customer); - // 이미 존재하는 이메일과 함께 생성 시도 String name2 = "customer2"; String sameEmail = "customer@gmail.com"; - Customer customer2 = createCustomer(name2, sameEmail); + Customer wrongCustomer = createCustomer(name2, sameEmail); - // 에러 발생 + // when then assertThrows(DuplicateKeyException.class, - () -> customerRepository.insert(customer2)); + () -> customerRepository.insert(wrongCustomer)); } + @DisplayName("전체 사용자 목록을 조회할 수 있습니다.") @Test - void 전체_사용자_목록_조회_성공() { - // 사용자 생성 + void findAll() { + // given Customer customer = createCustomer("customer", "customer@gmail.com"); Customer customer2 = createCustomer("customer2", "customer2@gmail.com"); customerRepository.insert(customer); customerRepository.insert(customer2); - // 전체 사용자 목록 조회 + // when List customers = customerRepository.findAll(); - // 저장된 2명의 사용자가 조회 + // then assertThat(customers).hasSize(2); } + @DisplayName("사용자 아이디로 사용자를 조회할 수 있습니다.") @Test - void 사용자_아이디로_조회_성공() { - // 사용자 생성 + void findById() { + // given String name = "customer"; String email = "customer@gmail.com"; Customer customer = createCustomer(name, email); customerRepository.insert(customer); - // 사용자 아이디로 조회 + // when Customer found = customerRepository.findById(customer.getId()).get(); - // 저장한 사용자와 동일한 사용자 반환 + // then Assertions.assertThat(found.getId()).isEqualTo(customer.getId()); } diff --git a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java index 13df3d61a7..26c5cea163 100644 --- a/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/BlacklistServiceTest.java @@ -1,7 +1,10 @@ package team.marco.voucher_management_system.service; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import team.marco.voucher_management_system.repository.custromer.BlacklistRepository; import team.marco.voucher_management_system.repository.custromer.CsvBlacklistRepository; @@ -11,24 +14,26 @@ import static org.assertj.core.api.Assertions.assertThat; +@SpringBootTest +@ActiveProfiles("test") class BlacklistServiceTest { private BlacklistService blacklistService; private BlacklistRepository blacklistRepository; - @BeforeEach - void VoucherService_초기화() { - blacklistRepository = new CsvBlacklistRepository("src/test/resources/test_blacklist.csv"); + public BlacklistServiceTest(@Value("${file.path.blacklist}") String path) { + blacklistRepository = new CsvBlacklistRepository(path); blacklistService = new BlacklistService(blacklistRepository); } + @DisplayName("파일에 저장된 블랙리스트를 조회할 수 있습니다.") @Test - void 블랙_리스트_조회() { - // test_blacklist 파일에 2명의 블랙리스트가 있을 때 + void test() { + // given - 파일에 미리 2명의 사용자를 추가해 놓았습니다. - // 블랙리스트 조회 + // when List blacklist = blacklistService.getBlacklist(); - // 블랙리스트 크기가 2 + // then assertThat(blacklist).hasSize(2); } } \ No newline at end of file diff --git a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java index d6313943e2..9aeaa12517 100644 --- a/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/CustomerServiceTest.java @@ -31,16 +31,17 @@ void setUp() { jdbcTemplate.update(query); } + @DisplayName("사용자 ID로 사용자를 조회할 수 있습니다.") @Test - void 사용자_ID로_조회() { - // 사용자 등록 + void findCustomerById() { + // given Customer customer = createCustomer("test", "test@gmail.com"); customerRepository.insert(customer); - // 사용자 조회 + // when Customer found = customerService.findCustomerById(customer.getId()); - // 등록된 사용자와 동일한 사용자가 조회됨 + // then assertThat(found.getId()).isEqualTo(customer.getId()); assertThat(found.getName()).isEqualTo(customer.getName()); assertThat(found.getEmail()).isEqualTo(customer.getEmail()); diff --git a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java index cf09ada8cf..69f78342d3 100644 --- a/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java +++ b/src/test/java/team/marco/voucher_management_system/service/VoucherServiceTest.java @@ -38,67 +38,53 @@ void setUp() { jdbcTemplate.update(query); } + @DisplayName("고정 할인 쿠폰을 생성할 수 있습니다.") @Test - void 고정_할인_쿠폰_생성() { - // 할인 금액이 주어 졌을 때 + void createFixedVoucher() { + // given int amount = 1000; VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( FIXED, amount); - // 고정 금액 쿠폰 생성 요청 + // when Voucher returned = voucherService.createVoucher(request); - // 1. 생성된 쿠폰이 FixedAmountVoucher 타입 + // then assertThat(returned.getVoucherType()).isEqualTo(FIXED); - // 2. 생성된 쿠폰의 할인 금액이 amount와 동일 assertThat(returned.getDiscountValue()).isEqualTo(amount); } + @DisplayName("퍼센트 할인 쿠폰을 생성할 수 있습니다.") @Test - void 퍼센트_할인_쿠폰_생성() { - // 할인율이 주어 졌을 때 + void createPercentVoucher() { + // given int percent = 10; VoucherCreateServiceRequest request = new VoucherCreateServiceRequest( PERCENT, percent); - // % 금액 쿠폰 생성 요청 + // when Voucher returned = voucherService.createVoucher(request); - // 1. 생성된 쿠폰이 PercentDiscountVoucher 타입 + // then assertThat(returned.getVoucherType()).isEqualTo(PERCENT); - // 2. 생성된 쿠폰의 할인율이 percent와 동일 assertThat(returned.getDiscountValue()).isEqualTo(percent); } + @DisplayName("전체 쿠폰 목록을 조회할 수 있습니다.") @Test - void 전체_쿠폰_목록_조회() { - // 리포지토리에 쿠폰 2개가 저장되어 있을 때 + void getVouchers() { + // given Voucher voucher = createFixedVoucher(1L, 1000); Voucher voucher2 = createPercentVoucher(2L,10); voucherRepository.save(voucher); voucherRepository.save(voucher2); - // 전체 쿠폰 목록 요청 - List returned = voucherService.getVouchers(); - - // 쿠폰 목록의 크기가 2 - assertThat(returned).hasSize(2); - } - - @Test - void 쿠폰_목록_조회() { - // 리포지토리에 쿠폰 2개가 저장되어 있을 때 - Voucher voucher = createFixedVoucher(1L, 1000); - Voucher voucher2 = createPercentVoucher(2L, 10); - voucherRepository.save(voucher); - voucherRepository.save(voucher2); - - // 전체 쿠폰 목록 요청 + // when List returned = voucherService.getVouchers(); - // 쿠폰 목록의 크기가 2 + // then assertThat(returned).hasSize(2); } @@ -119,29 +105,31 @@ void getVouchersByVoucherType() { assertThat(found).hasSize(1); } + @DisplayName("쿠폰 아이디로 쿠폰을 조회할 수 있습니다.") @Test - void 쿠폰_아이디로_조회() { - // 쿠폰 생성 + void getVoucher() { + // given Voucher voucher = createFixedVoucher(1L, 1000); voucherRepository.save(voucher); - // UUID로 쿠폰 조회 + // when Voucher found = voucherService.getVoucher(voucher.getId()); - // 조회된 쿠폰의 UUID가 인자로 넘겨준 UUID와 같음 + // then assertThat(found.getId()).isEqualTo(voucher.getId()); } + @DisplayName("쿠폰 아이디로 쿠폰을 삭제할 수 있습니다.") @Test - void 쿠폰_아이디로_삭제() { - // 쿠폰 생성 + void deleteVoucher() { + // given Voucher voucher = createFixedVoucher(1L, 1000); voucherRepository.save(voucher); - // UUID로 쿠폰 삭제 + // when voucherService.deleteVoucher(voucher.getId()); - // 쿠폰이 삭제됨 + // then List vouchers = voucherRepository.findAll(); assertThat(vouchers).hasSize(0); } diff --git a/src/test/resources/test_voucher_data.json b/src/test/resources/test_voucher_data.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/src/test/resources/test_voucher_data.json @@ -0,0 +1 @@ +[] \ No newline at end of file From 1665247339001747e13d99d0770a51c9b17b710d Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 16:39:14 +0900 Subject: [PATCH 128/134] =?UTF-8?q?docs:=20thymeleaf=20templates=20html=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=20=EC=8A=A4=ED=83=80=EC=9D=BC=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/templates/layouts/layout.html | 33 +++++++++++++ .../voucher/voucher_create_form.html | 47 ++++++++++--------- .../templates/voucher/voucher_detail.html | 2 +- .../templates/voucher/voucher_list.html | 18 +++---- 4 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/main/resources/templates/layouts/layout.html b/src/main/resources/templates/layouts/layout.html index a43f7a1cb9..818bf0be1e 100644 --- a/src/main/resources/templates/layouts/layout.html +++ b/src/main/resources/templates/layouts/layout.html @@ -79,6 +79,39 @@ background-color: #04AA6D; color: white; } + + div { + margin-bottom: 10px; + } + + .voucher-table tr th:last-child { + background-color: #fff; /* 배경색 흰색으로 */ + border: none; /* 선 없애기 */ + padding: 0; /* 내부 여백 없애기 */ + } + + /* 텍스트 입력 칸 스타일 */ + input[type="text"] { + border: 1px solid #ccc; /* 회색 보더 설정 */ + border-radius: 5px; /* 라운드 설정 */ + padding: 5px; /* 내부 여백 설정 */ + } + + /* 제출 버튼 스타일 */ + button.btn-primary { + margin-top: 10px; /* 위쪽 마진 설정 */ + } + + .btn-primary { + background-color: #04AA6D; /* 배경색 설정 */ + color: white; /* 글자색 설정 */ + border-radius: 5px; /* 라운드 조절 */ + margin: 5px; /* 마진 설정 */ + padding: 5px 10px; /* 내부 여백 설정 */ + border: none; /* 테두리 제거 */ + cursor: pointer; /* 커서 스타일 변경 */ + } + diff --git a/src/main/resources/templates/voucher/voucher_create_form.html b/src/main/resources/templates/voucher/voucher_create_form.html index 2ed7852139..bfe9e92029 100644 --- a/src/main/resources/templates/voucher/voucher_create_form.html +++ b/src/main/resources/templates/voucher/voucher_create_form.html @@ -1,27 +1,30 @@ - - - Voucher 생성 - - -

쿠폰 생성

-
-
- - + xmlns:th="http://www.thymeleaf.org" + xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" + layout:decorate="~{/layouts/layout}"> + + +
+
+ # 쿠폰 생성 +
-
- - +
+ +
+ + $ 할인 쿠폰 + % 할인 쿠폰
+
+
+ + +
+
+ +
+
-
- -
- - + \ No newline at end of file diff --git a/src/main/resources/templates/voucher/voucher_detail.html b/src/main/resources/templates/voucher/voucher_detail.html index 141f0a008b..095a96ee67 100644 --- a/src/main/resources/templates/voucher/voucher_detail.html +++ b/src/main/resources/templates/voucher/voucher_detail.html @@ -10,7 +10,7 @@ # 쿠폰 목록
-
+
diff --git a/src/main/resources/templates/voucher/voucher_list.html b/src/main/resources/templates/voucher/voucher_list.html index 7a74ebf151..e2e74db08f 100644 --- a/src/main/resources/templates/voucher/voucher_list.html +++ b/src/main/resources/templates/voucher/voucher_list.html @@ -9,29 +9,29 @@ # 쿠폰 목록 - -
-
+ +
+
- + + + + - - -
ID 쿠폰명 쿠폰 코드
+ +
- -
From 021c299c9d8745bb4fcf239a57b5105526988b92 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 21:48:04 +0900 Subject: [PATCH 129/134] =?UTF-8?q?fix:=20=EC=A7=80=EA=B0=91=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20->=20=EB=A9=94=EC=9D=B8=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20->=20=EA=B4=80=EB=A6=AC=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=A1=9C=20=EC=A0=84=ED=99=98=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C,=20=EA=B4=80=EB=A6=AC=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EB=84=98=EC=96=B4=EA=B0=80=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/consoleapp/ConsoleVoucherApplication.java | 4 +++- .../view/consoleapp/management/ManagementApplication.java | 4 +++- .../view/consoleapp/wallet/WalletApplication.java | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java index c8aa5e7e62..3c8d19fced 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleVoucherApplication.java @@ -25,11 +25,13 @@ public class ConsoleVoucherApplication implements Runnable { public ConsoleVoucherApplication(WalletApplication walletApplication, ManagementApplication managementApplication) { this.walletApplication = walletApplication; this.managementApplication = managementApplication; - this.isRunning = true; + this.isRunning = false; } @Override public void run() { + isRunning = true; + while (isRunning) { provideLauncher(); } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index ff4f1865b4..9189b90318 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -36,10 +36,12 @@ public class ManagementApplication { public ManagementApplication(VoucherController voucherController, CustomerController customerController) { this.voucherController = voucherController; this.customerController = customerController; - this.isRunning = true; + this.isRunning = false; } public void run() { + isRunning = true; + while (isRunning) { try { provideCommandManual(); diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index 3112b4aec2..1d6f05ed67 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -32,10 +32,11 @@ public class WalletApplication { public WalletApplication(VoucherController voucherController, CustomerController customerController) { this.voucherController = voucherController; this.customerController = customerController; - this.isRunning = true; + this.isRunning = false; } public void run() { + isRunning = true; customerId = validateCustomer(); while (isRunning) { From 06dad6dbf0d5ad2e7e5ddde02c5132c868c57c73 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 21:55:16 +0900 Subject: [PATCH 130/134] =?UTF-8?q?feat:=20=EC=BD=98=EC=86=94=20=EC=A7=80?= =?UTF-8?q?=EA=B0=91=20=EC=84=9C=EB=B9=84=EC=8A=A4=20"=EC=A4=80=EB=B9=84?= =?UTF-8?q?=EC=A4=91"=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기능 구현이 완료되면, 다시 서비스 --- .../consoleapp/wallet/WalletApplication.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java index 1d6f05ed67..140a67f6e9 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/wallet/WalletApplication.java @@ -1,7 +1,5 @@ package team.marco.voucher_management_system.view.consoleapp.wallet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import team.marco.voucher_management_system.controller.customer.CustomerController; import team.marco.voucher_management_system.controller.voucher.VoucherController; @@ -16,12 +14,13 @@ @Component public class WalletApplication { - private static final Logger logger = LoggerFactory.getLogger(WalletApplication.class); public static final String CUSTOMER_EMAIL_REQUEST = "사용자 이메일을 입력해주세요."; public static final String WALLET_HEADER = "==== 지갑 페이지 ===="; public static final String SELECT_SERVICE = "Q. 이용하실 서비스를 선택해 주세요."; public static final String VOUCHER_ID_REQUEST = "쿠폰 번호를 입력해 주세요."; public static final String VOUCHER_DELETE_COMPLETE = "쿠폰 삭제가 완료되었습니다."; + // Preparing for service + private static final String PREPARING_FOR_SERVICE = "현재 지갑 서비스를 준비 중입니다."; private final VoucherController voucherController; private final CustomerController customerController; @@ -36,18 +35,21 @@ public WalletApplication(VoucherController voucherController, CustomerController } public void run() { - isRunning = true; - customerId = validateCustomer(); - - while (isRunning) { - try { - provideCommandManual(); - WalletCommandType input = getCommandType(); - handleCommand(input); - } catch (IllegalArgumentException e) { - handleException(e); - } - } + print(PREPARING_FOR_SERVICE); + println(); + +// isRunning = true; +// customerId = validateCustomer(); +// +// while (isRunning) { +// try { +// provideCommandManual(); +// WalletCommandType input = getCommandType(); +// handleCommand(input); +// } catch (IllegalArgumentException e) { +// handleException(e); +// } +// } } private UUID validateCustomer() { From 14888766661005165d3f4551439fc3192ae84dcb Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 22:24:05 +0900 Subject: [PATCH 131/134] =?UTF-8?q?feat:=20=EB=B8=94=EB=9E=99=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20String=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=EC=97=90=EC=84=9C=20CustomerIdAndName=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=B0=98=ED=99=98=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/customer/CustomerController.java | 10 +++------- .../error/ErrorMessage.java | 1 + .../view/consoleapp/ConsoleUtil.java | 14 ++++++++++++++ .../management/ManagementApplication.java | 2 +- .../customer/CustomerControllerTest.java | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java index d2df711e23..429af298a7 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/customer/CustomerController.java @@ -1,6 +1,7 @@ package team.marco.voucher_management_system.controller.customer; import org.springframework.stereotype.Controller; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import team.marco.voucher_management_system.controller.customer.dto.CustomerResponse; import team.marco.voucher_management_system.domain.customer.Customer; import team.marco.voucher_management_system.service.customer.BlacklistService; @@ -10,8 +11,6 @@ import java.util.NoSuchElementException; import java.util.UUID; -import static java.text.MessageFormat.format; - @Controller public class CustomerController { private final CustomerService customerService; @@ -22,10 +21,8 @@ public CustomerController(CustomerService customerService, BlacklistService blac this.blacklistService = blacklistService; } - public List getBlacklistInfo() { - return blacklistService.getBlacklist().stream() - .map(dto -> format("id: {0}, 고객명: {1} ", dto.getId() , dto.getName())) - .toList(); + public List findBlacklist() { + return blacklistService.getBlacklist(); } public boolean isExistCustomer(String customerId) { @@ -40,7 +37,6 @@ public boolean isExistCustomer(String customerId) { public List findAll() { return customerService.findAllCustomer().stream() .map(CustomerResponse::of) - .peek(System.out::println) .toList(); } diff --git a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java index ebdb49d517..790656f190 100644 --- a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java +++ b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java @@ -5,6 +5,7 @@ public class ErrorMessage { public static final String INVALID_EMAIL = "해당 이메일의 사용자는 존재하지 않습니다."; public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; + public static final String CANNOT_CREATE_VOUCHER = "쿠폰을 추가하는 과정에서 오류가 발생했습니다."; public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; public static final String PROGRAM_ERROR = "프로그램에 에러가 발생했습니다."; } diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java index aa0b880a1d..665f788cd5 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/ConsoleUtil.java @@ -1,5 +1,6 @@ package team.marco.voucher_management_system.view.consoleapp; +import team.marco.voucher_management_system.controller.customer.dto.CustomerIdAndName; import team.marco.voucher_management_system.controller.customer.dto.CustomerResponse; import team.marco.voucher_management_system.controller.voucher.dto.VoucherResponse; @@ -66,6 +67,19 @@ public static void printCustomerList(List customers) { }); } + public static void printCustomerIdAndNameList(List blacklist) { + blacklist.forEach(b -> { + printCustomerIdAndName(b); + printSeparatorLine(); + }); + + } + + public static void printCustomerIdAndName(CustomerIdAndName customerIdAndName) { + print(format("name : {0}", customerIdAndName.getName())); + print(format("id : {0}", customerIdAndName.getId())); + } + public static void printCustomer(CustomerResponse customer) { print(format("name : {0}", customer.getName())); print(format("email : {0}", customer.getEmail())); diff --git a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java index 9189b90318..454d92cafa 100644 --- a/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java +++ b/src/main/java/team/marco/voucher_management_system/view/consoleapp/management/ManagementApplication.java @@ -144,7 +144,7 @@ private void getVoucherList() { private void getBlacklist() { logger.info("Call getBlackListUsers()"); - printStringList(customerController.getBlacklistInfo()); + printCustomerIdAndNameList(customerController.findBlacklist()); println(); println(INQUIRY_COMPLETE); } diff --git a/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java index 753720927d..4cca5aa09d 100644 --- a/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java +++ b/src/test/java/team/marco/voucher_management_system/controller/customer/CustomerControllerTest.java @@ -42,7 +42,7 @@ void getBlacklistInfo() { when(blacklistService.getBlacklist()).thenReturn(blacklist); // when - List result = customerController.getBlacklistInfo(); + List result = customerController.findBlacklist(); // then assertThat(result).isNotNull(); From 3f89d0df864e3ade29dcca3301eed9080084f338 Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 22:25:23 +0900 Subject: [PATCH 132/134] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=B3=80=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/voucher/VoucherService.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java index f27d2dac12..5b921d77ba 100644 --- a/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java +++ b/src/main/java/team/marco/voucher_management_system/service/voucher/VoucherService.java @@ -1,7 +1,5 @@ package team.marco.voucher_management_system.service.voucher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import team.marco.voucher_management_system.domain.voucher.Voucher; @@ -13,8 +11,6 @@ @Transactional(readOnly = true) @Service public class VoucherService { - private static final Logger logger = LoggerFactory.getLogger(VoucherService.class); - private final VoucherRepository voucherRepository; public VoucherService(VoucherRepository voucherRepository) { From 1c1a35b74bf587b440b6963e07810c43376cbdbe Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 22:27:38 +0900 Subject: [PATCH 133/134] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20ErrorMessage=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/voucher/VoucherViewController.java | 6 +++++- .../error/ErrorMessage.java | 1 + .../custromer/JdbcCustomerRepository.java | 4 +++- .../repository/voucher/JdbcVoucherRepository.java | 15 +++++++++------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java index ef6d45bf3f..442f8bb37d 100644 --- a/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java +++ b/src/main/java/team/marco/voucher_management_system/controller/voucher/VoucherViewController.java @@ -45,7 +45,7 @@ public String findVoucherCreateForm() { public String createVoucher(@RequestParam("voucherType") String voucherType, @RequestParam("discountValue") int discountValue, Model model) { - if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); + validateDiscountValue(discountValue); voucherService.createVoucher(new VoucherCreateServiceRequest( VoucherType.valueOf(voucherType), @@ -80,4 +80,8 @@ private List vouchersToVoucherResponses(List vouchers) private static boolean isNotPositive(int discountValue) { return discountValue <= 0; } + + private static void validateDiscountValue(int discountValue) { + if (isNotPositive(discountValue)) throw new IllegalArgumentException("할인 금액 또는 할인율은 양수입니다."); + } } diff --git a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java index 790656f190..2e8078a9b8 100644 --- a/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java +++ b/src/main/java/team/marco/voucher_management_system/error/ErrorMessage.java @@ -6,6 +6,7 @@ public class ErrorMessage { public static final String WRONG_INPUT = "올바르지 않은 입력입니다."; public static final String NUMBER_REQUIRED = "숫자를 입력해 주세요."; public static final String CANNOT_CREATE_VOUCHER = "쿠폰을 추가하는 과정에서 오류가 발생했습니다."; + public static final String CANNOT_CREATE_CUSTOMER = "사용자를 추가하는 과정에서 오류가 발생했습니다."; public static final String FILE_ERROR = "파일을 처리하는 과정에서 에러가 발생했습니다."; public static final String PROGRAM_ERROR = "프로그램에 에러가 발생했습니다."; } diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java index 10a8f7291c..d3486213e8 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/JdbcCustomerRepository.java @@ -11,6 +11,7 @@ import java.time.LocalDateTime; import java.util.*; +import static team.marco.voucher_management_system.error.ErrorMessage.CANNOT_CREATE_CUSTOMER; import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; import static team.marco.voucher_management_system.util.UUIDUtil.uuidToBytes; @@ -37,7 +38,7 @@ public Customer insert(Customer customer) { Timestamp.valueOf(customer.getCreatedAt())); if(update != 1) { - throw new RuntimeException("사용자를 추가하는 과정에서 오류가 발생했습니다."); + throw new RuntimeException(CANNOT_CREATE_CUSTOMER); } return customer; @@ -47,6 +48,7 @@ public Customer insert(Customer customer) { public List findAll() { List customers = new ArrayList<>(); jdbcTemplate.query(SELECT_ALL_SQL, (resultSet, rowNum) -> customers.add(resultSetToCustomer(resultSet))); + return Collections.unmodifiableList(customers); } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java index f2462eb426..093d1dc70c 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/JdbcVoucherRepository.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import java.util.*; +import static team.marco.voucher_management_system.error.ErrorMessage.CANNOT_CREATE_VOUCHER; import static team.marco.voucher_management_system.util.UUIDUtil.bytesToUUID; import static team.marco.voucher_management_system.util.UUIDUtil.uuidToBytes; @@ -36,9 +37,7 @@ public JdbcVoucherRepository(JdbcTemplate jdbcTemplate) { @Override public Voucher save(Voucher voucher) { - int update = 0; - - update = jdbcTemplate.update(INSERT_SQL, + int update = jdbcTemplate.update(INSERT_SQL, voucher.getId(), voucher.getVoucherType().name(), voucher.getDiscountValue(), @@ -46,8 +45,8 @@ public Voucher save(Voucher voucher) { voucher.getName()); if(update != 1) { - logger.error("쿠폰을 추가하는 과정에서 오류가 발생했습니다."); - throw new RuntimeException("쿠폰을 추가하는 과정에서 오류가 발생했습니다."); + logger.error(CANNOT_CREATE_VOUCHER); + throw new RuntimeException(CANNOT_CREATE_VOUCHER); } return voucher; @@ -87,7 +86,7 @@ public void deleteById(Long voucherId) { @Override public Optional findLatestVoucherId() { Long size = jdbcTemplate.queryForObject(SELECT_TOTAL_COUNTS, Long.class); - if(size == 0) return Optional.empty(); + if(isZero(size)) return Optional.empty(); return Optional.of(jdbcTemplate.queryForObject(SELECT_MAXIMUM_ID, Long.class)); } @@ -104,4 +103,8 @@ private Voucher resultSetToVoucher(ResultSet resultSet) throws SQLException { .name(name) .build(); } + + private static boolean isZero(Long num) { + return num == 0; + } } From 460cfe0080b4d69a12d383a20929f92b253fa04a Mon Sep 17 00:00:00 2001 From: uijin-j Date: Sun, 5 Nov 2023 22:28:34 +0900 Subject: [PATCH 134/134] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/voucher/Voucher.java | 16 ++++++++++------ .../custromer/CsvBlacklistRepository.java | 12 ++++++++---- .../repository/voucher/VoucherRepository.java | 2 +- src/main/resources/data/voucher_data.json | 2 +- src/main/resources/templates/layouts/layout.html | 1 - 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java index 51f134cb29..1e115e1047 100644 --- a/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java +++ b/src/main/java/team/marco/voucher_management_system/domain/voucher/Voucher.java @@ -81,18 +81,22 @@ public Voucher build() { private void validateAmount(int amount) { if(amount < MIN_AMOUNT || amount > MAX_AMOUNT) { - throw new IllegalArgumentException( - format("할인 금액은 {0}원 이상, {1}원 이하이어야 합니다.", MIN_AMOUNT, MAX_AMOUNT) - ); + throw new IllegalArgumentException(getAmountPolicy()); } } private void validatePercent(int percent) { if(percent < MIN_PERCENT || percent > MAX_PERCENT) { - throw new IllegalArgumentException( - format("할인 비율은 {0}% 이상, {1}% 이하이어야 합니다.", MIN_PERCENT, MAX_PERCENT) - ); + throw new IllegalArgumentException(getPercentPolicy()); } } } + + private static String getAmountPolicy() { + return format("할인 금액은 {0}원 이상, {1}원 이하이어야 합니다.", MIN_AMOUNT, MAX_AMOUNT); + } + + private static String getPercentPolicy() { + return format("할인 비율은 {0}% 이상, {1}% 이하이어야 합니다.", MIN_PERCENT, MAX_PERCENT); + } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java index a0dce4a164..ca41758c8c 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/custromer/CsvBlacklistRepository.java @@ -27,10 +27,7 @@ public CsvBlacklistRepository(@Value("${file.path.blacklist}") String path) { private List loadBlacklist(String path) { try (BufferedReader reader = Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8)) { reader.readLine(); // skip header - return reader.lines() - .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) - .map(data -> new CustomerIdAndName(stringToUUID(data[0]), data[1])) - .toList(); + return storedDataToCustomerIdAndName(reader); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -40,4 +37,11 @@ private List loadBlacklist(String path) { public List findAll() { return Collections.unmodifiableList(blacklist); } + + private static List storedDataToCustomerIdAndName(BufferedReader reader) { + return reader.lines() + .map(s -> s.split(DELIMITER_REGULAR_EXPRESSION)) + .map(data -> new CustomerIdAndName(stringToUUID(data[0]), data[1])) + .toList(); + } } diff --git a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java index b1e1248899..9a6c62913f 100644 --- a/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java +++ b/src/main/java/team/marco/voucher_management_system/repository/voucher/VoucherRepository.java @@ -10,7 +10,7 @@ public interface VoucherRepository { Voucher save(Voucher voucher); List findAll(); - + List findAllByVoucherType(VoucherType type); Optional findById(Long voucherId); diff --git a/src/main/resources/data/voucher_data.json b/src/main/resources/data/voucher_data.json index fe51488c70..0637a088a0 100644 --- a/src/main/resources/data/voucher_data.json +++ b/src/main/resources/data/voucher_data.json @@ -1 +1 @@ -[] +[] \ No newline at end of file diff --git a/src/main/resources/templates/layouts/layout.html b/src/main/resources/templates/layouts/layout.html index 818bf0be1e..881f0eda16 100644 --- a/src/main/resources/templates/layouts/layout.html +++ b/src/main/resources/templates/layouts/layout.html @@ -111,7 +111,6 @@ border: none; /* 테두리 제거 */ cursor: pointer; /* 커서 스타일 변경 */ } -