diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53e3609 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +application-db.properties \ No newline at end of file diff --git a/.gradle/8.12.1/checksums/checksums.lock b/.gradle/8.12.1/checksums/checksums.lock new file mode 100644 index 0000000..42eab84 Binary files /dev/null and b/.gradle/8.12.1/checksums/checksums.lock differ diff --git a/.gradle/8.12.1/checksums/md5-checksums.bin b/.gradle/8.12.1/checksums/md5-checksums.bin new file mode 100644 index 0000000..be7c341 Binary files /dev/null and b/.gradle/8.12.1/checksums/md5-checksums.bin differ diff --git a/.gradle/8.12.1/checksums/sha1-checksums.bin b/.gradle/8.12.1/checksums/sha1-checksums.bin new file mode 100644 index 0000000..71abd70 Binary files /dev/null and b/.gradle/8.12.1/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.12.1/executionHistory/executionHistory.bin b/.gradle/8.12.1/executionHistory/executionHistory.bin new file mode 100644 index 0000000..1992267 Binary files /dev/null and b/.gradle/8.12.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.12.1/executionHistory/executionHistory.lock b/.gradle/8.12.1/executionHistory/executionHistory.lock new file mode 100644 index 0000000..5032062 Binary files /dev/null and b/.gradle/8.12.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.12.1/fileChanges/last-build.bin b/.gradle/8.12.1/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.12.1/fileChanges/last-build.bin differ diff --git a/.gradle/8.12.1/fileHashes/fileHashes.bin b/.gradle/8.12.1/fileHashes/fileHashes.bin new file mode 100644 index 0000000..9f39445 Binary files /dev/null and b/.gradle/8.12.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.12.1/fileHashes/fileHashes.lock b/.gradle/8.12.1/fileHashes/fileHashes.lock new file mode 100644 index 0000000..6ee57eb Binary files /dev/null and b/.gradle/8.12.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.12.1/fileHashes/resourceHashesCache.bin b/.gradle/8.12.1/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..e4c8adc Binary files /dev/null and b/.gradle/8.12.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/8.12.1/gc.properties b/.gradle/8.12.1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.2/checksums/checksums.lock b/.gradle/8.2/checksums/checksums.lock new file mode 100644 index 0000000..bec950e Binary files /dev/null and b/.gradle/8.2/checksums/checksums.lock differ diff --git a/.gradle/8.2/checksums/md5-checksums.bin b/.gradle/8.2/checksums/md5-checksums.bin new file mode 100644 index 0000000..ac7125e Binary files /dev/null and b/.gradle/8.2/checksums/md5-checksums.bin differ diff --git a/.gradle/8.2/checksums/sha1-checksums.bin b/.gradle/8.2/checksums/sha1-checksums.bin new file mode 100644 index 0000000..50afcaa Binary files /dev/null and b/.gradle/8.2/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock b/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..dac5155 Binary files /dev/null and b/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/8.2/dependencies-accessors/gc.properties b/.gradle/8.2/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/8.2/fileChanges/last-build.bin b/.gradle/8.2/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.2/fileChanges/last-build.bin differ diff --git a/.gradle/8.2/fileHashes/fileHashes.lock b/.gradle/8.2/fileHashes/fileHashes.lock new file mode 100644 index 0000000..e34f9df Binary files /dev/null and b/.gradle/8.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.2/gc.properties b/.gradle/8.2/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..0daa6d3 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..db13d32 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Fri Feb 14 23:42:52 KST 2025 +gradle.version=8.12.1 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..b86c01b 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..1407c9e 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/.name b/.idea/.name new file mode 100644 index 0000000..0079477 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +assignment \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e2afcc0 --- /dev/null +++ b/.idea/compiler.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..ce1c62c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df1603e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,12 @@ + + + + \ 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..fe0b0da --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c3c6eb3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/assignment.main.iml b/.idea/modules/assignment.main.iml new file mode 100644 index 0000000..afc1871 --- /dev/null +++ b/.idea/modules/assignment.main.iml @@ -0,0 +1,8 @@ + + + + + + + + \ 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/HELP.md b/HELP.md new file mode 100644 index 0000000..18ca313 --- /dev/null +++ b/HELP.md @@ -0,0 +1,26 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.2/gradle-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.2/gradle-plugin/packaging-oci-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.2/reference/web/servlet.html) +* [JDBC API](https://docs.spring.io/spring-boot/3.4.2/reference/data/sql.html) +* [Spring Boot DevTools](https://docs.spring.io/spring-boot/3.4.2/reference/using/devtools.html) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Accessing Relational Data using JDBC with Spring](https://spring.io/guides/gs/relational-data-access/) +* [Managing Transactions](https://spring.io/guides/gs/managing-transactions/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f1d90ff --- /dev/null +++ b/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.4.2' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'ktb.back' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-web' + + implementation 'mysql:mysql-connector-java:8.0.33' + implementation 'org.jetbrains:annotations:24.0.0' + implementation 'org.springframework.boot:spring-boot-starter-validation' + + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/build/classes/java/main/ktb/back/assignment/AssignmentApplication.class b/build/classes/java/main/ktb/back/assignment/AssignmentApplication.class new file mode 100644 index 0000000..7ee0a01 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/AssignmentApplication.class differ diff --git a/build/classes/java/main/ktb/back/assignment/controller/CompanyController.class b/build/classes/java/main/ktb/back/assignment/controller/CompanyController.class new file mode 100644 index 0000000..a5ff72d Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/controller/CompanyController.class differ diff --git a/build/classes/java/main/ktb/back/assignment/controller/HelloController.class b/build/classes/java/main/ktb/back/assignment/controller/HelloController.class new file mode 100644 index 0000000..019fba0 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/controller/HelloController.class differ diff --git a/build/classes/java/main/ktb/back/assignment/dto/RequestCompanyStockHistory.class b/build/classes/java/main/ktb/back/assignment/dto/RequestCompanyStockHistory.class new file mode 100644 index 0000000..f6f89df Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/dto/RequestCompanyStockHistory.class differ diff --git a/build/classes/java/main/ktb/back/assignment/dto/ResponseCompanyStockHistory.class b/build/classes/java/main/ktb/back/assignment/dto/ResponseCompanyStockHistory.class new file mode 100644 index 0000000..ea2ccb3 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/dto/ResponseCompanyStockHistory.class differ diff --git a/build/classes/java/main/ktb/back/assignment/global/exception/ApiException.class b/build/classes/java/main/ktb/back/assignment/global/exception/ApiException.class new file mode 100644 index 0000000..aea021e Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/global/exception/ApiException.class differ diff --git a/build/classes/java/main/ktb/back/assignment/global/exception/ErrorResponse.class b/build/classes/java/main/ktb/back/assignment/global/exception/ErrorResponse.class new file mode 100644 index 0000000..ecddd21 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/global/exception/ErrorResponse.class differ diff --git a/build/classes/java/main/ktb/back/assignment/global/exception/GlobalExceptionHandler.class b/build/classes/java/main/ktb/back/assignment/global/exception/GlobalExceptionHandler.class new file mode 100644 index 0000000..fccf434 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/global/exception/GlobalExceptionHandler.class differ diff --git a/build/classes/java/main/ktb/back/assignment/global/validator/RequestValidator.class b/build/classes/java/main/ktb/back/assignment/global/validator/RequestValidator.class new file mode 100644 index 0000000..e556385 Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/global/validator/RequestValidator.class differ diff --git a/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepository.class b/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepository.class new file mode 100644 index 0000000..7b7e1ba Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepository.class differ diff --git a/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepositoryImpl.class b/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepositoryImpl.class new file mode 100644 index 0000000..056908c Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/repository/StockHistoryRepositoryImpl.class differ diff --git a/build/classes/java/main/ktb/back/assignment/service/CompanyService.class b/build/classes/java/main/ktb/back/assignment/service/CompanyService.class new file mode 100644 index 0000000..95c2abf Binary files /dev/null and b/build/classes/java/main/ktb/back/assignment/service/CompanyService.class differ diff --git a/build/reports/problems/problems-report.html b/build/reports/problems/problems-report.html new file mode 100644 index 0000000..f05a7da --- /dev/null +++ b/build/reports/problems/problems-report.html @@ -0,0 +1,663 @@ + + + + + + + + + + + + + Gradle Configuration Cache + + + +
+ +
+ Loading... +
+ + + + + + diff --git a/build/resources/main/application.properties b/build/resources/main/application.properties new file mode 100644 index 0000000..528844f --- /dev/null +++ b/build/resources/main/application.properties @@ -0,0 +1,2 @@ +spring.application.name=assignment +spring.profiles.include=db \ No newline at end of file diff --git a/build/tmp/compileJava/compileTransaction/stash-dir/CompanyController.class.uniqueId0 b/build/tmp/compileJava/compileTransaction/stash-dir/CompanyController.class.uniqueId0 new file mode 100644 index 0000000..9ae6dd3 Binary files /dev/null and b/build/tmp/compileJava/compileTransaction/stash-dir/CompanyController.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..ad90555 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..a4b76b9 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..e18bc25 --- /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.12.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/platforms/jvm/plugins-application/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 -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || 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..9b42019 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +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..306ff4d --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'assignment' diff --git a/src/main/java/ktb/back/assignment/AssignmentApplication.java b/src/main/java/ktb/back/assignment/AssignmentApplication.java new file mode 100644 index 0000000..a0f19af --- /dev/null +++ b/src/main/java/ktb/back/assignment/AssignmentApplication.java @@ -0,0 +1,13 @@ +package ktb.back.assignment; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AssignmentApplication { + + public static void main(String[] args) { + SpringApplication.run(AssignmentApplication.class, args); + } + +} diff --git a/src/main/java/ktb/back/assignment/controller/CompanyController.java b/src/main/java/ktb/back/assignment/controller/CompanyController.java new file mode 100644 index 0000000..d79a301 --- /dev/null +++ b/src/main/java/ktb/back/assignment/controller/CompanyController.java @@ -0,0 +1,33 @@ +package ktb.back.assignment.controller; + +import ktb.back.assignment.dto.ResponseCompanyStockHistory; +import ktb.back.assignment.global.validator.RequestValidator; +import ktb.back.assignment.service.CompanyService; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + + +@RestController +@RequestMapping("/api/v1/company") +public class CompanyController { + private final CompanyService companyService; + private final RequestValidator requestValidator; + + public CompanyController(CompanyService companyService,RequestValidator requestValidator){ + this.companyService = companyService; + this.requestValidator = requestValidator; + } + + @GetMapping + public List getCompanyPrice( + @RequestHeader(value = "x-api-key", required = false) String apiKeyHeader, + @RequestParam(required = false) String companyCode, + @RequestParam(required = false) String startDate, + @RequestParam(required = false) String endDate) { + requestValidator.validateApiKey(apiKeyHeader); + requestValidator.validateRequestParams(companyCode,startDate,endDate); + + return companyService.getCompanyStockHistory(companyCode, startDate, endDate); + } +} diff --git a/src/main/java/ktb/back/assignment/controller/HelloController.java b/src/main/java/ktb/back/assignment/controller/HelloController.java new file mode 100644 index 0000000..38ac397 --- /dev/null +++ b/src/main/java/ktb/back/assignment/controller/HelloController.java @@ -0,0 +1,14 @@ +package ktb.back.assignment.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + + @GetMapping("/hello") + public String hello(){ + return "hello!"; + } +} diff --git a/src/main/java/ktb/back/assignment/dto/RequestCompanyStockHistory.java b/src/main/java/ktb/back/assignment/dto/RequestCompanyStockHistory.java new file mode 100644 index 0000000..7138975 --- /dev/null +++ b/src/main/java/ktb/back/assignment/dto/RequestCompanyStockHistory.java @@ -0,0 +1,18 @@ +package ktb.back.assignment.dto; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class RequestCompanyStockHistory { + @NotNull(message = "companyCode 파라미터가 필요합니다.") + private String companyCode; + + @NotNull(message = "startDate 파라미터가 필요합니다.") + private String startDate; + + @NotNull(message = "endDate 파라미터가 필요합니다.") + private String endDate; +} diff --git a/src/main/java/ktb/back/assignment/dto/ResponseCompanyStockHistory.java b/src/main/java/ktb/back/assignment/dto/ResponseCompanyStockHistory.java new file mode 100644 index 0000000..b3fbe92 --- /dev/null +++ b/src/main/java/ktb/back/assignment/dto/ResponseCompanyStockHistory.java @@ -0,0 +1,14 @@ +package ktb.back.assignment.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@AllArgsConstructor +public class ResponseCompanyStockHistory { + private String companyName; + private LocalDate tradeDate; + private float closingPrice; +} diff --git a/src/main/java/ktb/back/assignment/global/exception/ApiException.java b/src/main/java/ktb/back/assignment/global/exception/ApiException.java new file mode 100644 index 0000000..d8a1a88 --- /dev/null +++ b/src/main/java/ktb/back/assignment/global/exception/ApiException.java @@ -0,0 +1,14 @@ +package ktb.back.assignment.global.exception; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public class ApiException extends RuntimeException{ + private final HttpStatus status; + + public ApiException(String message, HttpStatus status){ + super(message); + this.status = status; + } +} diff --git a/src/main/java/ktb/back/assignment/global/exception/ErrorResponse.java b/src/main/java/ktb/back/assignment/global/exception/ErrorResponse.java new file mode 100644 index 0000000..5155d3f --- /dev/null +++ b/src/main/java/ktb/back/assignment/global/exception/ErrorResponse.java @@ -0,0 +1,11 @@ +package ktb.back.assignment.global.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class ErrorResponse { + private int status; + private String messgae; +} diff --git a/src/main/java/ktb/back/assignment/global/exception/GlobalExceptionHandler.java b/src/main/java/ktb/back/assignment/global/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..a6c457c --- /dev/null +++ b/src/main/java/ktb/back/assignment/global/exception/GlobalExceptionHandler.java @@ -0,0 +1,17 @@ +package ktb.back.assignment.global.exception; + +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; + +@RestControllerAdvice +@RequestMapping(produces = "application/json") +public class GlobalExceptionHandler { + + @ExceptionHandler(ApiException.class) + public ResponseEntity handleApiException(ApiException ex) { + ErrorResponse errorResponse = new ErrorResponse(ex.getStatus().value(),ex.getMessage()); + return ResponseEntity.status(ex.getStatus()).body(errorResponse); + } +} diff --git a/src/main/java/ktb/back/assignment/global/validator/RequestValidator.java b/src/main/java/ktb/back/assignment/global/validator/RequestValidator.java new file mode 100644 index 0000000..65cbcbe --- /dev/null +++ b/src/main/java/ktb/back/assignment/global/validator/RequestValidator.java @@ -0,0 +1,28 @@ +package ktb.back.assignment.global.validator; + +import ktb.back.assignment.global.exception.ApiException; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; + +@Component +public class RequestValidator { + private static final String VALID_API_KEY = "c18aa07f-f005-4c2f-b6db-dff8294e6b5e"; + + public void validateApiKey(String apiKey){ + if(apiKey == null || apiKey.isBlank()){ + throw new ApiException("API Key가 없습니다.", HttpStatus.BAD_REQUEST); + }else if(!apiKey.equals(VALID_API_KEY)){ + throw new ApiException("잘못된 API Key입니다.",HttpStatus.FORBIDDEN); + } + } + + public void validateRequestParams(String companyCode,String startDate, String endDate){ + if(companyCode == null || companyCode.isBlank()){ + throw new ApiException("companyCode 파라미터가 필요합니다.", HttpStatus.BAD_REQUEST); + } else if (startDate == null || startDate.isBlank()) { + throw new ApiException("startDate 파라미터가 필요합니다.", HttpStatus.BAD_REQUEST); + } else if (endDate == null || endDate.isBlank()) { + throw new ApiException("endDate 파라미터가 필요합니다.", HttpStatus.BAD_REQUEST); + } + } +} diff --git a/src/main/java/ktb/back/assignment/repository/StockHistoryRepository.java b/src/main/java/ktb/back/assignment/repository/StockHistoryRepository.java new file mode 100644 index 0000000..3823e6d --- /dev/null +++ b/src/main/java/ktb/back/assignment/repository/StockHistoryRepository.java @@ -0,0 +1,11 @@ +package ktb.back.assignment.repository; + +import ktb.back.assignment.dto.ResponseCompanyStockHistory; + +import java.time.LocalDate; +import java.util.List; + +public interface StockHistoryRepository { + + public List findCompanyStockHistory(String companyCode, LocalDate startDate, LocalDate endDate); +} diff --git a/src/main/java/ktb/back/assignment/repository/StockHistoryRepositoryImpl.java b/src/main/java/ktb/back/assignment/repository/StockHistoryRepositoryImpl.java new file mode 100644 index 0000000..261bdfd --- /dev/null +++ b/src/main/java/ktb/back/assignment/repository/StockHistoryRepositoryImpl.java @@ -0,0 +1,39 @@ +package ktb.back.assignment.repository; + +import ktb.back.assignment.dto.ResponseCompanyStockHistory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Repository; + +import java.time.LocalDate; +import java.util.List; + +@Repository +public class StockHistoryRepositoryImpl implements StockHistoryRepository{ + private final JdbcTemplate jdbcTemplate; + + public StockHistoryRepositoryImpl(JdbcTemplate jdbcTemplate){ + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public List findCompanyStockHistory(String companyCode, LocalDate startDate, LocalDate endDate){ + String sql = """ + SELECT c.company_name , s.trade_date, s.close_price + FROM company c + JOIN stocks_history s ON c.company_code = s.company_code + WHERE c.company_code = ? AND s.trade_date BETWEEN ? AND ? + ORDER BY s.trade_date + """; + + return jdbcTemplate.query(sql,companyStockRowMapper(), companyCode,startDate,endDate); + } + + private RowMapper companyStockRowMapper(){ + return (rs,rowNum) -> new ResponseCompanyStockHistory( + rs.getString("company_name"), + rs.getDate("trade_date").toLocalDate(), + rs.getFloat("close_price") + ); + } +} diff --git a/src/main/java/ktb/back/assignment/service/CompanyService.java b/src/main/java/ktb/back/assignment/service/CompanyService.java new file mode 100644 index 0000000..b28bd12 --- /dev/null +++ b/src/main/java/ktb/back/assignment/service/CompanyService.java @@ -0,0 +1,23 @@ +package ktb.back.assignment.service; + +import ktb.back.assignment.dto.ResponseCompanyStockHistory; +import ktb.back.assignment.repository.StockHistoryRepositoryImpl; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.List; + +@Service +public class CompanyService { + private final StockHistoryRepositoryImpl stockHistoryRepository; + + public CompanyService(StockHistoryRepositoryImpl stockHistoryRepository){ + this.stockHistoryRepository = stockHistoryRepository; + } + + public List getCompanyStockHistory(String companyCode, String startDate, String endDate) { + LocalDate start = LocalDate.parse(startDate); + LocalDate end = LocalDate.parse(endDate); + return stockHistoryRepository.findCompanyStockHistory(companyCode,start,end); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..528844f --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=assignment +spring.profiles.include=db \ No newline at end of file diff --git a/src/test/java/ktb/back/assignment/AssignmentApplicationTests.java b/src/test/java/ktb/back/assignment/AssignmentApplicationTests.java new file mode 100644 index 0000000..5a81f19 --- /dev/null +++ b/src/test/java/ktb/back/assignment/AssignmentApplicationTests.java @@ -0,0 +1,13 @@ +package ktb.back.assignment; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class AssignmentApplicationTests { + + @Test + void contextLoads() { + } + +}