diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8274af5 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84c327a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +src/main/resources/application.yml diff --git a/.gradle/8.8/checksums/checksums.lock b/.gradle/8.8/checksums/checksums.lock new file mode 100644 index 0000000..a511b5b Binary files /dev/null and b/.gradle/8.8/checksums/checksums.lock differ diff --git a/.gradle/8.8/checksums/md5-checksums.bin b/.gradle/8.8/checksums/md5-checksums.bin new file mode 100644 index 0000000..e06d82e Binary files /dev/null and b/.gradle/8.8/checksums/md5-checksums.bin differ diff --git a/.gradle/8.8/checksums/sha1-checksums.bin b/.gradle/8.8/checksums/sha1-checksums.bin new file mode 100644 index 0000000..da9d3db Binary files /dev/null and b/.gradle/8.8/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.8/dependencies-accessors/gc.properties b/.gradle/8.8/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.8/executionHistory/executionHistory.bin b/.gradle/8.8/executionHistory/executionHistory.bin new file mode 100644 index 0000000..82c702e Binary files /dev/null and b/.gradle/8.8/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.8/executionHistory/executionHistory.lock b/.gradle/8.8/executionHistory/executionHistory.lock new file mode 100644 index 0000000..bf92503 Binary files /dev/null and b/.gradle/8.8/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.8/fileChanges/last-build.bin b/.gradle/8.8/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.8/fileChanges/last-build.bin differ diff --git a/.gradle/8.8/fileHashes/fileHashes.bin b/.gradle/8.8/fileHashes/fileHashes.bin new file mode 100644 index 0000000..a0e236e Binary files /dev/null and b/.gradle/8.8/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.8/fileHashes/fileHashes.lock b/.gradle/8.8/fileHashes/fileHashes.lock new file mode 100644 index 0000000..c96d385 Binary files /dev/null and b/.gradle/8.8/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.8/fileHashes/resourceHashesCache.bin b/.gradle/8.8/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..996fe7b Binary files /dev/null and b/.gradle/8.8/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/8.8/gc.properties b/.gradle/8.8/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..708a2b6 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..21f3277 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Sun Feb 16 16:27:53 KST 2025 +gradle.version=8.8 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..af2bbe5 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..9323f69 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..c3f502a --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml +# 에디터 기반 HTTP 클라이언트 요청 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..5204928 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +be-dev-ass-sep-v1 \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..79b5e78 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ce1c62c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + + \ 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/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7e9f46a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c2df0e2 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/be-dev-ass-sep-v1.main.iml b/.idea/modules/be-dev-ass-sep-v1.main.iml new file mode 100644 index 0000000..967cdcf --- /dev/null +++ b/.idea/modules/be-dev-ass-sep-v1.main.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ 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..112c2c0 --- /dev/null +++ b/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.0' + id 'io.spring.dependency-management' version '1.1.5' +} + +group = 'org.sep2' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-validation' + implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1' + implementation 'io.github.cdimascio:java-dotenv:5.2.2' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.mysql:mysql-connector-j' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + testImplementation platform('org.junit:junit-bom:5.10.0') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +tasks.named('test') { + useJUnitPlatform() +} \ No newline at end of file diff --git a/build/classes/java/main/org/sep2/ApiKeyProvider.class b/build/classes/java/main/org/sep2/ApiKeyProvider.class new file mode 100644 index 0000000..2f34260 Binary files /dev/null and b/build/classes/java/main/org/sep2/ApiKeyProvider.class differ diff --git a/build/classes/java/main/org/sep2/SampleApplication.class b/build/classes/java/main/org/sep2/SampleApplication.class new file mode 100644 index 0000000..917b0d3 Binary files /dev/null and b/build/classes/java/main/org/sep2/SampleApplication.class differ diff --git a/build/classes/java/main/org/sep2/controller/StockHistoryController.class b/build/classes/java/main/org/sep2/controller/StockHistoryController.class new file mode 100644 index 0000000..3935c7f Binary files /dev/null and b/build/classes/java/main/org/sep2/controller/StockHistoryController.class differ diff --git a/build/classes/java/main/org/sep2/domain/Company.class b/build/classes/java/main/org/sep2/domain/Company.class new file mode 100644 index 0000000..9f8fe32 Binary files /dev/null and b/build/classes/java/main/org/sep2/domain/Company.class differ diff --git a/build/classes/java/main/org/sep2/domain/StockHistory.class b/build/classes/java/main/org/sep2/domain/StockHistory.class new file mode 100644 index 0000000..a15f829 Binary files /dev/null and b/build/classes/java/main/org/sep2/domain/StockHistory.class differ diff --git a/build/classes/java/main/org/sep2/domain/StockHistoryId.class b/build/classes/java/main/org/sep2/domain/StockHistoryId.class new file mode 100644 index 0000000..28ac6fa Binary files /dev/null and b/build/classes/java/main/org/sep2/domain/StockHistoryId.class differ diff --git a/build/classes/java/main/org/sep2/dto/CompanyDto.class b/build/classes/java/main/org/sep2/dto/CompanyDto.class new file mode 100644 index 0000000..f1d8002 Binary files /dev/null and b/build/classes/java/main/org/sep2/dto/CompanyDto.class differ diff --git a/build/classes/java/main/org/sep2/dto/StockHistoryDto.class b/build/classes/java/main/org/sep2/dto/StockHistoryDto.class new file mode 100644 index 0000000..3f123f1 Binary files /dev/null and b/build/classes/java/main/org/sep2/dto/StockHistoryDto.class differ diff --git a/build/classes/java/main/org/sep2/dto/StockHistoryRequestDto.class b/build/classes/java/main/org/sep2/dto/StockHistoryRequestDto.class new file mode 100644 index 0000000..9a9b2ad Binary files /dev/null and b/build/classes/java/main/org/sep2/dto/StockHistoryRequestDto.class differ diff --git a/build/classes/java/main/org/sep2/dto/StockHistoryResponseDto.class b/build/classes/java/main/org/sep2/dto/StockHistoryResponseDto.class new file mode 100644 index 0000000..2fb64d9 Binary files /dev/null and b/build/classes/java/main/org/sep2/dto/StockHistoryResponseDto.class differ diff --git a/build/classes/java/main/org/sep2/exception/ApiKeyInvalidException.class b/build/classes/java/main/org/sep2/exception/ApiKeyInvalidException.class new file mode 100644 index 0000000..1a36042 Binary files /dev/null and b/build/classes/java/main/org/sep2/exception/ApiKeyInvalidException.class differ diff --git a/build/classes/java/main/org/sep2/exception/ApiKeyMissingException.class b/build/classes/java/main/org/sep2/exception/ApiKeyMissingException.class new file mode 100644 index 0000000..3d899f2 Binary files /dev/null and b/build/classes/java/main/org/sep2/exception/ApiKeyMissingException.class differ diff --git a/build/classes/java/main/org/sep2/exception/GlobalExceptionHandler.class b/build/classes/java/main/org/sep2/exception/GlobalExceptionHandler.class new file mode 100644 index 0000000..3f4a499 Binary files /dev/null and b/build/classes/java/main/org/sep2/exception/GlobalExceptionHandler.class differ diff --git a/build/classes/java/main/org/sep2/exception/ResourceNotFoundException.class b/build/classes/java/main/org/sep2/exception/ResourceNotFoundException.class new file mode 100644 index 0000000..f3ec9b1 Binary files /dev/null and b/build/classes/java/main/org/sep2/exception/ResourceNotFoundException.class differ diff --git a/build/classes/java/main/org/sep2/repository/CompanyRepository.class b/build/classes/java/main/org/sep2/repository/CompanyRepository.class new file mode 100644 index 0000000..fb2264d Binary files /dev/null and b/build/classes/java/main/org/sep2/repository/CompanyRepository.class differ diff --git a/build/classes/java/main/org/sep2/repository/StockHistoryRepository.class b/build/classes/java/main/org/sep2/repository/StockHistoryRepository.class new file mode 100644 index 0000000..d827291 Binary files /dev/null and b/build/classes/java/main/org/sep2/repository/StockHistoryRepository.class differ diff --git a/build/classes/java/main/org/sep2/service/StockHistoryService.class b/build/classes/java/main/org/sep2/service/StockHistoryService.class new file mode 100644 index 0000000..d057559 Binary files /dev/null and b/build/classes/java/main/org/sep2/service/StockHistoryService.class differ diff --git a/build/classes/java/main/org/sep2/service/impl/StockHistoryServiceImpl.class b/build/classes/java/main/org/sep2/service/impl/StockHistoryServiceImpl.class new file mode 100644 index 0000000..0df5797 Binary files /dev/null and b/build/classes/java/main/org/sep2/service/impl/StockHistoryServiceImpl.class differ diff --git a/build/classes/java/main/org/sep2/test.class b/build/classes/java/main/org/sep2/test.class new file mode 100644 index 0000000..81bdd74 Binary files /dev/null and b/build/classes/java/main/org/sep2/test.class differ diff --git a/build/resolvedMainClassName b/build/resolvedMainClassName new file mode 100644 index 0000000..dfbe00a --- /dev/null +++ b/build/resolvedMainClassName @@ -0,0 +1 @@ +org.sep2.SampleApplication \ No newline at end of file diff --git a/build/resources/main/application.yml b/build/resources/main/application.yml new file mode 100644 index 0000000..37d9365 --- /dev/null +++ b/build/resources/main/application.yml @@ -0,0 +1,19 @@ +spring: + datasource: + url: jdbc:mysql://ec2-3-36-99-237.ap-northeast-2.compute.amazonaws.com:13306/assignment?serverTimezone=UTC&characterEncoding=UTF-8 + username: sep + password: t6d5UJMD4whRQBKpoc1HYGaZx + driver-class-name: com.mysql.cj.jdbc.Driver + hikari: + maximum-pool-size: 5 # 최대 연결 수 제한 + minimum-idle: 2 # 최소 유지 커넥션 수 + idle-timeout: 30000 # 비활성 연결 유지 시간 설정 (30초) + + jpa: + database-platform: org.hibernate.dialect.MySQLDialect + hibernate: + ddl-auto: update + show-sql: true + +api: + key: c18aa07f-f005-4c2f-b6db-dff8294e6b5e diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryController.class.uniqueId1 b/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryController.class.uniqueId1 new file mode 100644 index 0000000..3935c7f Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryController.class.uniqueId1 differ diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryRequestDto.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryRequestDto.class.uniqueId0 new file mode 100644 index 0000000..d67ddb9 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/StockHistoryRequestDto.class.uniqueId0 differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 0000000..ba80add Binary files /dev/null and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 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..01122f9 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Sat Feb 15 21:35:55 KST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/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/master/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 + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# 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"' + +# 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 + which java >/dev/null 2>&1 || 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 + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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 + +# 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 \ + "$@" + +# 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..ac1b06f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@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=. +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%" == "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%"=="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! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c1a3219 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'be-dev-ass-sep-v1' + diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..5fe8172 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..a2facee Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..82ced92 Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/org/.DS_Store b/src/main/java/org/.DS_Store new file mode 100644 index 0000000..575ca56 Binary files /dev/null and b/src/main/java/org/.DS_Store differ diff --git a/src/main/java/org/sep2/.DS_Store b/src/main/java/org/sep2/.DS_Store new file mode 100644 index 0000000..a301b17 Binary files /dev/null and b/src/main/java/org/sep2/.DS_Store differ diff --git a/src/main/java/org/sep2/ApiKeyProvider.java b/src/main/java/org/sep2/ApiKeyProvider.java new file mode 100644 index 0000000..8cadc00 --- /dev/null +++ b/src/main/java/org/sep2/ApiKeyProvider.java @@ -0,0 +1,15 @@ +package org.sep2; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class ApiKeyProvider { + + @Value("${api.key}") // application.yml에서 API Key 가져오기 + private String apiKey; + + public boolean isValid(String providedApiKey) { + return apiKey.equals(providedApiKey); + } +} diff --git a/src/main/java/org/sep2/SampleApplication.java b/src/main/java/org/sep2/SampleApplication.java new file mode 100644 index 0000000..2062015 --- /dev/null +++ b/src/main/java/org/sep2/SampleApplication.java @@ -0,0 +1,13 @@ +package org.sep2; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleApplication { + public static void main(String[] args) { + SpringApplication.run(SampleApplication.class, args); + } +} \ No newline at end of file diff --git a/src/main/java/org/sep2/controller/StockHistoryController.java b/src/main/java/org/sep2/controller/StockHistoryController.java new file mode 100644 index 0000000..a5211dd --- /dev/null +++ b/src/main/java/org/sep2/controller/StockHistoryController.java @@ -0,0 +1,61 @@ +package org.sep2.controller; + +import jakarta.validation.Valid; +import org.sep2.dto.StockHistoryRequestDto; +import org.sep2.dto.StockHistoryResponseDto; +import org.sep2.exception.ApiKeyInvalidException; +import org.sep2.exception.ApiKeyMissingException; +import org.sep2.exception.ResourceNotFoundException; +import org.sep2.service.StockHistoryService; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.beans.factory.annotation.Value; +import org.sep2.ApiKeyProvider; +import java.time.LocalDate; +import java.util.List; + +@RestController +@RequestMapping("/api/v1/stocks") +public class StockHistoryController { + + private final StockHistoryService stockHistoryService; + private final ApiKeyProvider apiKeyProvider; + + @Value("${api.key}") // + private String configuredApiKey; + + public StockHistoryController(StockHistoryService stockHistoryService, ApiKeyProvider apiKeyProvider) { + this.stockHistoryService = stockHistoryService; + this.apiKeyProvider = apiKeyProvider; + } + + @GetMapping + public ResponseEntity getStockHistory( + @RequestParam String companyCode, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, + @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate, + @RequestParam(required = false) String apikey, + @Valid @ModelAttribute StockHistoryRequestDto requestDto, + @RequestHeader(value = "x-api-key", required = false) String headerApiKey) { +// 데이터 조회 + List stockHistoryList = stockHistoryService.getStockHistory( + requestDto.getCompanyCode(), + requestDto.getStartDate(), + requestDto.getEndDate()); + // api 검증 + String key = (headerApiKey != null) ? headerApiKey : apikey; + if (key == null || key.isBlank()) { + throw new ApiKeyMissingException("API Key가 누락되었습니다."); + } + if (!apiKeyProvider.isValid(key)) { + throw new ApiKeyInvalidException("유효하지 않은 API Key입니다."); + } + + if (stockHistoryList.isEmpty()) { + throw new ResourceNotFoundException("해당 기간 동안의 주식 데이터가 없습니다."); + } + + return ResponseEntity.ok(stockHistoryList); + } +} diff --git a/src/main/java/org/sep2/domain/Company.java b/src/main/java/org/sep2/domain/Company.java new file mode 100644 index 0000000..aa07f47 --- /dev/null +++ b/src/main/java/org/sep2/domain/Company.java @@ -0,0 +1,27 @@ +package org.sep2.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "company") // 테이블 이름 지정 +@Getter +@Setter +@NoArgsConstructor +public class Company { + + @Id + @Column(name = "company_code", nullable = false, length = 10) + private String companyCode; + + + @Column(name = "company_name", nullable = false) + private String companyName; + + +} \ No newline at end of file diff --git a/src/main/java/org/sep2/domain/StockHistory.java b/src/main/java/org/sep2/domain/StockHistory.java new file mode 100644 index 0000000..d15bcd6 --- /dev/null +++ b/src/main/java/org/sep2/domain/StockHistory.java @@ -0,0 +1,37 @@ +package org.sep2.domain; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Table(name = "stocks_history") +@Getter +@Setter +@NoArgsConstructor +public class StockHistory { + + @EmbeddedId + private StockHistoryId id; + + @ManyToOne + @JoinColumn(name = "company_code", referencedColumnName = "company_code", insertable = false, updatable = false) + private Company company; + + @Column(nullable = false) + private float openPrice; + + @Column(nullable = false) + private float highPrice; + + @Column(nullable = false) + private float lowPrice; + + @Column(nullable = false) + private float closePrice; + + @Column(nullable = false) + private float volume; + + +} \ No newline at end of file diff --git a/src/main/java/org/sep2/domain/StockHistoryId.java b/src/main/java/org/sep2/domain/StockHistoryId.java new file mode 100644 index 0000000..011f45c --- /dev/null +++ b/src/main/java/org/sep2/domain/StockHistoryId.java @@ -0,0 +1,34 @@ +package org.sep2.domain; + + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import lombok.EqualsAndHashCode; +import java.io.Serializable; +import java.time.LocalDate; + +@Embeddable +@EqualsAndHashCode +public class StockHistoryId implements Serializable { + @Column(name = "company_code", nullable = false) + private String companyCode; + @Column(name = "trade_date", nullable = false) + private LocalDate tradeDate; + + public StockHistoryId() {} + + public StockHistoryId(String companyCode, LocalDate tradeDate) { + this.companyCode = companyCode; + this.tradeDate = tradeDate; + } + + // Getter 추가 + public String getCompanyCode() { + return companyCode; + } + + public LocalDate getTradeDate() { + return tradeDate; + } + +} \ No newline at end of file diff --git a/src/main/java/org/sep2/dto/CompanyDto.java b/src/main/java/org/sep2/dto/CompanyDto.java new file mode 100644 index 0000000..8d6c3b9 --- /dev/null +++ b/src/main/java/org/sep2/dto/CompanyDto.java @@ -0,0 +1,10 @@ +package org.sep2.dto; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class CompanyDto { + private String companyCode; + private String companyName; +} \ No newline at end of file diff --git a/src/main/java/org/sep2/dto/StockHistoryDto.java b/src/main/java/org/sep2/dto/StockHistoryDto.java new file mode 100644 index 0000000..7fbeca5 --- /dev/null +++ b/src/main/java/org/sep2/dto/StockHistoryDto.java @@ -0,0 +1,15 @@ +package org.sep2.dto; +import lombok.AllArgsConstructor; +import lombok.Getter; +import java.time.LocalDate; + +@Getter +@AllArgsConstructor +public class StockHistoryDto { + private LocalDate tradeDate; + private float openPrice; + private float highPrice; + private float lowPrice; + private float closePrice; + private float volume; +} \ No newline at end of file diff --git a/src/main/java/org/sep2/dto/StockHistoryRequestDto.java b/src/main/java/org/sep2/dto/StockHistoryRequestDto.java new file mode 100644 index 0000000..2d898a9 --- /dev/null +++ b/src/main/java/org/sep2/dto/StockHistoryRequestDto.java @@ -0,0 +1,41 @@ +package org.sep2.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import lombok.Getter; +import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDate; + +@Setter +@Getter +public class StockHistoryRequestDto { + + // Getter & Setter + @NotBlank(message = "companyCode는 필수 입력값입니다.") // 빈 값 허용 안 함 + private String companyCode; + + @NotNull(message = "startDate는 필수 입력값입니다.") + @DateTimeFormat(pattern = "yyyy-MM-dd") // 날짜 형식 지정 + private LocalDate startDate; + + @NotNull(message = "endDate는 필수 입력값입니다.") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private LocalDate endDate; + + + private String apikey; + + // 기본 생성자 + public StockHistoryRequestDto() {} + + // 생성자 + public StockHistoryRequestDto(String companyCode, LocalDate startDate, LocalDate endDate, String apikey) { + this.companyCode = companyCode; + this.startDate = startDate; + this.endDate = endDate; + this.apikey = apikey; + } + +} diff --git a/src/main/java/org/sep2/dto/StockHistoryResponseDto.java b/src/main/java/org/sep2/dto/StockHistoryResponseDto.java new file mode 100644 index 0000000..5e6e5db --- /dev/null +++ b/src/main/java/org/sep2/dto/StockHistoryResponseDto.java @@ -0,0 +1,19 @@ +package org.sep2.dto; + +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +public class StockHistoryResponseDto { + private String companyName; + private LocalDate tradeDate; + private long tradePrice; + + public StockHistoryResponseDto(String companyName, LocalDate tradeDate, long tradePrice) { + this.companyName = companyName; + this.tradeDate = tradeDate; + this.tradePrice = tradePrice; + } + +} diff --git a/src/main/java/org/sep2/exception/ApiKeyInvalidException.java b/src/main/java/org/sep2/exception/ApiKeyInvalidException.java new file mode 100644 index 0000000..79f3200 --- /dev/null +++ b/src/main/java/org/sep2/exception/ApiKeyInvalidException.java @@ -0,0 +1,7 @@ +package org.sep2.exception; + +public class ApiKeyInvalidException extends RuntimeException { + public ApiKeyInvalidException(String message) { + super(message); + } +} diff --git a/src/main/java/org/sep2/exception/ApiKeyMissingException.java b/src/main/java/org/sep2/exception/ApiKeyMissingException.java new file mode 100644 index 0000000..6bb428c --- /dev/null +++ b/src/main/java/org/sep2/exception/ApiKeyMissingException.java @@ -0,0 +1,7 @@ +package org.sep2.exception; + +public class ApiKeyMissingException extends RuntimeException { + public ApiKeyMissingException(String message) { + super(message); + } +} diff --git a/src/main/java/org/sep2/exception/GlobalExceptionHandler.java b/src/main/java/org/sep2/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..382d8ac --- /dev/null +++ b/src/main/java/org/sep2/exception/GlobalExceptionHandler.java @@ -0,0 +1,45 @@ +package org.sep2.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + +@RestControllerAdvice +@RequestMapping(produces = "application/json") // 모든 응답을 JSON으로 반환 +public class GlobalExceptionHandler { + + private ResponseEntity buildResponseEntity(HttpStatus status, String message) { + Map response = new HashMap<>(); + response.put("status", status.value()); + response.put("message", message); + response.put("timestamp", LocalDateTime.now()); + response.put("data", null); + return new ResponseEntity<>(response, status); + } + + // 400: API Key 없는 경우 + @ExceptionHandler(ApiKeyMissingException.class) + public ResponseEntity handleApiKeyMissingException(ApiKeyMissingException ex) { + return buildResponseEntity(HttpStatus.BAD_REQUEST, ex.getMessage()); + } + + // 403: API Key가 유효하지 않는 경우 + @ExceptionHandler(ApiKeyInvalidException.class) + public ResponseEntity handleApiKeyInvalidException(ApiKeyInvalidException ex) { + return buildResponseEntity(HttpStatus.FORBIDDEN, ex.getMessage()); + } + + // 404: 존재하지 않는 API 요청 + @ExceptionHandler(ResourceNotFoundException.class) + public ResponseEntity handleResourceNotFoundException(ResourceNotFoundException ex) { + return buildResponseEntity(HttpStatus.NOT_FOUND, ex.getMessage()); + } + + +} diff --git a/src/main/java/org/sep2/exception/ResourceNotFoundException.java b/src/main/java/org/sep2/exception/ResourceNotFoundException.java new file mode 100644 index 0000000..b1dcef9 --- /dev/null +++ b/src/main/java/org/sep2/exception/ResourceNotFoundException.java @@ -0,0 +1,7 @@ +package org.sep2.exception; + +public class ResourceNotFoundException extends RuntimeException { + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/org/sep2/repository/CompanyRepository.java b/src/main/java/org/sep2/repository/CompanyRepository.java new file mode 100644 index 0000000..f6dc5bd --- /dev/null +++ b/src/main/java/org/sep2/repository/CompanyRepository.java @@ -0,0 +1,11 @@ +package org.sep2.repository; + +import org.sep2.domain.Company; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CompanyRepository extends JpaRepository { + // 기업 코드를 기반으로 기업 정보를 조회하는 메서드 + Company findByCompanyCode(String companyCode); +} \ No newline at end of file diff --git a/src/main/java/org/sep2/repository/StockHistoryRepository.java b/src/main/java/org/sep2/repository/StockHistoryRepository.java new file mode 100644 index 0000000..e8660a4 --- /dev/null +++ b/src/main/java/org/sep2/repository/StockHistoryRepository.java @@ -0,0 +1,20 @@ +package org.sep2.repository; + +import org.sep2.domain.StockHistory; +import org.sep2.domain.StockHistoryId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.util.List; + +@Repository +public interface StockHistoryRepository extends JpaRepository { + + // 특정 기업의 특정 기간 동안 주식 데이터를 조회하는 메서드 + List findByIdCompanyCodeAndIdTradeDateBetween( + String companyCode, + LocalDate startDate, + LocalDate endDate + ); +} \ No newline at end of file diff --git a/src/main/java/org/sep2/service/StockHistoryService.java b/src/main/java/org/sep2/service/StockHistoryService.java new file mode 100644 index 0000000..51212af --- /dev/null +++ b/src/main/java/org/sep2/service/StockHistoryService.java @@ -0,0 +1,9 @@ +package org.sep2.service; + +import org.sep2.dto.StockHistoryResponseDto; +import java.time.LocalDate; +import java.util.List; + +public interface StockHistoryService { + List getStockHistory(String companyCode, LocalDate startDate, LocalDate endDate); +} diff --git a/src/main/java/org/sep2/service/impl/StockHistoryServiceImpl.java b/src/main/java/org/sep2/service/impl/StockHistoryServiceImpl.java new file mode 100644 index 0000000..3009268 --- /dev/null +++ b/src/main/java/org/sep2/service/impl/StockHistoryServiceImpl.java @@ -0,0 +1,35 @@ +package org.sep2.service.impl; + +import org.sep2.domain.StockHistory; +import org.sep2.dto.StockHistoryResponseDto; +import org.sep2.repository.StockHistoryRepository; +import org.sep2.service.StockHistoryService; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class StockHistoryServiceImpl implements StockHistoryService { + + private final StockHistoryRepository stockHistoryRepository; + + public StockHistoryServiceImpl(StockHistoryRepository stockHistoryRepository) { + this.stockHistoryRepository = stockHistoryRepository; + } + + @Override + public List getStockHistory(String companyCode, LocalDate startDate, LocalDate endDate) { + List stockHistoryList = + stockHistoryRepository.findByIdCompanyCodeAndIdTradeDateBetween(companyCode, startDate, endDate); + + return stockHistoryList.stream() + .map(stockHistory -> new StockHistoryResponseDto( + stockHistory.getCompany().getCompanyName(), + stockHistory.getId().getTradeDate(), + (long) stockHistory.getClosePrice() + )) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/org/sep2/test.java b/src/main/java/org/sep2/test.java new file mode 100644 index 0000000..f293429 --- /dev/null +++ b/src/main/java/org/sep2/test.java @@ -0,0 +1,30 @@ +package org.sep2; + +import jakarta.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + + +@Component +public class test { + + @Value("${spring.datasource.url}") + private String dbUrl; + + @Value("${spring.datasource.username}") + private String dbUser; + + @Value("${spring.datasource.password}") + private String dbPassword; + + @Value("${api.key}") + private String apiKey; + + @PostConstruct + public void checkEnv() { + System.out.println(" DB URL: " + dbUrl); + System.out.println(" DB User: " + dbUser); + System.out.println(" DB Password: " + dbPassword); + System.out.println(" API Key: " + apiKey); + } +} \ No newline at end of file diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000..2520f77 Binary files /dev/null and b/src/test/.DS_Store differ