diff --git a/.github/.gitmessage.txt b/.github/.gitmessage.txt new file mode 100644 index 0000000..1878ee4 --- /dev/null +++ b/.github/.gitmessage.txt @@ -0,0 +1,31 @@ +# <타입> : <제목> 형식으로 작성하며 제목은 최대 50글자 정도로만 입력 +# 제목을 아랫줄에 작성, 제목 끝에 마침표 금지, 무엇을 했는지 명확하게 작성 +# 예) Feat: "회원 가입 기능 구현" + + +################ +# 본문(추가 설명)을 아랫줄에 작성 +# 예) SMS, 이메일 중복확인 API 개발 + + +################ +# 꼬릿말(footer)을 아랫줄에 작성 (관련된 이슈 번호 등 추가) +# 예) +# Resolves: #123 +# Ref: #456 +# Related to: #48, #45 + + +################ +# feat : 기능 추가 +# fix : 버그 수정 +# docs : 문서 수정 +# test : 테스트 코드 추가 +# refactor : 코드 리팩토링 +# style : 코드 의미에 영향을 주지 않는 변경사항 +# chore : 빌드 부분 혹은 패키지 매니저 수정사항 +# cicd : CI/CD 관련 설정 +################ + +# 커밋 컨벤션 설정 방법 ## +# git config --global commit.template .github/gitmessage.txt \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..c2ce916 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,43 @@ +[comment]: <> "PR 제목은 다음과 같은 형태로 작성하고, 리뷰어에는 팀원 전체를 할당합니다." +[comment]: <> "{Jira-Issue-number} {한 줄 축약 내용 또는 티켓 제목 원형 그대로 이용}" + + + + +## 작업 개요 + + + + + +## 작업 분류 + +- [ ] 버그 수정 +- [ ] 신규 기능 +- [ ] 프로젝트 구조 변경 + + + +## 작업 상세 내용 + + + + + +## 생각해볼 문제 + + + + + +## 완료한 테스트 + + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59bb50d --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +HELP.md +.gradle +build/ +src/main/generated/ +src/test/generated_tests/ +!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/ + +## 추가 +upload/ \ No newline at end of file diff --git a/.gradle/8.5/checksums/checksums.lock b/.gradle/8.5/checksums/checksums.lock new file mode 100644 index 0000000..5b4bb9f Binary files /dev/null and b/.gradle/8.5/checksums/checksums.lock differ diff --git a/.gradle/8.5/checksums/md5-checksums.bin b/.gradle/8.5/checksums/md5-checksums.bin new file mode 100644 index 0000000..9427d03 Binary files /dev/null and b/.gradle/8.5/checksums/md5-checksums.bin differ diff --git a/.gradle/8.5/checksums/sha1-checksums.bin b/.gradle/8.5/checksums/sha1-checksums.bin new file mode 100644 index 0000000..5853dd1 Binary files /dev/null and b/.gradle/8.5/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.5/dependencies-accessors/dependencies-accessors.lock b/.gradle/8.5/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..630c645 Binary files /dev/null and b/.gradle/8.5/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/8.5/dependencies-accessors/gc.properties b/.gradle/8.5/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.5/executionHistory/executionHistory.bin b/.gradle/8.5/executionHistory/executionHistory.bin new file mode 100644 index 0000000..872424c Binary files /dev/null and b/.gradle/8.5/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.5/executionHistory/executionHistory.lock b/.gradle/8.5/executionHistory/executionHistory.lock new file mode 100644 index 0000000..1c56488 Binary files /dev/null and b/.gradle/8.5/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.5/fileChanges/last-build.bin b/.gradle/8.5/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.5/fileChanges/last-build.bin differ diff --git a/.gradle/8.5/fileHashes/fileHashes.bin b/.gradle/8.5/fileHashes/fileHashes.bin new file mode 100644 index 0000000..f24e2b1 Binary files /dev/null and b/.gradle/8.5/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.5/fileHashes/fileHashes.lock b/.gradle/8.5/fileHashes/fileHashes.lock new file mode 100644 index 0000000..b4ae9e4 Binary files /dev/null and b/.gradle/8.5/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.5/fileHashes/resourceHashesCache.bin b/.gradle/8.5/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..4cf395f Binary files /dev/null and b/.gradle/8.5/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/8.5/gc.properties b/.gradle/8.5/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..5d4dc6c Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..ac35628 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Tue Feb 27 09:15:51 KST 2024 +gradle.version=8.5 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..4d51205 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 0000000..a90e68d Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d8b3076 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml new file mode 100644 index 0000000..02b915b --- /dev/null +++ b/.idea/git_toolbox_prj.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f2c1963 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..898e07a --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b084678 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..1603e6b --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.2.2' + id 'io.spring.dependency-management' version '1.1.4' +} + +group = 'code-review-project' +version = '0.0.1-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.1' + + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" +} + +tasks.named('test') { + useJUnitPlatform() +} + +clean { + delete file('src/main/generated') +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1aa94a4 --- /dev/null +++ b/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=SC2039,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=SC2039,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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/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/settings.gradle b/settings.gradle new file mode 100644 index 0000000..56772b3 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'code-review-project' \ No newline at end of file diff --git a/src/main/java/code_review/project/CodeReviewProjectApplication.java b/src/main/java/code_review/project/CodeReviewProjectApplication.java new file mode 100644 index 0000000..d386227 --- /dev/null +++ b/src/main/java/code_review/project/CodeReviewProjectApplication.java @@ -0,0 +1,12 @@ +package code_review.project; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@SpringBootApplication +public class CodeReviewProjectApplication { + public static void main(String[] args) { + SpringApplication.run(CodeReviewProjectApplication.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/code_review/project/account/application/AccountService.java b/src/main/java/code_review/project/account/application/AccountService.java new file mode 100644 index 0000000..7749063 --- /dev/null +++ b/src/main/java/code_review/project/account/application/AccountService.java @@ -0,0 +1,98 @@ +package code_review.project.account.application; + +import code_review.project.account.domain.entity.Account; +import code_review.project.account.domain.dto.in.AccountRequest; +import code_review.project.account.repository.AccountRepository; +import lombok.Builder; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +@Slf4j +public class AccountService { + + private final AccountRepository accountRepository; + + public String createAccount(AccountRequest request) { + Account account = Account.create(request.getAccountName()); + accountRepository.save(account); + return account.getName(); + } + + public Integer depositAccount(Long accountId, Integer amount) { + Account entity = accountRepository.findById(accountId) + .orElseThrow(() -> new IllegalArgumentException("해당 계좌를 찾을 수 없습니다.")); + + entity.deposit(amount); + + return entity.getAmount(); + } + + public Integer withdrawAccount(Long accountId, Integer amount) { + Account entity = accountRepository.findById(accountId) + .orElseThrow(() -> new IllegalArgumentException("해당 계좌를 찾을 수 없습니다.")); + + entity.withdraw(amount); + return entity.getAmount(); + } + + public TransferAccountResponse transferAccount(Long accountId, String recipientAccountId, Integer amount) { + + // from + Account from = accountRepository.findById(accountId) + .orElseThrow(() -> new IllegalArgumentException("해당 계좌를 찾을 수 없습니다.")); + + // to + Account to = accountRepository.findById(Long.valueOf(recipientAccountId)) + .orElseThrow(() -> new IllegalArgumentException("해당 계좌를 찾을 수 없습니다.")); + + Account.transfer(from, to, amount); + + return TransferAccountResponse.of(from.getName(), from.getAmount(), to.getName(), to.getAmount()); + } + + public AccountResponse findAccount(Long accountId) { + Account entity = accountRepository.findById(accountId) + .orElseThrow(() -> new IllegalArgumentException("해당 계좌를 찾을 수 없습니다.")); + return AccountResponse.of(entity); + } + + @Data + @Builder + public static class AccountResponse { + private Long accountId; + private String name; + private Integer amount; + + public static AccountResponse of(Account entity) { + return AccountResponse.builder() + .accountId(entity.getId()) + .name(entity.getName()) + .amount(entity.getAmount()) + .build(); + } + } + + @Data + @Builder + public static class TransferAccountResponse { + private String fromName; + private Integer fromAmount; + private String toName; + private Integer toAmount; + + public static TransferAccountResponse of(String fromName, Integer fromAmount, String toName, Integer toAmount) { + return TransferAccountResponse.builder() + .fromName(fromName) + .fromAmount(fromAmount) + .toName(toName) + .toAmount(toAmount) + .build(); + } + } +} diff --git a/src/main/java/code_review/project/account/domain/dto/in/AccountRequest.java b/src/main/java/code_review/project/account/domain/dto/in/AccountRequest.java new file mode 100644 index 0000000..476c3ab --- /dev/null +++ b/src/main/java/code_review/project/account/domain/dto/in/AccountRequest.java @@ -0,0 +1,8 @@ +package code_review.project.account.domain.dto.in; + +import lombok.Getter; + +@Getter +public class AccountRequest { + private String accountName; +} diff --git a/src/main/java/code_review/project/account/domain/entity/Account.java b/src/main/java/code_review/project/account/domain/entity/Account.java new file mode 100644 index 0000000..335deee --- /dev/null +++ b/src/main/java/code_review/project/account/domain/entity/Account.java @@ -0,0 +1,57 @@ +package code_review.project.account.domain.entity; + +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import code_review.project.common.BaseTimeEntity; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Builder +@AllArgsConstructor +@Getter +@NoArgsConstructor(access = PROTECTED) +@EntityListeners(AmountChangeListener.class) +public class Account extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "account_id") + private Long id; + + private String name; + + private Integer amount; + + public static Account create(String accountName) { + return Account.builder() + .name(accountName) + .amount(0) + .build(); + } + + public void deposit(Integer amount) { + this.amount += amount; + } + + public void withdraw(Integer amount) { + int result = this.amount - amount; + if (result < 0) { + throw new IllegalArgumentException("존재하는 금액보다 출금하려는 금액이 큽니다."); + } + this.amount = result; + } + + public static void transfer(Account from, Account to, Integer amount) { + from.withdraw(amount); + to.deposit(amount); + } +} diff --git a/src/main/java/code_review/project/account/domain/entity/AmountChangeListener.java b/src/main/java/code_review/project/account/domain/entity/AmountChangeListener.java new file mode 100644 index 0000000..d7b480c --- /dev/null +++ b/src/main/java/code_review/project/account/domain/entity/AmountChangeListener.java @@ -0,0 +1,20 @@ +package code_review.project.account.domain.entity; + +import jakarta.persistence.PostUpdate; +import jakarta.persistence.PreUpdate; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class AmountChangeListener { + @PreUpdate + public void beforeUpdate(Account entity) { + Integer result = entity.getAmount(); + log.info("before => {}", result); + } + + @PostUpdate + public void afterUpdate(Account entity) { + Integer result = entity.getAmount(); + log.info("after => {}", result); + } +} diff --git a/src/main/java/code_review/project/account/presentation/AccountController.java b/src/main/java/code_review/project/account/presentation/AccountController.java new file mode 100644 index 0000000..614ed4e --- /dev/null +++ b/src/main/java/code_review/project/account/presentation/AccountController.java @@ -0,0 +1,49 @@ +package code_review.project.account.presentation; + +import code_review.project.account.application.AccountService; +import code_review.project.account.application.AccountService.AccountResponse; +import code_review.project.account.application.AccountService.TransferAccountResponse; +import code_review.project.account.domain.dto.in.AccountRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/accounts") +@Slf4j +public class AccountController { + + private final AccountService accountService; + + @PostMapping + public ResponseEntity createAccount(@RequestBody AccountRequest request) { + return ResponseEntity.ok(accountService.createAccount(request)); + } + + @PostMapping("{accountId}/deposit") + public ResponseEntity depositAccount(@PathVariable Long accountId, Integer amount) { + return ResponseEntity.ok(accountService.depositAccount(accountId, amount)); + } + + @PostMapping("{accountId}/withdraw") + public ResponseEntity withdrawAccount(@PathVariable Long accountId, Integer amount) { + return ResponseEntity.ok(accountService.withdrawAccount(accountId, amount)); + } + + @PostMapping("{accountId}/transfer") + public ResponseEntity transferAccount(@PathVariable Long accountId, String recipientAccountId, Integer amount) { + return ResponseEntity.ok(accountService.transferAccount(accountId, recipientAccountId, amount)); + } + + @GetMapping("/{accountId}") + public ResponseEntity findAccount(@PathVariable Long accountId) { + return ResponseEntity.ok(accountService.findAccount(accountId)); + } +} \ No newline at end of file diff --git a/src/main/java/code_review/project/account/repository/AccountRepository.java b/src/main/java/code_review/project/account/repository/AccountRepository.java new file mode 100644 index 0000000..8cd0e06 --- /dev/null +++ b/src/main/java/code_review/project/account/repository/AccountRepository.java @@ -0,0 +1,9 @@ +package code_review.project.account.repository; + +import code_review.project.account.domain.entity.Account; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; + +public interface AccountRepository extends JpaRepository { + Account findByName(@Param("name") String name); +} diff --git a/src/main/java/code_review/project/common/BaseEntity.java b/src/main/java/code_review/project/common/BaseEntity.java new file mode 100644 index 0000000..e16ea2a --- /dev/null +++ b/src/main/java/code_review/project/common/BaseEntity.java @@ -0,0 +1,6 @@ +package code_review.project.common; + +import org.springframework.data.domain.AbstractAggregateRoot; + +public abstract class BaseEntity extends AbstractAggregateRoot> { +} diff --git a/src/main/java/code_review/project/common/BaseTimeEntity.java b/src/main/java/code_review/project/common/BaseTimeEntity.java new file mode 100644 index 0000000..5a750a1 --- /dev/null +++ b/src/main/java/code_review/project/common/BaseTimeEntity.java @@ -0,0 +1,22 @@ +package code_review.project.common; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseTimeEntity extends BaseEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} diff --git a/src/main/java/code_review/project/common/EnumMapperType.java b/src/main/java/code_review/project/common/EnumMapperType.java new file mode 100644 index 0000000..53247a2 --- /dev/null +++ b/src/main/java/code_review/project/common/EnumMapperType.java @@ -0,0 +1,6 @@ +package code_review.project.common; + +public interface EnumMapperType { + String getCode(); + String getDescription(); +} diff --git a/src/main/java/code_review/project/common/EnumMapperValue.java b/src/main/java/code_review/project/common/EnumMapperValue.java new file mode 100644 index 0000000..cd383d5 --- /dev/null +++ b/src/main/java/code_review/project/common/EnumMapperValue.java @@ -0,0 +1,15 @@ +package code_review.project.common; + +import lombok.Getter; + +@Getter +public class EnumMapperValue { + + private final String code; + private final String description; + + public EnumMapperValue(EnumMapperType enumMapperType) { + this.code = enumMapperType.getCode(); + this.description = enumMapperType.getDescription(); + } +} diff --git a/src/main/java/code_review/project/config/JpaConfig.java b/src/main/java/code_review/project/config/JpaConfig.java new file mode 100644 index 0000000..8cae057 --- /dev/null +++ b/src/main/java/code_review/project/config/JpaConfig.java @@ -0,0 +1,21 @@ +package code_review.project.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaConfig { + + @PersistenceContext + private EntityManager em; + + @Bean + public JPAQueryFactory jpaQueryFactory() { + return new JPAQueryFactory(em); + } +} diff --git a/src/main/java/code_review/project/todolist/application/ToDoListService.java b/src/main/java/code_review/project/todolist/application/ToDoListService.java new file mode 100644 index 0000000..77b8b30 --- /dev/null +++ b/src/main/java/code_review/project/todolist/application/ToDoListService.java @@ -0,0 +1,53 @@ +package code_review.project.todolist.application; + +import static code_review.project.todolist.domain.entity.CompletionStatus.UNCOMPLETED; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; + +import code_review.project.todolist.domain.dto.in.ChangeToDoListRequest; +import code_review.project.todolist.domain.entity.CompletionStatus; +import code_review.project.todolist.domain.entity.ToDoList; +import code_review.project.todolist.domain.dto.in.RegisterToDoListRequest; +import code_review.project.todolist.domain.dto.out.ToDoListResponse; +import code_review.project.todolist.repository.ToDoListRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +@Slf4j +public class ToDoListService { + + private final ToDoListRepository toDoListRepository; + + public List findToDoList() { + return toDoListRepository.findAllToDoList(); + } + + public String registerToDoList(RegisterToDoListRequest request) { + ToDoList entity = ToDoList.builder() + .description(request.getDescription()) + .isCompleted(UNCOMPLETED) + .build(); + toDoListRepository.save(entity); + return entity.getDescription(); + } + + public CompletionStatus changeToDoList(String todoId, ChangeToDoListRequest request) { + ToDoList entity = toDoListRepository.findById(Long.valueOf(todoId)) + .orElseThrow(() -> new IllegalArgumentException("할일 목록이 존재하지 않습니다.")); + entity.changeCompletion(request); + return entity.getIsCompleted(); + } + + public Boolean deleteToDoList(String todoId) { + ToDoList entity = toDoListRepository.findById(Long.valueOf(todoId)) + .orElseThrow(() -> new IllegalArgumentException("할일 목록이 존재하지 않습니다.")); + toDoListRepository.delete(entity); + return true; + } +} diff --git a/src/main/java/code_review/project/todolist/domain/dto/in/ChangeToDoListRequest.java b/src/main/java/code_review/project/todolist/domain/dto/in/ChangeToDoListRequest.java new file mode 100644 index 0000000..30b39b1 --- /dev/null +++ b/src/main/java/code_review/project/todolist/domain/dto/in/ChangeToDoListRequest.java @@ -0,0 +1,13 @@ +package code_review.project.todolist.domain.dto.in; + +import code_review.project.todolist.domain.entity.CompletionStatus; +import java.time.LocalDateTime; +import lombok.Getter; +import org.springframework.format.annotation.DateTimeFormat; + +@Getter +public class ChangeToDoListRequest { + private CompletionStatus status; + @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private LocalDateTime completedTime; +} diff --git a/src/main/java/code_review/project/todolist/domain/dto/in/RegisterToDoListRequest.java b/src/main/java/code_review/project/todolist/domain/dto/in/RegisterToDoListRequest.java new file mode 100644 index 0000000..b6d9e2d --- /dev/null +++ b/src/main/java/code_review/project/todolist/domain/dto/in/RegisterToDoListRequest.java @@ -0,0 +1,8 @@ +package code_review.project.todolist.domain.dto.in; + +import lombok.Getter; + +@Getter +public class RegisterToDoListRequest { + private String description; +} diff --git a/src/main/java/code_review/project/todolist/domain/dto/out/ToDoListResponse.java b/src/main/java/code_review/project/todolist/domain/dto/out/ToDoListResponse.java new file mode 100644 index 0000000..1163a39 --- /dev/null +++ b/src/main/java/code_review/project/todolist/domain/dto/out/ToDoListResponse.java @@ -0,0 +1,34 @@ +package code_review.project.todolist.domain.dto.out; + +import code_review.project.todolist.domain.entity.CompletionStatus; +import code_review.project.todolist.domain.entity.ToDoList; +import com.querydsl.core.annotations.QueryProjection; +import java.time.LocalDateTime; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ToDoListResponse { + private Long toDoListId; + private String description; + private CompletionStatus isCompleted; + private LocalDateTime completedTime; + + public static ToDoListResponse of(ToDoList entity) { + return ToDoListResponse.builder() + .description(entity.getDescription()) + .isCompleted(entity.getIsCompleted()) + .completedTime(entity.getCompletedTime()) + .build(); + } + + @QueryProjection + public ToDoListResponse(Long toDoListId, String description, CompletionStatus isCompleted, + LocalDateTime completedTime) { + this.toDoListId = toDoListId; + this.description = description; + this.isCompleted = isCompleted; + this.completedTime = completedTime; + } +} diff --git a/src/main/java/code_review/project/todolist/domain/entity/CompletionStatus.java b/src/main/java/code_review/project/todolist/domain/entity/CompletionStatus.java new file mode 100644 index 0000000..f022e49 --- /dev/null +++ b/src/main/java/code_review/project/todolist/domain/entity/CompletionStatus.java @@ -0,0 +1,17 @@ +package code_review.project.todolist.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum CompletionStatus { + COMPLETED("완료"), + UNCOMPLETED("미완료"); + + private String description; + + public String getCode() { + return name(); + } +} diff --git a/src/main/java/code_review/project/todolist/domain/entity/ToDoList.java b/src/main/java/code_review/project/todolist/domain/entity/ToDoList.java new file mode 100644 index 0000000..b852088 --- /dev/null +++ b/src/main/java/code_review/project/todolist/domain/entity/ToDoList.java @@ -0,0 +1,50 @@ +package code_review.project.todolist.domain.entity; + +import static jakarta.persistence.EnumType.STRING; +import static jakarta.persistence.GenerationType.IDENTITY; +import static lombok.AccessLevel.PROTECTED; + +import code_review.project.common.BaseTimeEntity; +import code_review.project.todolist.domain.dto.in.ChangeToDoListRequest; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Entity +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = PROTECTED) +@Getter +@ToString +public class ToDoList extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "to_do_list_id") + private Long id; + + private String description; + + @Enumerated(STRING) + private CompletionStatus isCompleted; + + private LocalDateTime completedTime; + + public void changeDescription(String description) { + this.description = description; + } + + public void changeCompletion(ChangeToDoListRequest request) { + this.isCompleted = request.getStatus(); + this.completedTime = request.getCompletedTime(); + } +} diff --git a/src/main/java/code_review/project/todolist/presentation/ToDoListController.java b/src/main/java/code_review/project/todolist/presentation/ToDoListController.java new file mode 100644 index 0000000..ba2781b --- /dev/null +++ b/src/main/java/code_review/project/todolist/presentation/ToDoListController.java @@ -0,0 +1,48 @@ +package code_review.project.todolist.presentation; + +import code_review.project.todolist.application.ToDoListService; +import code_review.project.todolist.domain.dto.in.ChangeToDoListRequest; +import code_review.project.todolist.domain.dto.in.RegisterToDoListRequest; +import code_review.project.todolist.domain.dto.out.ToDoListResponse; +import code_review.project.todolist.domain.entity.CompletionStatus; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/todos") +@Slf4j +public class ToDoListController { + + private final ToDoListService toDoListService; + + @GetMapping + public ResponseEntity> findToDoList() { + return ResponseEntity.ok(toDoListService.findToDoList()); + } + + @PostMapping + public ResponseEntity registerToDoList(@RequestBody RegisterToDoListRequest request) { + return ResponseEntity.ok(toDoListService.registerToDoList(request)); + } + + @PatchMapping("/{todoId}/change") + public ResponseEntity changeToDoList(@PathVariable("todoId") String todoId, @RequestBody ChangeToDoListRequest request) { + return ResponseEntity.ok(toDoListService.changeToDoList(todoId, request)); + } + + @DeleteMapping("/{todoId}/change") + public ResponseEntity deleteToDoList(@PathVariable("todoId") String todoId) { + return ResponseEntity.ok(toDoListService.deleteToDoList(todoId)); + } +} diff --git a/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepository.java b/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepository.java new file mode 100644 index 0000000..5f8d7c7 --- /dev/null +++ b/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepository.java @@ -0,0 +1,8 @@ +package code_review.project.todolist.repository; + +import code_review.project.todolist.domain.dto.out.ToDoListResponse; +import java.util.List; + +public interface ToDoListCustomRepository { + List findAllToDoList(); +} diff --git a/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepositoryImpl.java b/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepositoryImpl.java new file mode 100644 index 0000000..a129916 --- /dev/null +++ b/src/main/java/code_review/project/todolist/repository/ToDoListCustomRepositoryImpl.java @@ -0,0 +1,33 @@ +package code_review.project.todolist.repository; + +import static code_review.project.todolist.domain.entity.QToDoList.toDoList; + +import code_review.project.todolist.domain.dto.out.ToDoListResponse; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class ToDoListCustomRepositoryImpl implements ToDoListCustomRepository { + + private final JPAQueryFactory queryFactory; + + @Override + public List findAllToDoList() { + return queryFactory + .select(Projections.constructor(ToDoListResponse.class, + toDoList.id, + toDoList.description, + toDoList.isCompleted, + toDoList.completedTime)) + .from(toDoList) + .orderBy( + toDoList.isCompleted.desc(), + toDoList.createdAt.asc()) + .fetch(); + } + +} diff --git a/src/main/java/code_review/project/todolist/repository/ToDoListRepository.java b/src/main/java/code_review/project/todolist/repository/ToDoListRepository.java new file mode 100644 index 0000000..2e56046 --- /dev/null +++ b/src/main/java/code_review/project/todolist/repository/ToDoListRepository.java @@ -0,0 +1,9 @@ +package code_review.project.todolist.repository; + +import code_review.project.todolist.domain.entity.ToDoList; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; + +public interface ToDoListRepository extends JpaRepository, ToDoListCustomRepository { + ToDoList findByDescription(@Param("description") String description); +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..ddd8b09 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,22 @@ +spring: + profiles: + active: DEV + + datasource: + url: jdbc:mysql://localhost:3306/study + username: root + password: tiger + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.MySQLDialect + open-in-view: false + +logging.level: + org.hibernate.SQL: debug + org.hibernate.type: trace \ No newline at end of file diff --git a/src/test/java/code_review/project/account/application/AccountServiceTest.java b/src/test/java/code_review/project/account/application/AccountServiceTest.java new file mode 100644 index 0000000..d8d2ba1 --- /dev/null +++ b/src/test/java/code_review/project/account/application/AccountServiceTest.java @@ -0,0 +1,89 @@ +package code_review.project.account.application; + +import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + +import code_review.project.account.application.AccountService.TransferAccountResponse; +import code_review.project.account.domain.entity.Account; +import code_review.project.account.repository.AccountRepository; +import jakarta.persistence.EntityManager; +import lombok.extern.slf4j.Slf4j; +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.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +@Slf4j +class AccountServiceTest { + + @Autowired + private EntityManager em; + + @Autowired + private AccountService accountService; + + @Autowired + private AccountRepository accountRepository; + + @BeforeEach + @Transactional + void BeforeEachRegisterAccount() { + //accountService.createAccount("미래계좌"); + } + + @Test + void registerAccount() { + //String accountName = accountService.createAccount("미래계좌"); + //assertThat(accountName).isEqualTo("미래계좌"); + } + + @Test + void depositAccount() { + // given + Account entity = accountRepository.findByName("미래계좌"); + Integer amount = accountService.depositAccount(entity.getId(), 10000); + assertThat(amount).isEqualTo(10000); + } + + @Test + void withdrawAccountFailTest() { + assertThatThrownBy( + () -> accountService.withdrawAccount(1L, 10000)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + void withdrawAccount() { + Account result = accountRepository.findByName("미래계좌"); + accountService.depositAccount(result.getId(), 10000); + Integer amount = accountService.withdrawAccount(result.getId(), 10000); + assertThat(amount).isEqualTo(0); + } + + @Test + void transferAccount() { + + Account from = Account.builder() + .name("적금계좌") + .amount(10000) + .build(); + + Account to = Account.builder() + .name("도약계좌") + .amount(0) + .build(); + + accountRepository.save(from); + accountRepository.save(to); + TransferAccountResponse result = accountService.transferAccount(from.getId(), String.valueOf(to.getId()), 10000); + + assertThatThrownBy( + () -> accountService.transferAccount(from.getId(), String.valueOf(to.getId()), 10000)) + .isInstanceOf(IllegalArgumentException.class); + + log.info("result => {}", result); + } +} \ No newline at end of file diff --git a/src/test/java/code_review/project/todolist/application/ToDoListServiceTest.java b/src/test/java/code_review/project/todolist/application/ToDoListServiceTest.java new file mode 100644 index 0000000..ba6fd3c --- /dev/null +++ b/src/test/java/code_review/project/todolist/application/ToDoListServiceTest.java @@ -0,0 +1,79 @@ +package code_review.project.todolist.application; + +import static code_review.project.todolist.domain.entity.CompletionStatus.UNCOMPLETED; +import static org.assertj.core.api.Assertions.assertThat; + +import code_review.project.todolist.domain.entity.CompletionStatus; +import code_review.project.todolist.domain.entity.ToDoList; +import code_review.project.todolist.repository.ToDoListRepository; +import jakarta.persistence.EntityManager; +import lombok.extern.slf4j.Slf4j; +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.transaction.annotation.Transactional; + +@SpringBootTest +@Transactional +@Slf4j +class ToDoListServiceTest { + + @Autowired + private EntityManager em; + + @Autowired + private ToDoListRepository toDoListRepository; + + @BeforeEach + @Transactional + void BeforeEachRegisterToDoList() { + ToDoList entity = ToDoList.builder() + .description("자바 공부하기") + .isCompleted(UNCOMPLETED) + .build(); + toDoListRepository.save(entity); + } + + @Test + void findToDoList() { + + } + + @Test + void registerToDoList() { + ToDoList entity = ToDoList.builder() + .description("자바 공부하기") + .isCompleted(UNCOMPLETED) + .build(); + toDoListRepository.save(entity); + } + + @Test + void changeToDoList() { + ToDoList entity = toDoListRepository.findByDescription("자바 공부하기"); + entity.changeDescription("스프링 공부하기"); + + flushAndClear(); + + toDoListRepository.findById(entity.getId()).ifPresent(data -> { + assertThat(data.getDescription()).isEqualTo("스프링 공부하기"); + }); + } + + @Test + void deleteToDoList() { + ToDoList entity = toDoListRepository.findByDescription("자바 공부하기"); + toDoListRepository.delete(entity); + + flushAndClear(); + + ToDoList result = toDoListRepository.findByDescription("자바 공부하기"); + assertThat(result).isNull(); + } + + private void flushAndClear() { + em.flush(); + em.clear(); + } +} \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..fa47019 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,22 @@ +spring: + profiles: + active: TEST + + datasource: + url: jdbc:mysql://localhost:3306/study + username: root + password: tiger + driver-class-name: com.mysql.cj.jdbc.Driver + + jpa: + hibernate: + ddl-auto: none + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.MySQLDialect + open-in-view: false + +logging.level: + org.hibernate.SQL: debug + org.hibernate.type: trace \ No newline at end of file